Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] migrate cmake to use FindPython instead of FindPythonInterp+FindPythonLibs #7393

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-pipelines/vs_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ steps:
conda install -n base conda-libmamba-solver
conda config --set solver libmamba
conda create --name rdkit_build ^
cmake ^
boost-cpp=$(boost_version) boost=$(boost_version) ^
py-boost=$(boost_version) libboost=$(boost_version) ^
numpy matplotlib=3.8 cairo pillow eigen pandas=2.1
call activate rdkit_build
conda install -c conda-forge sphinx myst-parser ipython=8.20 jupyter pytest nbval
conda install -c conda-forge cmake
displayName: Install dependencies
- script: |
set Boost_ROOT=
Expand Down
33 changes: 13 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,38 +290,31 @@ if(RDK_BUILD_PYTHON_WRAPPERS)

#-------
# pull in python:
find_package(PythonInterp)
if (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
endif (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
find_package(Python COMPONENTS Interpreter Development NumPy REQUIRED)

if(PYTHON_VERSION_MAJOR EQUAL 2)
message(FATAL_ERROR "ERROR: The RDKit no longer supports Python 2.\nIf you have Python 3 installed, you can tell cmake where to find it using the -DPYTHON_EXECUTABLE argument.")
if(Python_VERSION_MAJOR EQUAL 2)
message(FATAL_ERROR "ERROR: The RDKit no longer supports Python 2.\nIf you have Python 3 installed, you can tell cmake where to find it using the -DPython_ROOT_DIR argument.")
endif()

find_package(PythonLibs)
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_DIR})
target_include_directories(rdkit_base INTERFACE ${Python_INCLUDE_DIRS})

# determine linkage of python
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
OUTPUT_VARIABLE Py_ENABLE_SHARED
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(WIN32 OR "${Py_ENABLE_SHARED}" STREQUAL "1")
target_link_libraries(rdkit_py_base INTERFACE ${PYTHON_LIBRARIES} )
target_link_libraries(rdkit_py_base INTERFACE ${Python_LIBRARIES} )
endif()

find_package(NumPy REQUIRED)
target_include_directories(rdkit_base INTERFACE ${PYTHON_NUMPY_INCLUDE_PATH})
target_include_directories(rdkit_base INTERFACE ${Python_NumPy_INCLUDE_DIRS})

if(PYTHON_VERSION_MAJOR EQUAL 3)
# Find boost-python3 using name specified as command line option then fall back to commonly used names
set(RDK_BOOST_PYTHON3_NAME "python3" CACHE STRING "Name of the boost python3 library. If installed as libboost_python-xxx.so, use python-xxx.")
list(APPEND Boost_Python_Names "${RDK_BOOST_PYTHON3_NAME}" "python-py3${PYTHON_VERSION_MINOR}" "python3")
endif(PYTHON_VERSION_MAJOR EQUAL 3)
# Find boost-python3 using name specified as command line option then fall back to commonly used names
set(RDK_BOOST_PYTHON3_NAME "python3" CACHE STRING "Name of the boost python3 library. If installed as libboost_python-xxx.so, use python-xxx.")
list(APPEND Boost_Python_Names "${RDK_BOOST_PYTHON3_NAME}" "python-py3${PYTHON_VERSION_MINOR}" "python3")

# Boost 1.67+ uses a version suffix like "python36" or "python27"
list(APPEND Boost_Python_Names "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
Expand Down Expand Up @@ -349,7 +342,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
# Determine correct installation directory for Python bindings
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sys; import sysconfig; \
${Python_EXECUTABLE} -c "import sys; import sysconfig; \
base_key = 'base' if sys.platform == 'win32' else 'platbase'; \
schema = 'nt' if sys.platform == 'win32' else 'posix_prefix'; \
print(sysconfig.get_path('platlib', schema, vars={base_key: '${CMAKE_INSTALL_PREFIX}'}))"
Expand Down Expand Up @@ -390,7 +383,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
# We strip off the first word though (which will be the compiler name).
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('LDSHARED').lstrip().split(' ', 1)[1])"
${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('LDSHARED').lstrip().split(' ', 1)[1])"
OUTPUT_VARIABLE PYTHON_LDSHARED
OUTPUT_STRIP_TRAILING_WHITESPACE
)
Expand All @@ -404,7 +397,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
# check to see if we can find nbval,
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import nbval"
${Python_EXECUTABLE} -c "import nbval"
ERROR_VARIABLE nbvalERR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT nbvalERR)
Expand Down
26 changes: 12 additions & 14 deletions Code/GraphMol/FilterCatalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ if(NOT RDK_USE_BOOST_SERIALIZATION)
message("== Making FilterCatalog without boost Serialization support")
endif()

