From 6c387f9a0cf85f63dec2c3521a97eb458ded075a Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sun, 3 Mar 2024 22:49:42 -0500 Subject: [PATCH] can use modularized Boost, even if built as part of the main project --- export/cmake/CMakeLists.txt.export | 25 +++++++++++++++++++++---- export/cmake/libint2-config.cmake.in | 2 +- python/CMakeLists.txt | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/export/cmake/CMakeLists.txt.export b/export/cmake/CMakeLists.txt.export index 8c2b78a43..7398d3a35 100644 --- a/export/cmake/CMakeLists.txt.export +++ b/export/cmake/CMakeLists.txt.export @@ -121,14 +121,31 @@ if (REQUIRE_CXX_API AND NOT ${LIBINT_HAS_CXX_API}) endif() if (NOT LIBINT_USE_BUNDLED_BOOST) - if (NOT TARGET Boost::boost) + if (NOT TARGET Boost::headers) find_package(Boost 1.29) endif() - if (TARGET Boost::boost) + if (TARGET Boost::headers) cmake_push_check_state() list(APPEND CMAKE_REQUIRED_FLAGS "-std=c++11") - list(APPEND CMAKE_REQUIRED_LIBRARIES Boost::boost) + + # since Boost::headers is an ALIAS pass the real target to check_cxx_source_compiles + get_target_property(Boost_target_for_linking Boost::headers ALIASED_TARGET) + if (NOT Boost_target_for_linking) + set(Boost_target_for_linking Boost::headers) + endif() + # corner case: if using modularized Boost then use boost_preprocessor target directly + if (TARGET boost_preprocessor) + set(Boost_target_for_linking boost_preprocessor) + endif() + get_target_property(Boost_target_for_linking_is_imported ${Boost_target_for_linking} IMPORTED) + if (Boost_target_for_linking_is_imported) + list(APPEND CMAKE_REQUIRED_LIBRARIES ${Boost_target_for_linking}) + else() + get_target_property(Boost_target_for_linking_interface_include_directories ${Boost_target_for_linking} INTERFACE_INCLUDE_DIRECTORIES) + string(REGEX REPLACE ".*;?\\$]*)>;?.*" "\\1" Boost_target_for_linking_build_interface_include_directories "${Boost_target_for_linking_interface_include_directories}") + list(APPEND CMAKE_REQUIRED_INCLUDES ${Boost_target_for_linking_build_interface_include_directories}) + endif() check_cxx_source_compiles(" #include @@ -327,7 +344,7 @@ if (LIBINT_HAS_CXX_API) target_compile_features(libint2_cxx INTERFACE "cxx_std_11") target_link_libraries(libint2_cxx INTERFACE ${int2_library} libint2_Eigen) if (LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS) - target_link_libraries(libint2_cxx INTERFACE Boost::boost) + target_link_libraries(libint2_cxx INTERFACE Boost::headers) endif(LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS) if(MSVC) # MSVC does not include constants, unless _USE_MATH_DEFINES is defined. diff --git a/export/cmake/libint2-config.cmake.in b/export/cmake/libint2-config.cmake.in index 9989dbfc3..b6c808802 100644 --- a/export/cmake/libint2-config.cmake.in +++ b/export/cmake/libint2-config.cmake.in @@ -35,7 +35,7 @@ if(NOT TARGET Libint2::libint2) endif() # if relied on system Boost for preprocessor variadics, make sure it's available -if (LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS AND NOT TARGET Boost::boost) +if (LIBINT_HAS_SYSTEM_BOOST_PREPROCESSOR_VARIADICS AND NOT TARGET Boost::headers) include(CMakeFindDependencyMacro) find_dependency(Boost 1.29) endif() diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c869c4855..e3b66e49d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -84,7 +84,7 @@ if (TARGET libint2_obj) endif() target_link_libraries(libint2-python PRIVATE libint2_obj) - target_link_libraries(libint2-python PRIVATE Boost::boost) + target_link_libraries(libint2-python PRIVATE Boost::headers) else() find_package(Libint2 REQUIRED) target_link_libraries(libint2-python PRIVATE Libint2::cxx)