Skip to content

Commit 67f507a

Browse files
authored
Some cmake cleanup work (rdkit#7720)
* 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
1 parent b340eb9 commit 67f507a

File tree

12 files changed

+69
-183
lines changed

12 files changed

+69
-183
lines changed

.azure-pipelines/linux_build_py37.yml

Lines changed: 0 additions & 74 deletions
This file was deleted.

.azure-pipelines/vs_build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ steps:
66
conda info -a
77
conda install -n base conda-libmamba-solver
88
conda config --set solver libmamba
9-
conda create --name rdkit_build ^
10-
boost-cpp=$(boost_version) boost=$(boost_version) ^
11-
py-boost=$(boost_version) libboost=$(boost_version) ^
12-
numpy matplotlib=3.8 cairo pillow eigen pandas=2.1
9+
conda create --name rdkit_build -c conda-forge $(python) ^
10+
boost=$(boost_version) boost-cpp=$(boost_version) ^
11+
libboost-python-devel=(boost_version) ^
12+
libboost=$(boost_version) ^
13+
libboost-devel=$(boost_version) ^
14+
numpy matplotlib cairo pillow eigen pandas=2.1
1315
call activate rdkit_build
14-
conda install -c conda-forge sphinx myst-parser ipython=8.20 jupyter pytest nbval
16+
conda install -c conda-forge sphinx myst-parser ipython jupyter pytest nbval
1517
conda install -c conda-forge cmake
1618
displayName: Install dependencies
1719
- script: |
@@ -40,8 +42,6 @@ steps:
4042
-DRDK_BUILD_CFFI_LIB=ON ^
4143
-DRDK_SWIG_STATIC=OFF ^
4244
-DRDK_TEST_MULTITHREADED=ON ^
43-
-DRDK_BOOST_PYTHON3_NAME=$(python_name) ^
44-
-DBoost_NO_BOOST_CMAKE=TRUE ^
4545
-DCMAKE_INCLUDE_PATH=%CONDA_PREFIX%/Library/include ^
4646
-DCMAKE_LIBRARY_PATH="%CONDA_PREFIX%/Library/lib
4747
displayName: Configure build (Run CMake)

.azure-pipelines/vs_build_dll.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ steps:
66
conda info -a
77
conda install -n base conda-libmamba-solver
88
conda config --set solver libmamba
9-
conda create --name rdkit_build ^
10-
boost-cpp=$(boost_version) boost=$(boost_version) ^
9+
conda create --name rdkit_build -c conda-forge $(python) ^
10+
boost=$(boost_version) boost-cpp=$(boost_version) ^
11+
libboost-python-devel=(boost_version) ^
1112
libboost=$(boost_version) ^
12-
numpy matplotlib=3.8 cairo pillow eigen pandas=2.1
13+
libboost-devel=$(boost_version) ^
14+
numpy matplotlib cairo pillow eigen pandas=2.1
1315
call activate rdkit_build
14-
conda install -c conda-forge cmake ipython=8.20 pytest nbval
16+
conda install -c conda-forge cmake ipython pytest nbval
1517
displayName: Install dependencies
1618
- script: |
1719
set Boost_ROOT=
@@ -39,7 +41,6 @@ steps:
3941
-DRDK_BUILD_SWIG_WRAPPERS=OFF ^
4042
-DRDK_SWIG_STATIC=OFF ^
4143
-DRDK_TEST_MULTITHREADED=ON ^
42-
-DBoost_NO_BOOST_CMAKE=TRUE ^
4344
-DCMAKE_INCLUDE_PATH=%CONDA_PREFIX%/Library/include ^
4445
-DCMAKE_LIBRARY_PATH="%CONDA_PREFIX%/Library/lib
4546
displayName: Configure build (Run CMake)

CMakeLists.txt

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.16)
22

33
project (RDKit)
44

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

74-
set(RDK_BOOST_VERSION "1.58.0")
74+
set(RDK_BOOST_VERSION "1.70.0")
7575

7676
if(NOT MSVC)
7777
if(RDK_OPTIMIZE_POPCNT)
@@ -150,7 +150,7 @@ set(RDKit_ExternalDir "${CMAKE_CURRENT_SOURCE_DIR}/External")
150150
set(RDKit_DataDir "${CMAKE_CURRENT_SOURCE_DIR}/Data")
151151

