Skip to content

Commit

Permalink
Merge pull request #333 from evaleev/332-cant-use-boost-build-using-c…
Browse files Browse the repository at this point in the history
…make-aka-modularized-boost

can use modularized Boost, even if built as part of the main project
  • Loading branch information
evaleev authored Mar 4, 2024
2 parents c0115e1 + 6c387f9 commit 2ab0295
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions export/cmake/CMakeLists.txt.export
Original file line number Diff line number Diff line change
Expand Up @@ -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 ".*;?\\$<BUILD_INTERFACE:([^>]*)>;?.*" "\\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 <boost/preprocessor.hpp>
Expand Down Expand Up @@ -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 <cmath> constants, unless _USE_MATH_DEFINES is defined.
Expand Down
2 changes: 1 addition & 1 deletion export/cmake/libint2-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2ab0295

Please sign in to comment.