find_package(PythonInterp)
if (PYTHONINTERP_FOUND)
if(DEFINED PYTHON_VERSION_STRING AND ${PYTHON_VERSION_STRING} VERSION_GREATER "2.6" )
message("== Updating Filters.cpp from pains file")
execute_process(
COMMAND
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/update_pains.py
RESULT_VARIABLE rc
)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "Failed updating Filters.cpp from wehi_pains.csv")
endif(NOT rc EQUAL 0)
endif()
find_package(Python COMPONENTS Interpreter)
if (Python_Interpreter_FOUND)
message("== Updating Filters.cpp from pains file")
execute_process(
COMMAND
${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/update_pains.py
RESULT_VARIABLE rc
)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "Failed updating Filters.cpp from wehi_pains.csv")
endif(NOT rc EQUAL 0)
endif()


rdkit_library(FilterCatalog
Filters.cpp
FilterCatalog.cpp
FilterCatalogEntry.cpp
FilterCatalogRunner.cpp
FilterCatalogRunner.cpp
FilterMatchers.cpp
FunctionalGroupHierarchy.cpp
LINK_LIBRARIES Subgraphs SubstructMatch SmilesParse
Expand Down
23 changes: 8 additions & 15 deletions Code/cmake/Modules/RDKitUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,13 @@ macro(rdkit_python_extension)
CAR(RDKPY_NAME ${RDKPY_DEFAULT_ARGS})
CDR(RDKPY_SOURCES ${RDKPY_DEFAULT_ARGS})
if(RDK_BUILD_PYTHON_WRAPPERS)
PYTHON_ADD_MODULE(${RDKPY_NAME} ${RDKPY_SOURCES})
set_target_properties(${RDKPY_NAME} PROPERTIES PREFIX "")
Python_add_library(${RDKPY_NAME} MODULE ${RDKPY_SOURCES})

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)
set_target_properties(${RDKPY_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})

target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
target_link_libraries(${RDKPY_NAME} PRIVATE ${RDKPY_LINK_LIBRARIES}
RDBoost rdkit_py_base rdkit_base )
if("${PYTHON_LDSHARED}" STREQUAL "")
else()
Expand Down Expand Up @@ -206,23 +199,23 @@ macro(add_pytest)
CAR(PYTEST_NAME ${PYTEST_DEFAULT_ARGS})
CDR(PYTEST_SOURCES ${PYTEST_DEFAULT_ARGS})
if(RDK_BUILD_PYTHON_WRAPPERS)
add_test(${PYTEST_NAME} ${PYTHON_EXECUTABLE}
add_test(${PYTEST_NAME} ${Python_EXECUTABLE}
${PYTEST_SOURCES})
SET(RDKIT_PYTEST_CACHE "${PYTEST_NAME};${RDKIT_PYTEST_CACHE}" CACHE INTERNAL "Global list of python tests")
endif(RDK_BUILD_PYTHON_WRAPPERS)
endmacro(add_pytest)

function(add_jupytertest testname workingdir notebook)
if(RDK_BUILD_PYTHON_WRAPPERS AND RDK_NBVAL_AVAILABLE)
add_test(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} -m pytest --nbval ${notebook}
add_test(NAME ${testname} COMMAND ${Python_EXECUTABLE} -m pytest --nbval ${notebook}
WORKING_DIRECTORY ${workingdir} )
SET(RDKIT_JUPYTERTEST_CACHE "${testname};${RDKIT_JUPYTERTEST_CACHE}" CACHE INTERNAL "Global list of jupyter tests")
endif()
endfunction(add_jupytertest)

function(add_pythonpytest testname workingdir)
if(RDK_BUILD_PYTHON_WRAPPERS)
add_test(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} -m pytest
add_test(NAME ${testname} COMMAND ${Python_EXECUTABLE} -m pytest
WORKING_DIRECTORY ${workingdir} )
SET(RDKIT_PYTHONTEST_CACHE "${testname};${RDKIT_PYTHONTEST_CACHE}" CACHE INTERNAL "Global list of pytest tests")
endif()
Expand Down