152152
#include catch
153-
find_package(Catch2 3)
153+
find_package(Catch2 3 QUIET)
154154
if(NOT Catch2_FOUND)
155155
Include(FetchContent)
156156

@@ -290,59 +290,26 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
290290

291291
#-------
292292
# pull in python:
293-
find_package(PythonInterp)
294-
if (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
295-
set(Python_ADDITIONAL_VERSIONS "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
296-
endif (PYTHONINTERP_FOUND AND NOT Python_ADDITIONAL_VERSIONS)
297-
298-
if(PYTHON_VERSION_MAJOR EQUAL 2)
299-
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.")
300-
endif()
301-
302-
find_package(PythonLibs)
303-
target_include_directories(rdkit_base INTERFACE ${PYTHON_INCLUDE_DIR})
293+
find_package(Python3 COMPONENTS Interpreter Development NumPy)
294+
target_include_directories(rdkit_base INTERFACE ${Python3_INCLUDE_DIRS})
295+
target_include_directories(rdkit_base INTERFACE ${Python3_NumPy_INCLUDE_DIRS})
304296

305297
# determine linkage of python
306298
execute_process(
307299
COMMAND
308-
${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
300+
${Python3_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
309301
OUTPUT_VARIABLE Py_ENABLE_SHARED
310302
OUTPUT_STRIP_TRAILING_WHITESPACE
311303
)
312304

313305
if(WIN32 OR "${Py_ENABLE_SHARED}" STREQUAL "1")
314-
target_link_libraries(rdkit_py_base INTERFACE ${PYTHON_LIBRARIES} )
315-
endif()
316-
317-
find_package(NumPy REQUIRED)
318-
target_include_directories(rdkit_base INTERFACE ${PYTHON_NUMPY_INCLUDE_PATH})
319-
320-
if(PYTHON_VERSION_MAJOR EQUAL 3)
321-
# Find boost-python3 using name specified as command line option then fall back to commonly used names
322-
set(RDK_BOOST_PYTHON3_NAME "python3" CACHE STRING "Name of the boost python3 library. If installed as libboost_python-xxx.so, use python-xxx.")
323-
list(APPEND Boost_Python_Names "${RDK_BOOST_PYTHON3_NAME}" "python-py3${PYTHON_VERSION_MINOR}" "python3")
324-
endif(PYTHON_VERSION_MAJOR EQUAL 3)
325-
326-
# Boost 1.67+ uses a version suffix like "python36" or "python27"
327-
list(APPEND Boost_Python_Names "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
328-
329-
# Try each potential boost-python name until one works
330-
foreach(Boost_Python_LibN ${Boost_Python_Names})
331-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS "${Boost_Python_LibN}" QUIET)
332-
if(Boost_FOUND)
333-
set(Boost_Python_Lib ${Boost_Python_LibN})
334-
break()
335-
endif()
336-
endforeach()
337-
# Finally just try "python" and hope it is a compatible version
338-
if(NOT Boost_FOUND)
339-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS python REQUIRED)
340-
set(Boost_Python_Lib "python")
306+
target_link_libraries(rdkit_py_base INTERFACE ${Python3_LIBRARY} )
341307
endif()
342308

343-
find_package(Boost COMPONENTS "numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}" REQUIRED)
309+
310+
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" "numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" REQUIRED CONFIG)
344311

345-
target_link_libraries(rdkit_py_base INTERFACE Boost::${Boost_Python_Lib} "Boost::numpy${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
312+
target_link_libraries(rdkit_py_base INTERFACE "Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}" "Boost::numpy${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
346313

347314
if(RDK_INSTALL_INTREE)
348315
set(RDKit_PythonDir "${CMAKE_SOURCE_DIR}/rdkit")
@@ -351,7 +318,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
351318
# Determine correct installation directory for Python bindings
352319
execute_process(
353320
COMMAND
354-
${PYTHON_EXECUTABLE} -c "import sys; import sysconfig; \
321+
${Python3_EXECUTABLE} -c "import sys; import sysconfig; \
355322
base_key = 'base' if sys.platform == 'win32' else 'platbase'; \
356323
schema = 'nt' if sys.platform == 'win32' else 'posix_prefix'; \
357324
print(sysconfig.get_path('platlib', schema, vars={base_key: '${CMAKE_INSTALL_PREFIX}'}))"
@@ -392,21 +359,20 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
392359
# We strip off the first word though (which will be the compiler name).
393360
execute_process(
394361
COMMAND
395-
${PYTHON_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('LDSHARED').lstrip().split(' ', 1)[1])"
362+
${Python3_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('LDSHARED').lstrip().split(' ', 1)[1])"
396363
OUTPUT_VARIABLE PYTHON_LDSHARED
397364
OUTPUT_STRIP_TRAILING_WHITESPACE
398365
)
399-
message("PYTHON Py_ENABLE_SHARED: ${Py_ENABLE_SHARED}")
400-
message("PYTHON USING LINK LINE: ${PYTHON_LDSHARED}")
401366
endif()
402367

368+
403369
install(TARGETS rdkit_py_base EXPORT ${RDKit_EXPORTED_TARGETS}
404370
COMPONENT dev )
405371

406372
# check to see if we can find nbval,
407373
execute_process(
408374
COMMAND
409-
${PYTHON_EXECUTABLE} -c "import nbval"
375+
${Python3_EXECUTABLE} -c "import nbval"
410376
ERROR_VARIABLE nbvalERR
411377
OUTPUT_STRIP_TRAILING_WHITESPACE)
412378
if(NOT nbvalERR)
@@ -416,7 +382,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
416382
endif()
417383

418384
else(RDK_BUILD_PYTHON_WRAPPERS)
419-
find_package(Boost ${RDK_BOOST_VERSION} REQUIRED)
385+
find_package(Boost ${RDK_BOOST_VERSION} REQUIRED CONFIG)
420386
endif(RDK_BUILD_PYTHON_WRAPPERS)
421387

422388
find_package(Eigen3)
@@ -452,7 +418,7 @@ else()
452418
endif()
453419

454420
if(RDK_USE_BOOST_SERIALIZATION)
455-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system serialization iostreams REQUIRED)
421+
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system serialization iostreams REQUIRED CONFIG)
456422
target_link_libraries(rdkit_base INTERFACE ${Boost_LIBRARIES})
457423
target_compile_definitions(rdkit_base INTERFACE -DRDK_USE_BOOST_SERIALIZATION)
458424
if(NOT Boost_USE_STATIC_LIBS)
@@ -462,7 +428,7 @@ endif()
462428

463429
if(RDK_USE_BOOST_IOSTREAMS)
464430
target_compile_definitions(rdkit_base INTERFACE -DRDK_USE_BOOST_IOSTREAMS)
465-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system iostreams REQUIRED)
431+
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS system iostreams REQUIRED CONFIG)
466432
target_link_libraries(rdkit_base INTERFACE ${Boost_LIBRARIES})
467433

468434
if (NOT Boost_USE_STATIC_LIBS)
@@ -471,7 +437,7 @@ if(RDK_USE_BOOST_IOSTREAMS)
471437

472438
# deal with zlib
473439
if (WIN32)
474-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS zlib)
440+
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS zlib CONFIG)
475441
if(Boost_zlib_FOUND)
476442
set(zlib_lib Boost::zlib)
477443
endif()

