Skip to content

Commit

Permalink
Some cmake cleanup work (rdkit#7720)
Browse files Browse the repository at this point in the history
* cmake modernization

- get rid of some warnings
- switch to what I hope is the correct way of doing things
- bump min cmake version to 3.16
- bump min boost version to 1.70

This builds on linux

* remove some usages of PYTHON_EXECUTABLE

* remove old-school python usage from coverage tests

* remove unused CI file

* bump boost version for windows builds to 1.84

* still trying to get the ci builds working

* typo

* eventually the CI will work

* robustify some tests
  • Loading branch information
greglandrum authored Aug 16, 2024
1 parent b340eb9 commit 67f507a
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 183 deletions.
74 changes: 0 additions & 74 deletions .azure-pipelines/linux_build_py37.yml

This file was deleted.

14 changes: 7 additions & 7 deletions .azure-pipelines/vs_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ steps:
conda info -a
conda install -n base conda-libmamba-solver
conda config --set solver libmamba
conda create --name rdkit_build ^
boost-cpp=$(boost_version) boost=$(boost_version) ^
py-boost=$(boost_version) libboost=$(boost_version) ^
numpy matplotlib=3.8 cairo pillow eigen pandas=2.1
conda create --name rdkit_build -c conda-forge $(python) ^
boost=$(boost_version) boost-cpp=$(boost_version) ^
libboost-python-devel=(boost_version) ^
libboost=$(boost_version) ^
libboost-devel=$(boost_version) ^
numpy matplotlib 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 sphinx myst-parser ipython jupyter pytest nbval
conda install -c conda-forge cmake
displayName: Install dependencies
- script: |
Expand Down Expand Up @@ -40,8 +42,6 @@ steps:
-DRDK_BUILD_CFFI_LIB=ON ^
-DRDK_SWIG_STATIC=OFF ^
-DRDK_TEST_MULTITHREADED=ON ^
-DRDK_BOOST_PYTHON3_NAME=$(python_name) ^
-DBoost_NO_BOOST_CMAKE=TRUE ^
-DCMAKE_INCLUDE_PATH=%CONDA_PREFIX%/Library/include ^
-DCMAKE_LIBRARY_PATH="%CONDA_PREFIX%/Library/lib
displayName: Configure build (Run CMake)
Expand Down
11 changes: 6 additions & 5 deletions .azure-pipelines/vs_build_dll.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ steps:
conda info -a
conda install -n base conda-libmamba-solver
conda config --set solver libmamba
conda create --name rdkit_build ^
boost-cpp=$(boost_version) boost=$(boost_version) ^
conda create --name rdkit_build -c conda-forge $(python) ^
boost=$(boost_version) boost-cpp=$(boost_version) ^
libboost-python-devel=(boost_version) ^
libboost=$(boost_version) ^
numpy matplotlib=3.8 cairo pillow eigen pandas=2.1
libboost-devel=$(boost_version) ^
numpy matplotlib cairo pillow eigen pandas=2.1
call activate rdkit_build
conda install -c conda-forge cmake ipython=8.20 pytest nbval
conda install -c conda-forge cmake ipython pytest nbval
displayName: Install dependencies
- script: |
set Boost_ROOT=
Expand Down Expand Up @@ -39,7 +41,6 @@ steps:
-DRDK_BUILD_SWIG_WRAPPERS=OFF ^
-DRDK_SWIG_STATIC=OFF ^
-DRDK_TEST_MULTITHREADED=ON ^
-DBoost_NO_BOOST_CMAKE=TRUE ^
-DCMAKE_INCLUDE_PATH=%CONDA_PREFIX%/Library/include ^
-DCMAKE_LIBRARY_PATH="%CONDA_PREFIX%/Library/lib
displayName: Configure build (Run CMake)
Expand Down
72 changes: 19 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.16)

project (RDKit)

