Skip to content

Commit 560d5ad

Browse files
authored
export the targets with a python dependency to a different config file (rdkit#7914)
* export the targets with a python dependency to a different config file * add the forgotten file * improve the dependency from boost components * fix management of dependencies for RDKitPython * fix install location for RdkitPython cmake config file * fix finding boost components * put libraries that depend on rdkit_py_base in the python component
1 parent 4eb1ea9 commit 560d5ad

File tree

5 files changed

+81
-24
lines changed

5 files changed

+81
-24
lines changed

CMakeLists.txt

+31-4
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
305305
#-------
306306
# pull in python:
307307
find_package(Python3 COMPONENTS Interpreter Development.Module NumPy)
308-
target_include_directories(rdkit_base INTERFACE ${Python3_INCLUDE_DIRS})
309-
target_include_directories(rdkit_base INTERFACE ${Python3_NumPy_INCLUDE_DIRS})
308+
target_include_directories(rdkit_py_base INTERFACE ${Python3_INCLUDE_DIRS})
309+
target_include_directories(rdkit_py_base INTERFACE ${Python3_NumPy_INCLUDE_DIRS})
310310

311311
# determine linkage of python
312312
execute_process(
@@ -380,7 +380,7 @@ if(RDK_BUILD_PYTHON_WRAPPERS)
380380
endif()
381381

382382

383-
install(TARGETS rdkit_py_base EXPORT ${RDKit_EXPORTED_TARGETS}
383+
install(TARGETS rdkit_py_base EXPORT ${RDKitPython_EXPORTED_TARGETS}
384384
COMPONENT dev )
385385

386386
# check to see if we can find nbval,
@@ -604,6 +604,9 @@ if(RDK_BUILD_CONTRIB)
604604
endif(RDK_BUILD_CONTRIB)
605605

606606
# export the project targets (to be included in the cmake package configuration)
607+
include(CMakePackageConfigHelpers)
608+
609+
# first manage the targets for the base C++ toolkit
607610
install(
608611
EXPORT ${RDKit_EXPORTED_TARGETS}
609612
FILE ${RDKit_EXPORTED_TARGETS}.cmake
@@ -612,7 +615,6 @@ install(
612615
)
613616

614617
# create and install package configuration and version files
615-
include(CMakePackageConfigHelpers)
616618
write_basic_package_version_file(
617619
"${RDKit_BINARY_DIR}/rdkit-config-version.cmake"
618620
VERSION ${RDKit_RELEASENAME}
@@ -628,6 +630,31 @@ install(FILES
628630
${RDKit_BINARY_DIR}/rdkit-config-version.cmake
629631
DESTINATION ${RDKit_LibDir}/cmake/rdkit)
630632

633+
# then manage the targets for the python bindings
634+
if(RDK_BUILD_PYTHON_WRAPPERS)
635+
install(
636+
EXPORT ${RDKitPython_EXPORTED_TARGETS}
637+
FILE ${RDKitPython_EXPORTED_TARGETS}.cmake
638+
NAMESPACE RDKit::
639+
DESTINATION ${RDKit_LibDir}/cmake/rdkitpython
640+
)
641+
642+
write_basic_package_version_file(
643+
"${RDKit_BINARY_DIR}/rdkitpython-config-version.cmake"
644+
VERSION ${RDKit_RELEASENAME}
645+
COMPATIBILITY AnyNewerVersion
646+
)
647+
648+
configure_file (
649+
${RDKit_SOURCE_DIR}/rdkitpython-config.cmake.in
650+
${RDKit_BINARY_DIR}/rdkitpython-config.cmake @ONLY)
651+
652+
install(FILES
653+
${RDKit_BINARY_DIR}/rdkitpython-config.cmake
654+
${RDKit_BINARY_DIR}/rdkitpython-config-version.cmake
655+
DESTINATION ${RDKit_LibDir}/cmake/rdkitpython)
656+
endif(RDK_BUILD_PYTHON_WRAPPERS)
657+
631658
# Memory testing setup
632659
FIND_PROGRAM(MEMORYCHECK_COMMAND valgrind)
633660
CONFIGURE_FILE(CTestCustom.ctest.in ${RDKit_BINARY_DIR}/CTestCustom.ctest)

Code/RDBoost/CMakeLists.txt

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
if(WIN32 OR "${Py_ENABLE_SHARED}" STREQUAL "1")
2-
rdkit_library(RDBoost Wrap.cpp
3-
LINK_LIBRARIES RDGeneral rdkit_py_base rdkit_base)
4-
else()
5-
rdkit_library(RDBoost Wrap.cpp
6-
LINK_LIBRARIES RDGeneral rdkit_base)
7-
if("${PYTHON_LDSHARED}" STREQUAL "")
8-
else() # fixes an apple issue
9-
STRING(REGEX REPLACE "-bundle" "" LDSHARED ${PYTHON_LDSHARED})
10-
set_target_properties(RDBoost PROPERTIES LINK_FLAGS ${LDSHARED})
11-
endif()
1+
rdkit_library(RDBoost Wrap.cpp
2+
LINK_LIBRARIES RDGeneral rdkit_py_base)
3+
if(NOT WIN32 AND
4+
NOT "${Py_ENABLE_SHARED}" STREQUAL "1" AND
5+
NOT "${PYTHON_LDSHARED}" STREQUAL "")
6+
# fixes an apple issue
7+
STRING(REGEX REPLACE "-bundle" "" LDSHARED ${PYTHON_LDSHARED})
8+
set_target_properties(RDBoost PROPERTIES LINK_FLAGS ${LDSHARED})
129
endif()
1310
target_compile_definitions(RDBoost PRIVATE RDKIT_RDBOOST_BUILD)
1411

Code/cmake/Modules/RDKitUtils.cmake

+24-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ else()
2424
endif()
2525
set(RDKit_BUILDNAME "${CMAKE_SYSTEM_NAME}|${CMAKE_SYSTEM_VERSION}|${systemAttribute}|${compilerID}|${bit3264}")
2626
set(RDKit_EXPORTED_TARGETS rdkit-targets)
27+
set(RDKitPython_EXPORTED_TARGETS rdkitpython-targets)
2728

2829

2930
macro(rdkit_library)
@@ -33,13 +34,25 @@ macro(rdkit_library)
3334
${ARGN})
3435
CAR(RDKLIB_NAME ${RDKLIB_DEFAULT_ARGS})
3536
CDR(RDKLIB_SOURCES ${RDKLIB_DEFAULT_ARGS})
37+
# select the export and component name for the installed library
38+
set(exportName ${RDKit_EXPORTED_TARGETS})
39+
set(sharedLibComponent runtime)
40+
set(staticLibComponent dev)
41+
foreach(linkLib ${RDKLIB_LINK_LIBRARIES})
42+
if("${linkLib}" STREQUAL "rdkit_py_base")
43+
set(exportName ${RDKitPython_EXPORTED_TARGETS})
44+
set(sharedLibComponent python)
45+
set(staticLibComponent python)
46+
break()
47+
endif()
48+
endforeach()
3649
if((MSVC AND (NOT RDK_INSTALL_DLLS_MSVC)) OR (WIN32 AND RDK_INSTALL_STATIC_LIBS))
3750
add_library(${RDKLIB_NAME} ${RDKLIB_SOURCES})
3851
target_link_libraries(${RDKLIB_NAME} PUBLIC rdkit_base)
3952
if(RDK_INSTALL_DEV_COMPONENT)
40-
INSTALL(TARGETS ${RDKLIB_NAME} EXPORT ${RDKit_EXPORTED_TARGETS}
53+
INSTALL(TARGETS ${RDKLIB_NAME} EXPORT ${exportName}
4154
DESTINATION ${RDKit_LibDir}/${RDKLIB_DEST}
42-
COMPONENT dev )
55+
COMPONENT ${staticLibComponent})
4356
endif(RDK_INSTALL_DEV_COMPONENT)
4457
else()
4558
# we're going to always build in shared mode since we
@@ -48,9 +61,9 @@ macro(rdkit_library)
4861
# with g++ unless libraries are shared.
4962
add_library(${RDKLIB_NAME} SHARED ${RDKLIB_SOURCES})
5063
target_link_libraries(${RDKLIB_NAME} PUBLIC rdkit_base)
51-
INSTALL(TARGETS ${RDKLIB_NAME} EXPORT ${RDKit_EXPORTED_TARGETS}
64+
INSTALL(TARGETS ${RDKLIB_NAME} EXPORT ${exportName}
5265
DESTINATION ${RDKit_LibDir}/${RDKLIB_DEST}
53-
COMPONENT runtime )
66+
COMPONENT ${sharedLibComponent})
5467
if(RDK_INSTALL_STATIC_LIBS)
5568
add_library(${RDKLIB_NAME}_static ${RDKLIB_SOURCES})
5669

@@ -60,7 +73,11 @@ macro(rdkit_library)
6073
set(skipNext FALSE)
6174
continue()
6275
endif()
63-
if(TARGET "${linkLib}")
76+
if("${linkLib}" STREQUAL "rdkit_py_base")
77+
# rdkit_py_base is an interface target, keep it as-is
78+
target_link_libraries(${RDKLIB_NAME}_static PUBLIC "${linkLib}")
79+
continue()
80+
elseif(TARGET "${linkLib}")
6481
get_target_property(linkLib_IMPORTED "${linkLib}" IMPORTED)
6582
if (linkLib_IMPORTED)
6683
# linkLib is an imported target: use it as-is
@@ -97,9 +114,9 @@ macro(rdkit_library)
97114
endforeach()
98115
target_link_libraries(${RDKLIB_NAME}_static PUBLIC rdkit_base)
99116
if(RDK_INSTALL_DEV_COMPONENT)
100-
INSTALL(TARGETS ${RDKLIB_NAME}_static EXPORT ${RDKit_EXPORTED_TARGETS}
117+
INSTALL(TARGETS ${RDKLIB_NAME}_static EXPORT ${exportName}
101118
DESTINATION ${RDKit_LibDir}/${RDKLIB_DEST}
102-
COMPONENT dev )
119+
COMPONENT ${staticLibComponent})
103120
endif(RDK_INSTALL_DEV_COMPONENT)
104121
set_target_properties(${RDKLIB_NAME}_static PROPERTIES
105122
OUTPUT_NAME "RDKit${RDKLIB_NAME}_static")

rdkit-config.cmake.in

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ set(RDKit_HAS_URF_SUPPORT @RDK_USE_URF@)
2424
set(RDKit_USE_OPTIMIZED_POPCNT @RDK_OPTIMIZE_POPCNT@)
2525
set(RDKit_USE_STRICT_ROTOR_DEFINITION @RDK_USE_STRICT_ROTOR_DEFINITION@)
2626
set(RDKit_USE_BOOST_VERSION @Boost_VERSION_STRING@)
27-
set(RDKit_USE_BOOST_SERIALIZATION @RDK_USE_BOOST_SERIALIZATION@)
27+
set(RDKit_USE_BOOST_COMPONENTS system)
2828
set(RDKit_USE_BOOST_IOSTREAMS @RDK_USE_BOOST_IOSTREAMS@)
29+
if (RDKit_USE_BOOST_IOSTREAMS)
30+
set(RDKit_USE_BOOST_COMPONENTS ${RDKit_USE_BOOST_COMPONENTS} iostreams)
31+
endif()
32+
set(RDKit_USE_BOOST_SERIALIZATION @RDK_USE_BOOST_SERIALIZATION@)
33+
if (RDKit_USE_BOOST_SERIALIZATION)
34+
set(RDKit_USE_BOOST_COMPONENTS ${RDKit_USE_BOOST_COMPONENTS} serialization)
35+
endif()
2936

3037
# Find the RDKit dependencies
3138
include(CMakeFindDependencyMacro)
3239

3340
find_dependency(Threads REQUIRED)
3441

35-
find_dependency(Boost @Boost_VERSION_STRING@ REQUIRED)
42+
find_dependency(Boost @Boost_VERSION_STRING@ COMPONENTS headers ${RDKit_USE_BOOST_COMPONENTS})
3643

3744
if(RDKit_HAS_DESCRIPTORS3D)
3845
find_dependency(Eigen3 REQUIRED NO_MODULE)

rdkitpython-config.cmake.in

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Find the RDKitPython dependencies
2+
include(CMakeFindDependencyMacro)
3+
4+
find_dependency(Python3 @Python3_VERSION_MAJOR@.@Python3_VERSION_MINOR@ COMPONENTS Interpreter Development.Module NumPy)
5+
find_dependency(Boost @Boost_VERSION_STRING@ COMPONENTS python@Python3_VERSION_MAJOR@@Python3_VERSION_MINOR@ numpy@Python3_VERSION_MAJOR@@Python3_VERSION_MINOR@)
6+
find_dependency(RDKit @RDKit_RELEASENAME@ REQUIRED)
7+
8+
# Import the targets
9+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

0 commit comments

Comments
 (0)