Code/GraphMol/FilterCatalog/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ if(NOT RDK_USE_BOOST_SERIALIZATION)
22
message("== Making FilterCatalog without boost Serialization support")
33
endif()
44

5-
find_package(PythonInterp)
6-
if (PYTHONINTERP_FOUND)
7-
if(DEFINED PYTHON_VERSION_STRING AND ${PYTHON_VERSION_STRING} VERSION_GREATER "2.6" )
5+
find_package(Python3 COMPONENTS Interpreter)
6+
if (Python3::Interpreter)
87
message("== Updating Filters.cpp from pains file")
98
execute_process(
109
COMMAND
@@ -14,7 +13,6 @@ if (PYTHONINTERP_FOUND)
1413
if(NOT rc EQUAL 0)
1514
message(FATAL_ERROR "Failed updating Filters.cpp from wehi_pains.csv")
1615
endif(NOT rc EQUAL 0)
17-
endif()
1816
endif()
1917

2018

Code/GraphMol/RGroupDecomposition/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ rdkit_test(testRGroupDecompInternals testRGroupInternals.cpp
2323
rdkit_catch_test(rgroupCatchTests catch_rgd.cpp
2424
LINK_LIBRARIES RGroupDecomposition )
2525

26-
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS program_options)
26+
find_package(Boost ${RDK_BOOST_VERSION} COMPONENTS program_options CONFIG)
2727
if(RDK_BUILD_CPP_TESTS AND Boost_FOUND)
2828
add_executable(gaExample GaExample.cpp)
2929
if(NOT Boost_USE_STATIC_LIBS)

Code/cmake/Modules/CodeCoverage.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Covera
8686
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
8787
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
8888

89+
find_package(Python3 COMPONENTS Interpreter)
8990

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

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

145-
IF(NOT PYTHON_EXECUTABLE)
146+
IF(NOT Python3_EXECUTABLE)
146147
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
147148
ENDIF() # NOT PYTHON_EXECUTABLE
148149

Code/cmake/Modules/RDKitUtils.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ macro(rdkit_python_extension)
145145
CAR(RDKPY_NAME ${RDKPY_DEFAULT_ARGS})
146146
CDR(RDKPY_SOURCES ${RDKPY_DEFAULT_ARGS})
147147
if(RDK_BUILD_PYTHON_WRAPPERS)
148-
PYTHON_ADD_MODULE(${RDKPY_NAME} ${RDKPY_SOURCES})
148+
Python3_add_library(${RDKPY_NAME} MODULE ${RDKPY_SOURCES})
149149
set_target_properties(${RDKPY_NAME} PROPERTIES PREFIX "")
150150

151151
if(WIN32)
@@ -158,7 +158,7 @@ macro(rdkit_python_extension)
158158
${RDK_PYTHON_OUTPUT_DIRECTORY}/${RDKPY_DEST})
159159
endif(WIN32)
160160