Expand Down Expand Up @@ -71,7 +71,7 @@ option(RDK_BUILD_MINIMAL_LIB_RXN "build support for reactions into MinimalLib" O
option(RDK_BUILD_MINIMAL_LIB_SUBSTRUCTLIBRARY "build support for SubstructLibrary into MinimalLib" ON )
option(RDK_BUILD_MINIMAL_LIB_MCS "build support for MCS into MinimalLib" OFF )

set(RDK_BOOST_VERSION "1.58.0")
set(RDK_BOOST_VERSION "1.70.0")

if(NOT MSVC)
if(RDK_OPTIMIZE_POPCNT)
Expand Down Expand Up @@ -150,7 +150,7 @@ set(RDKit_ExternalDir "${CMAKE_CURRENT_SOURCE_DIR}/External")
set(RDKit_DataDir "${CMAKE_CURRENT_SOURCE_DIR}/Data")

#include catch
find_package(Catch2 3)
find_package(Catch2 3 QUIET)
if(NOT Catch2_FOUND)
Include(FetchContent)

Expand Down Expand Up @@ -290,59 +290,26 @@ 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)

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.")
endif()

find_package(PythonLibs)
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_DIR})
find_package(Python3 COMPONENTS Interpreter Development NumPy)
target_include_directories(rdkit_base INTERFACE ${Python3_INCLUDE_DIRS})
target_include_directories(rdkit_base INTERFACE ${Python3_NumPy_INCLUDE_DIRS})

# determine linkage of python
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
${Python3_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} )
endif()

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

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)

# Boost 1.67+ uses a version suffix like "python36" or "python27"
list(APPEND Boost_Python_Names "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")

# Try each potential boost-python name until one works
foreach(Boost_Python_LibN ${Boost_Python_Names})
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS "${Boost_Python_LibN}" QUIET)
if(Boost_FOUND)
set(Boost_Python_Lib ${Boost_Python_LibN})
break()
endif()
endforeach()
# Finally just try "python" and hope it is a compatible version
if(NOT Boost_FOUND)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS python REQUIRED)
set(Boost_Python_Lib "python")
target_link_libraries(rdkit_py_base INTERFACE ${Python3_LIBRARY} )
endif()

find_package(Boost COMPONENTS "numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}" REQUIRED)

find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" "numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" REQUIRED CONFIG)

target_link_libraries(rdkit_py_base INTERFACE Boost::${Boost_Python_Lib} "Boost::numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
target_link_libraries(rdkit_py_base INTERFACE "Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" "Boost::numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")

if(RDK_INSTALL_INTREE)
set(RDKit_PythonDir "${CMAKE_SOURCE_DIR}/rdkit")
Expand All @@ -351,7 +318,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
# Determine correct installation directory for Python bindings
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sys; import sysconfig; \
${Python3_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 @@ -392,21 +359,20 @@ 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])"
${Python3_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('LDSHARED').lstrip().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()


install(TARGETS rdkit_py_base EXPORT ${RDKit_EXPORTED_TARGETS}
COMPONENT dev )

# check to see if we can find nbval,
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import nbval"
${Python3_EXECUTABLE} -c "import nbval"
ERROR_VARIABLE nbvalERR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT nbvalERR)
Expand All @@ -416,7 +382,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
endif()

else(RDK_BUILD_PYTHON_WRAPPERS)
find_package(Boost ${RDK_BOOST_VERSION} REQUIRED)
find_package(Boost ${RDK_BOOST_VERSION} REQUIRED CONFIG)
endif(RDK_BUILD_PYTHON_WRAPPERS)

find_package(Eigen3)
Expand Down Expand Up @@ -452,7 +418,7 @@ else()
endif()

if(RDK_USE_BOOST_SERIALIZATION)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system serialization iostreams REQUIRED)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system serialization iostreams REQUIRED CONFIG)
target_link_libraries(rdkit_base INTERFACE ${Boost_LIBRARIES})
target_compile_definitions(rdkit_base INTERFACE -DRDK_USE_BOOST_SERIALIZATION)
if(NOT Boost_USE_STATIC_LIBS)
Expand All @@ -462,7 +428,7 @@ endif()

