mirror of
https://github.com/wassname/ray.git
synced 2026-07-28 11:25:04 +08:00
Improve case on Mac where cmake fails to find Python with the custom search path. (#49)
* On Mac OS X, if cmake fails to find Python with custom search path, default to using find_package. * Fix formatting in CMakeLists.txt. * Set CUSTOM_PYTHON_EXECUTABLE variable on mac if the custom search path fails. * Require exact Python version match. * Use cmake mode keyword for logging messages. * Fix. * Find python libraries in cmake by searching near the include directories. * Update cmakelists for numbuf.
This commit is contained in:
committed by
Philipp Moritz
parent
c9757a6fd0
commit
f267da6aa8
+67
-50
@@ -4,40 +4,65 @@ project(numbuf)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
||||
|
||||
# Make libnumbuf.so look for shared libraries in the folder libnumbuf.so is in
|
||||
# Make libnumbuf.so look for shared libraries in the folder libnumbuf.so is in.
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/")
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
|
||||
if(NOT APPLE)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
find_package(PythonLibs REQUIRED)
|
||||
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
|
||||
set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
else()
|
||||
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("-- Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_LIBRARY_NAME: " ${PYTHON_LIBRARY_NAME})
|
||||
# Now find the Python include directories.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_inc()"
|
||||
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.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_PREFIX: " ${PYTHON_PREFIX})
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
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.")
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
HINTS "${PYTHON_PREFIX}"
|
||||
HINTS "${PYTHON_INCLUDE_DIRS}/../.."
|
||||
PATH_SUFFIXES "lib" "libs"
|
||||
NO_DEFAULT_PATH)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"from distutils.sysconfig import *; print get_python_inc()"
|
||||
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
|
||||
SET(PYTHONLIBS_FOUND TRUE)
|
||||
message("-- Found PythonLibs: " ${PYTHON_LIBRARIES})
|
||||
message("-- -- Used custom search path")
|
||||
else()
|
||||
find_package(PythonLibs REQUIRED)
|
||||
message("-- -- Used find_package(PythonLibs)")
|
||||
endif()
|
||||
message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
# 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()
|
||||
endif()
|
||||
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})
|
||||
|
||||
find_package(NumPy REQUIRED)
|
||||
|
||||
@@ -50,31 +75,27 @@ include_directories("${NUMPY_INCLUDE_DIR}")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
if(UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
endif()
|
||||
|
||||
set(ARROW_DIR "${CMAKE_SOURCE_DIR}/thirdparty/arrow/" CACHE STRING
|
||||
"Path of the arrow source directory")
|
||||
set(ARROW_DIR "${CMAKE_SOURCE_DIR}/thirdparty/arrow/"
|
||||
CACHE STRING "Path of the arrow source directory")
|
||||
|
||||
if (APPLE)
|
||||
set(ARROW_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow.dylib" CACHE STRING
|
||||
"Path to libarrow.dylib (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.dylib" CACHE STRING
|
||||
"Path to libarrow_io.dylib (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.dylib" CACHE STRING
|
||||
"Path to libarrow_ipc.dylib (needs to be changed if arrow is build in debug mode)")
|
||||
if(APPLE)
|
||||
set(ARROW_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow.dylib"
|
||||
CACHE STRING "Path to libarrow.dylib (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.dylib"
|
||||
CACHE STRING "Path to libarrow_io.dylib (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.dylib"
|
||||
CACHE STRING "Path to libarrow_ipc.dylib (needs to be changed if arrow is build in debug mode)")
|
||||
else()
|
||||
set(ARROW_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow.so" CACHE STRING
|
||||
"Path to libarrow.so (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.so" CACHE STRING
|
||||
"Path to libarrow_io.so (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.so" CACHE STRING
|
||||
"Path to libarrow_ipc.so (needs to be changed if arrow is build in debug mode)")
|
||||
set(ARROW_LIB "${CMAKE_SOURCE_DIR}/thirdparty/arrow/cpp/build/release/libarrow.so"
|
||||
CACHE STRING "Path to libarrow.so (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.so"
|
||||
CACHE STRING "Path to libarrow_io.so (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.so"
|
||||
CACHE STRING "Path to libarrow_ipc.so (needs to be changed if arrow is build in debug mode)")
|
||||
endif()
|
||||
|
||||
include_directories("${ARROW_DIR}/cpp/src/")
|
||||
@@ -94,17 +115,13 @@ add_library(numbuf SHARED
|
||||
get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
|
||||
if(APPLE)
|
||||
add_custom_command(TARGET numbuf
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libnumbuf.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libnumbuf.so)
|
||||
add_custom_command(TARGET numbuf
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow.dylib" "@loader_path/libarrow.dylib" libnumbuf.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow.dylib" "@loader_path/libarrow.dylib" libnumbuf.so)
|
||||
add_custom_command(TARGET numbuf
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow_io.dylib" "@loader_path/libarrow_io.dylib" libnumbuf.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow_io.dylib" "@loader_path/libarrow_io.dylib" libnumbuf.so)
|
||||
add_custom_command(TARGET numbuf
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow_ipc.dylib" "@loader_path/libarrow_ipc.dylib" libnumbuf.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libarrow_ipc.dylib" "@loader_path/libarrow_ipc.dylib" libnumbuf.so)
|
||||
endif(APPLE)
|
||||
|
||||
target_link_libraries(numbuf ${ARROW_LIB} ${ARROW_IO_LIB} ${ARROW_IPC_LIB} ${PYTHON_LIBRARIES})
|
||||
|
||||
+52
-28
@@ -4,34 +4,59 @@ project(photon)
|
||||
|
||||
if(NOT APPLE)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
find_package(PythonLibs REQUIRED)
|
||||
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
|
||||
set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
else()
|
||||
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("-- Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_LIBRARY_NAME: " ${PYTHON_LIBRARY_NAME})
|
||||
# Now find the Python include directories.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_inc()"
|
||||
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.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_PREFIX: " ${PYTHON_PREFIX})
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
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.")
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
HINTS "${PYTHON_PREFIX}"
|
||||
HINTS "${PYTHON_INCLUDE_DIRS}/../.."
|
||||
PATH_SUFFIXES "lib" "libs"
|
||||
NO_DEFAULT_PATH)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"from distutils.sysconfig import *; print get_python_inc()"
|
||||
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
|
||||
SET(PYTHONLIBS_FOUND TRUE)
|
||||
message("-- Found PythonLibs: " ${PYTHON_LIBRARIES})
|
||||
message("-- -- Used custom search path")
|
||||
else()
|
||||
find_package(PythonLibs REQUIRED)
|
||||
message("-- -- Used find_package(PythonLibs)")
|
||||
endif()
|
||||
message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
# 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()
|
||||
endif()
|
||||
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})
|
||||
|
||||
if(APPLE)
|
||||
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||
@@ -41,15 +66,15 @@ include_directories("${PYTHON_INCLUDE_DIRS}")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} --std=c99 -Werror")
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
if(UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
endif()
|
||||
|
||||
set(PHOTON_CLIENT_LIB "${CMAKE_SOURCE_DIR}/build/photon_client.a" CACHE STRING
|
||||
"Path to photon_client.a")
|
||||
set(PHOTON_CLIENT_LIB "${CMAKE_SOURCE_DIR}/build/photon_client.a"
|
||||
CACHE STRING "Path to photon_client.a")
|
||||
|
||||
set(COMMON_LIB "${CMAKE_SOURCE_DIR}/../common/build/libcommon.a" CACHE STRING
|
||||
"Path to libcommon.a")
|
||||
set(COMMON_LIB "${CMAKE_SOURCE_DIR}/../common/build/libcommon.a"
|
||||
CACHE STRING "Path to libcommon.a")
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../")
|
||||
@@ -64,8 +89,7 @@ add_library(photon SHARED
|
||||
get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
|
||||
if(APPLE)
|
||||
add_custom_command(TARGET photon
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libphoton.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libphoton.so)
|
||||
endif(APPLE)
|
||||
|
||||
target_link_libraries(photon ${PHOTON_CLIENT_LIB} ${COMMON_LIB} ${PYTHON_LIBRARIES})
|
||||
|
||||
+50
-26
@@ -4,34 +4,59 @@ project(plasma)
|
||||
|
||||
if(NOT APPLE)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
find_package(PythonLibs REQUIRED)
|
||||
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED)
|
||||
set(CUSTOM_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
else()
|
||||
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("-- Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "Found Python program: ${CUSTOM_PYTHON_EXECUTABLE}")
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print 'python' + sys.version[0:3]"
|
||||
OUTPUT_VARIABLE PYTHON_LIBRARY_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_LIBRARY_NAME: " ${PYTHON_LIBRARY_NAME})
|
||||
# Now find the Python include directories.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_inc()"
|
||||
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.
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c "import sys; print sys.exec_prefix"
|
||||
OUTPUT_VARIABLE PYTHON_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
message(STATUS "PYTHON_PREFIX: " ${PYTHON_PREFIX})
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
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.")
|
||||
FIND_LIBRARY(PYTHON_LIBRARIES
|
||||
NAMES ${PYTHON_LIBRARY_NAME}
|
||||
HINTS "${PYTHON_PREFIX}"
|
||||
HINTS "${PYTHON_INCLUDE_DIRS}/../.."
|
||||
PATH_SUFFIXES "lib" "libs"
|
||||
NO_DEFAULT_PATH)
|
||||
execute_process(COMMAND ${CUSTOM_PYTHON_EXECUTABLE} -c
|
||||
"from distutils.sysconfig import *; print get_python_inc()"
|
||||
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
|
||||
SET(PYTHONLIBS_FOUND TRUE)
|
||||
message("-- Found PythonLibs: " ${PYTHON_LIBRARIES})
|
||||
message("-- -- Used custom search path")
|
||||
else()
|
||||
find_package(PythonLibs REQUIRED)
|
||||
message("-- -- Used find_package(PythonLibs)")
|
||||
endif()
|
||||
message(STATUS "PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
# 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()
|
||||
endif()
|
||||
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})
|
||||
|
||||
if(APPLE)
|
||||
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||
@@ -41,12 +66,12 @@ include_directories("${PYTHON_INCLUDE_DIRS}")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} --std=c99 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L")
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
if(UNIX AND NOT APPLE)
|
||||
link_libraries(rt)
|
||||
endif()
|
||||
|
||||
set(COMMON_LIB "${CMAKE_SOURCE_DIR}/../common/build/libcommon.a" CACHE STRING
|
||||
"Path to libcommon.a")
|
||||
set(COMMON_LIB "${CMAKE_SOURCE_DIR}/../common/build/libcommon.a"
|
||||
CACHE STRING "Path to libcommon.a")
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/")
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../")
|
||||
@@ -62,8 +87,7 @@ add_library(plasma SHARED
|
||||
get_filename_component(PYTHON_SHARED_LIBRARY ${PYTHON_LIBRARIES} NAME)
|
||||
if(APPLE)
|
||||
add_custom_command(TARGET plasma
|
||||
POST_BUILD COMMAND
|
||||
${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libplasma.so)
|
||||
POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change ${PYTHON_SHARED_LIBRARY} ${PYTHON_LIBRARIES} libplasma.so)
|
||||
endif(APPLE)
|
||||
|
||||
target_link_libraries(plasma ${COMMON_LIB} ${PYTHON_LIBRARIES})
|
||||
|
||||
Reference in New Issue
Block a user