2016-07-20 21:47:37 -07:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
project(numbuf)
|
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
|
|
|
|
2017-01-09 20:15:54 -08:00
|
|
|
option(HAS_PLASMA
|
|
|
|
"Are we linking with the plasma object store? Recommended if numbuf is used as part of ray."
|
|
|
|
OFF)
|
|
|
|
|
|
|
|
if(HAS_PLASMA)
|
|
|
|
add_definitions(-DHAS_PLASMA)
|
|
|
|
endif()
|
2016-11-19 02:27:21 -08:00
|
|
|
|
2016-11-29 14:32:54 -08:00
|
|
|
message(STATUS "Trying custom approach for finding Python.")
|
|
|
|
# Start off by figuring out which Python executable to use.
|
|
|
|
find_program(CUSTOM_PYTHON_EXECUTABLE python)
|
|
|
|
message(STATUS "Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
2016-12-11 12:25:31 -08:00
|
|
|
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print('python' + sys.version[0:3])"
|
2016-11-29 14:32:54 -08:00
|
|
|
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
message(STATUS "PYTHON_LIBRARY_NAME: " ${PYTHON_LIBRARY_NAME})
|
|
|
|
# Now find the Python include directories.
|
2016-12-11 12:25:31 -08:00
|
|
|
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print(get_python_inc())"
|
2016-11-29 14:32:54 -08:00
|
|
|
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
message(STATUS "PYTHON_INCLUDE_DIRS: " ${PYTHON_INCLUDE_DIRS})
|
|
|
|
# Now find the Python libraries. We'll start by looking near the Python
|
|
|
|
# executable. If that fails, then we'll look near the Python include
|
|
|
|
# directories.
|
2016-12-11 12:25:31 -08:00
|
|
|
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print(sys.exec_prefix)"
|
2016-11-29 14:32:54 -08:00
|
|
|
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
message(STATUS "PYTHON_PREFIX: " ${PYTHON_PREFIX})
|
2016-12-13 17:37:22 -08:00
|
|
|
# The name ending in "m" is for miniconda.
|
2016-11-29 14:32:54 -08:00
|
|
|
FIND_LIBRARY(PYTHON_LIBRARIES
|
2016-12-13 17:37:22 -08:00
|
|
|
NAMES "${PYTHON_LIBRARY_NAME}" "${PYTHON_LIBRARY_NAME}m"
|
2016-11-29 14:32:54 -08:00
|
|
|
HINTS "${PYTHON_PREFIX}"
|
|
|
|
PATH_SUFFIXES "lib" "libs"
|
|
|
|
NO_DEFAULT_PATH)
|
|
|
|
message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
|
|
|
# If that failed, perhaps because the user is in a virtualenv, search around
|
|
|
|
# the Python include directories.
|
|
|
|
if(NOT PYTHON_LIBRARIES)
|
|
|
|
message(STATUS "Failed to find PYTHON_LIBRARIES near the Python executable, so now looking near the Python include directories.")
|
2016-12-13 17:37:22 -08:00
|
|
|
# The name ending in "m" is for miniconda.
|
2016-11-19 19:00:42 -08:00
|
|
|
FIND_LIBRARY(PYTHON_LIBRARIES
|
2016-12-13 17:37:22 -08:00
|
|
|
NAMES "${PYTHON_LIBRARY_NAME}" "${PYTHON_LIBRARY_NAME}m"
|
2016-11-29 14:32:54 -08:00
|
|
|
HINTS "${PYTHON_INCLUDE_DIRS}/../.."
|
2016-11-19 19:00:42 -08:00
|
|
|
PATH_SUFFIXES "lib" "libs"
|
|
|
|
NO_DEFAULT_PATH)
|
|
|
|
message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
2016-07-24 21:24:26 -07:00
|
|
|
endif()
|
2016-11-29 14:32:54 -08:00
|
|
|
# If we found the Python libraries and the include directories, then continue
|
|
|
|
# on. If not, then try find_package as a last resort, but it probably won't
|
|
|
|
# work.
|
|
|
|
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
|
|
|
|
message(STATUS "The custom approach for finding Python succeeded.")
|
|
|
|
SET(PYTHONLIBS_FOUND TRUE)
|
|
|
|
else()
|
|
|
|
message(WARNING "The custom approach for finding Python failed. Defaulting to find_package.")
|
|
|
|
find_package(PythonInterp REQUIRED)
|
|
|
|
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
|
|
|
|
set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
|
|
|
|
endif()
|
|
|
|
|
2016-11-19 19:00:42 -08:00
|
|
|
message(STATUS "Using CUSTOM_PYTHON_EXECUTABLE: " ${CUSTOM_PYTHON_EXECUTABLE})
|
|
|
|
message(STATUS "Using PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
|
|
|
message(STATUS "Using PYTHON_INCLUDE_DIRS: " ${PYTHON_INCLUDE_DIRS})
|
2016-07-24 21:24:26 -07:00
|
|
|
|
2016-07-20 21:47:37 -07:00
|
|
|
find_package(NumPy REQUIRED)
|
|
|
|
|
2016-07-23 18:34:22 -07:00
|
|
|
if(APPLE)
|
|
|
|
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
|
|
|
endif(APPLE)
|
|
|
|
|
2016-07-20 21:47:37 -07:00
|
|
|
include_directories("${PYTHON_INCLUDE_DIRS}")
|
|
|
|
include_directories("${NUMPY_INCLUDE_DIR}")
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
|
|
|
2016-11-19 19:00:42 -08:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
link_libraries(rt)
|
2016-07-20 21:47:37 -07:00
|
|
|
endif()
|
|
|
|
|
2016-11-19 19:00:42 -08:00
|
|
|
set(ARROW_DIR "${CMAKE_SOURCE_DIR}/thirdparty/arrow/"
|
|
|
|
CACHE STRING "Path of the arrow source directory")
|
2016-07-20 21:47:37 -07:00
|
|
|
|
2016-11-21 02:14:13 -08:00
|
|
|
set(ARROW_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow.a"
|
|
|
|
CACHE STRING "Path to libarrow.a (needs to be changed if arrow is build in debug mode)")
|
|
|
|
set(ARROW_IO_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow_io.a"
|
|
|
|
CACHE STRING "Path to libarrow_io.a (needs to be changed if arrow is build in debug mode)")
|
|
|
|
set(ARROW_IPC_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow_ipc.a"
|
|
|
|
CACHE STRING "Path to libarrow_ipc.a (needs to be changed if arrow is build in debug mode)")
|
2016-07-20 21:47:37 -07:00
|
|
|
|
|
|
|
include_directories("${ARROW_DIR}/cpp/src/")
|
|
|
|
include_directories("cpp/src/")
|
|
|
|
include_directories("python/src/")
|
|
|
|
|
2017-01-09 20:15:54 -08:00
|
|
|
if(HAS_PLASMA)
|
|
|
|
include_directories("../src/plasma")
|
|
|
|
include_directories("../src/common")
|
|
|
|
include_directories("../src/common/thirdparty")
|
|
|
|
include_directories("../src/common/build/flatcc-prefix/src/flatcc/include")
|
|
|
|
endif()
|
|
|
|
|
2016-07-20 21:47:37 -07:00
|
|
|
add_definitions(-fPIC)
|
|
|
|
|
|
|
|
add_library(numbuf SHARED
|
|
|
|
cpp/src/numbuf/tensor.cc
|
|
|
|
cpp/src/numbuf/dict.cc
|
|
|
|
cpp/src/numbuf/sequence.cc
|
|
|
|
python/src/pynumbuf/numbuf.cc
|
|
|
|
python/src/pynumbuf/adapters/numpy.cc
|
|
|
|
python/src/pynumbuf/adapters/python.cc)
|
|
|
|
|
2016-07-25 13:21:31 -07:00
|
|
|
get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
|
2016-07-24 21:24:26 -07:00
|
|
|
if(APPLE)
|
|
|
|
add_custom_command(TARGET numbuf
|
2016-11-19 19:00:42 -08:00
|
|
|
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libnumbuf.so)
|
2016-07-24 21:24:26 -07:00
|
|
|
endif(APPLE)
|
|
|
|
|
2016-11-21 02:14:13 -08:00
|
|
|
if(APPLE)
|
|
|
|
target_link_libraries(numbuf ${ARROW_LIB} ${ARROW_IO_LIB} ${ARROW_IPC_LIB} ${PYTHON_LIBRARIES})
|
|
|
|
else()
|
|
|
|
target_link_libraries(numbuf -Wl,--whole-archive ${ARROW_LIB} -Wl,--no-whole-archive ${ARROW_IO_LIB} ${ARROW_IPC_LIB} ${PYTHON_LIBRARIES})
|
|
|
|
endif()
|
2016-10-27 23:40:10 -07:00
|
|
|
|
2017-01-09 20:15:54 -08:00
|
|
|
if(HAS_PLASMA)
|
|
|
|
target_link_libraries(numbuf ${ARROW_LIB} ${ARROW_IO_LIB} ${ARROW_IPC_LIB} ${PYTHON_LIBRARIES} "${CMAKE_SOURCE_DIR}/../src/plasma/build/libplasma_client.a" "${CMAKE_SOURCE_DIR}/../src/common/build/libcommon.a" "${CMAKE_SOURCE_DIR}/../src/common/build/flatcc-prefix/src/flatcc/lib/libflatcc.a")
|
|
|
|
else()
|
|
|
|
target_link_libraries(numbuf ${ARROW_LIB} ${ARROW_IO_LIB} ${ARROW_IPC_LIB} ${PYTHON_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
|
2016-11-19 02:27:21 -08:00
|
|
|
install(TARGETS numbuf DESTINATION ${CMAKE_SOURCE_DIR}/numbuf/)
|