if(RDK_USE_BOOST_IOSTREAMS)
target_compile_definitions(rdkit_base INTERFACE -DRDK_USE_BOOST_IOSTREAMS)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system iostreams REQUIRED)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system iostreams REQUIRED CONFIG)
target_link_libraries(rdkit_base INTERFACE ${Boost_LIBRARIES})

if (NOT Boost_USE_STATIC_LIBS)
Expand All @@ -471,7 +437,7 @@ if(RDK_USE_BOOST_IOSTREAMS)

# deal with zlib
if (WIN32)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS zlib)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS zlib CONFIG)
if(Boost_zlib_FOUND)
set(zlib_lib Boost::zlib)
endif()
Expand Down
6 changes: 2 additions & 4 deletions Code/GraphMol/FilterCatalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ 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" )
find_package(Python3 COMPONENTS Interpreter)
if (Python3::Interpreter)
message("== Updating Filters.cpp from pains file")
execute_process(
COMMAND
Expand All @@ -14,7 +13,6 @@ if (PYTHONINTERP_FOUND)
if(NOT rc EQUAL 0)
message(FATAL_ERROR "Failed updating Filters.cpp from wehi_pains.csv")
endif(NOT rc EQUAL 0)
endif()
endif()


Expand Down
2 changes: 1 addition & 1 deletion Code/GraphMol/RGroupDecomposition/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ rdkit_test(testRGroupDecompInternals testRGroupInternals.cpp
rdkit_catch_test(rgroupCatchTests catch_rgd.cpp
LINK_LIBRARIES RGroupDecomposition )

find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS program_options)
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS program_options CONFIG)
if(RDK_BUILD_CPP_TESTS AND Boost_FOUND)
add_executable(gaExample GaExample.cpp)
if(NOT Boost_USE_STATIC_LIBS)
Expand Down
5 changes: 3 additions & 2 deletions Code/cmake/Modules/CodeCoverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Covera
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"

find_package(Python3 COMPONENTS Interpreter)

# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
Expand Down Expand Up @@ -118,7 +119,7 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' '*.ll' '*.yy' --output-file ${_outputname}.info.cleaned
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Code/cmake/Modules/fixup_coverage.py ${CMAKE_SOURCE_DIR} ${_outputname}.info.cleaned
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Code/cmake/Modules/fixup_coverage.py ${CMAKE_SOURCE_DIR} ${_outputname}.info.cleaned

COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
Expand All @@ -142,7 +143,7 @@ ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)

IF(NOT PYTHON_EXECUTABLE)
IF(NOT Python3_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE

Expand Down
10 changes: 5 additions & 5 deletions Code/cmake/Modules/RDKitUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ 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})
Python3_add_library(${RDKPY_NAME} MODULE ${RDKPY_SOURCES})
set_target_properties(${RDKPY_NAME} PROPERTIES PREFIX "")

if(WIN32)
Expand All @@ -158,7 +158,7 @@ macro(rdkit_python_extension)
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
endif(WIN32)

target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
target_link_libraries(${RDKPY_NAME} PUBLIC ${RDKPY_LINK_LIBRARIES}
RDBoost rdkit_py_base rdkit_base )
if("${PYTHON_LDSHARED}" STREQUAL "")
else()
Expand Down Expand Up @@ -206,23 +206,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} ${Python3_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 ${Python3_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 ${Python3_EXECUTABLE} -m pytest
WORKING_DIRECTORY ${workingdir} )
SET(RDKIT_PYTHONTEST_CACHE "${testname};${RDKIT_PYTHONTEST_CACHE}" CACHE INTERNAL "Global list of pytest tests")
endif()
Expand Down
Loading

0 comments on commit 67f507a

Please sign in to comment.