mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Fix python linkage (#1808)
* apply (manually) #1807 from @bp-kelley to modern_cxx branch and fix (hopefully) a windows problem * another windows problem * another windows problem * windows now builds locally * update link targets
This commit is contained in:
@@ -169,11 +169,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
|
||||
endif (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
|
||||
find_package(PythonLibs)
|
||||
if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
|
||||
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_PATH})
|
||||
else(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
|
||||
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_DIR})
|
||||
endif(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 6)
|
||||
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_DIR})
|
||||
find_package(NumPy REQUIRED)
|
||||
target_include_directories(rdkit_base INTERFACE ${PYTHON_NUMPY_INCLUDE_PATH})
|
||||
|
||||
@@ -235,6 +231,28 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
|
||||
endif(RDK_INSTALL_INTREE)
|
||||
|
||||
# determine linkage of python
|
||||
execute_process(
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
|
||||
OUTPUT_VARIABLE Py_ENABLE_SHARED
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
if(NOT WIN32)
|
||||
# See https://bugs.python.org/msg277944
|
||||
# The "command to create shared modules". Used as variable in the "Makefile (and similar) templates to build python modules"
|
||||
# for both in-python and third party modules. Initialized to hold the value which works for third party modules to link
|
||||
# against the _installed_ python.
|
||||
# We strip off the first word though (which will be the compiler name).
|
||||
execute_process(
|
||||
COMMAND
|
||||
${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_config_var('LDSHARED').split(' ', 1)[1])"
|
||||
OUTPUT_VARIABLE PYTHON_LDSHARED
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
message("PYTHON Py_ENABLE_SHARED: ${Py_ENABLE_SHARED}")
|
||||
message("PYTHON USING LINK LINE: ${PYTHON_LDSHARED}")
|
||||
endif()
|
||||
else(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
find_package(Boost 1.56.0 REQUIRED)
|
||||
endif(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
rdkit_library(RDBoost Wrap.cpp
|
||||
LINK_LIBRARIES RDGeneral ${PYTHON_LIBRARIES} ${Boost_IMPORTED_LIBRARIES})
|
||||
if(WIN32 OR "${Py_ENABLE_SHARED}" STREQUAL "1")
|
||||
rdkit_library(RDBoost Wrap.cpp
|
||||
LINK_LIBRARIES RDGeneral ${PYTHON_LIBRARIES} ${Boost_IMPORTED_LIBRARIES})
|
||||
else()
|
||||
rdkit_library(RDBoost Wrap.cpp
|
||||
LINK_LIBRARIES RDGeneral ${Boost_IMPORTED_LIBRARIES})
|
||||
if("${PYTHON_LDSHARED}" STREQUAL "")
|
||||
else()
|
||||
# fixes an apple issue
|
||||
STRING(REGEX REPLACE "-bundle" "" LDSHARED ${PYTHON_LDSHARED})
|
||||
set_target_properties(RDBoost PROPERTIES LINK_FLAGS ${LDSHARED})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
rdkit_headers(Wrap.h PySequenceHolder.h
|
||||
list_indexing_suite.hpp
|
||||
@@ -13,7 +24,7 @@ add_subdirectory(Wrap)
|
||||
if(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
# this is a particularly nasty little bit of hackery.
|
||||
# cmake (as of 2.8) ignores the ADDITIONAL_MAKE_CLEAN_FILES argument
|
||||
# unless it's in a directory that actualy has a target. So in order to
|
||||
# unless it's in a directory that actualy has a target. So in order to
|
||||
# cleanup files created by the python tests we have to put something
|
||||
# here with the ugly relative path
|
||||
IF(COMMAND cmake_policy)
|
||||
|
||||
@@ -115,17 +115,29 @@ macro(rdkit_python_extension)
|
||||
if(RDK_BUILD_PYTHON_WRAPPERS)
|
||||
PYTHON_ADD_MODULE(${RDKPY_NAME} ${RDKPY_SOURCES})
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES PREFIX "")
|
||||
if(WIN32)
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES SUFFIX ".pyd"
|
||||
LIBRARY_OUTPUT_DIRECTORY
|
||||
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
|
||||
else(WIN32)
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY
|
||||
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
|
||||
endif(WIN32)
|
||||
target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
|
||||
${PYTHON_LIBRARIES} ${Boost_IMPORTED_LIBRARIES} )
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES SUFFIX ".pyd"
|
||||
LIBRARY_OUTPUT_DIRECTORY
|
||||
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
|
||||
else(WIN32)
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES
|
||||
LIBRARY_OUTPUT_DIRECTORY
|
||||
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
|
||||
endif(WIN32)
|
||||
|
||||
if(WIN32 OR "${Py_ENABLE_SHARED}" STREQUAL "1")
|
||||
target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
|
||||
${PYTHON_LIBRARIES} ${Boost_IMPORTED_LIBRARIES} )
|
||||
else()
|
||||
target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
|
||||
${Boost_IMPORTED_LIBRARIES} )
|
||||
if("${PYTHON_LDSHARED}" STREQUAL "")
|
||||
else()
|
||||
message("set_target_properties ${RDKPY_NAME} PROPERTIES LINK_FLAGS ${PYTHON_LDSHARED}")
|
||||
set_target_properties(${RDKPY_NAME} PROPERTIES LINK_FLAGS ${PYTHON_LDSHARED})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
INSTALL(TARGETS ${RDKPY_NAME}
|
||||
LIBRARY DESTINATION ${RDKit_PythonDir}/${RDKPY_DEST} COMPONENT python)
|
||||
|
||||
Reference in New Issue
Block a user