161-
target_link_libraries(${RDKPY_NAME} ${RDKPY_LINK_LIBRARIES}
161+
target_link_libraries(${RDKPY_NAME} PUBLIC ${RDKPY_LINK_LIBRARIES}
162162
RDBoost rdkit_py_base rdkit_base )
163163
if("${PYTHON_LDSHARED}" STREQUAL "")
164164
else()
@@ -206,23 +206,23 @@ macro(add_pytest)
206206
CAR(PYTEST_NAME ${PYTEST_DEFAULT_ARGS})
207207
CDR(PYTEST_SOURCES ${PYTEST_DEFAULT_ARGS})
208208
if(RDK_BUILD_PYTHON_WRAPPERS)
209-
add_test(${PYTEST_NAME} ${PYTHON_EXECUTABLE}
209+
add_test(${PYTEST_NAME} ${Python3_EXECUTABLE}
210210
${PYTEST_SOURCES})
211211
SET(RDKIT_PYTEST_CACHE "${PYTEST_NAME};${RDKIT_PYTEST_CACHE}" CACHE INTERNAL "Global list of python tests")
212212
endif(RDK_BUILD_PYTHON_WRAPPERS)
213213
endmacro(add_pytest)
214214

215215
function(add_jupytertest testname workingdir notebook)
216216
if(RDK_BUILD_PYTHON_WRAPPERS AND RDK_NBVAL_AVAILABLE)
217-
add_test(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} -m pytest --nbval ${notebook}
217+
add_test(NAME ${testname} COMMAND ${Python3_EXECUTABLE} -m pytest --nbval ${notebook}
218218
WORKING_DIRECTORY ${workingdir} )
219219
SET(RDKIT_JUPYTERTEST_CACHE "${testname};${RDKIT_JUPYTERTEST_CACHE}" CACHE INTERNAL "Global list of jupyter tests")
220220
endif()
221221
endfunction(add_jupytertest)
222222

223223
function(add_pythonpytest testname workingdir)
224224
if(RDK_BUILD_PYTHON_WRAPPERS)
225-
add_test(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} -m pytest
225+
add_test(NAME ${testname} COMMAND ${Python3_EXECUTABLE} -m pytest
226226
WORKING_DIRECTORY ${workingdir} )
227227
SET(RDKIT_PYTHONTEST_CACHE "${testname};${RDKIT_PYTHONTEST_CACHE}" CACHE INTERNAL "Global list of pytest tests")
228228
endif()

0 commit comments

Comments
 (0)