With that combination the first search seems to happen in CONFIG mode but subsequent searches will use MODULE mode. This will result in the following warning: CMake Warning at /usr/share/cmake-3.18/Modules/FindBoost.cmake:1187 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): /usr/share/cmake-3.18/Modules/FindBoost.cmake:1311 (_Boost_COMPONENT_DEPENDENCIES) /usr/share/cmake-3.18/Modules/FindBoost.cmake:1919 (_Boost_MISSING_DEPENDENCIES) cmake/Modules/OpmFind.cmake:135 (find_package) cmake/Modules/OpmFind.cmake:230 (find_and_append_package_to) cmake/Modules/OpmLibMain.cmake:83 (find_and_append_package_list_to) CMakeLists.txt:222 (include) Also the variable Boost_LIBRARIES will look quite messed up by occurrences of optimized and debug: Boost_LIBRARIES=optimized;/usr/lib/x86_64-linux-gnu/libboost_system.so.1.74.0;debug;/usr/lib/x86_64-linux-gnu/libboost_system.so;optimized;/usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0;debug;/usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so Which will make the modules unusable because of CMake errors during linking: CMake Error at /usr/share/dune/cmake/modules/DuneMacros.cmake:991 (target_link_libraries): The "debug" argument must be followed by a library. Call Stack (most recent call first): src/CMakeLists.txt:2 (target_link_dune_default_libraries) -- Configuring incomplete, errors occurred! Note this fix is only needed for Boost versions 1.70 and higher. Older versions do not provide cmake package configuration files (BoostConfig.cmake) and hence there can be no mixup. Note also that the alternative approach of setting CMAKE_FIND_PACKAGE_PREFER_CONFIG does not work for OPM as with this e.g. the Dune module versions would not be set correctly.
44 lines
1.5 KiB
CMake
44 lines
1.5 KiB
CMake
# When using Boost >= 1.70 and e.g. CMake 3.18 we need to make sure that
|
|
# subsequent searches are using config mode too. Otherwise the library
|
|
# list will be completely messed up. We use a set Boost_Dir to detect that
|
|
# previous searches were done using config mode.
|
|
if(Boost_DIR)
|
|
set(_Boost_CONFIG_MODE CONFIG)
|
|
endif()
|
|
find_package (Boost 1.44.0 COMPONENTS unit_test_framework QUIET ${_Boost_CONFIG_MODE})
|
|
|
|
if (Boost_UNIT_TEST_FRAMEWORK_FOUND)
|
|
# setup to do a test compile
|
|
include (CMakePushCheckState)
|
|
cmake_push_check_state ()
|
|
include (CheckCXXSourceCompiles)
|
|
list (APPEND CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
|
|
list (APPEND CMAKE_REQUIRED_LIBRARIES ${Boost_LIBRARIES})
|
|
|
|
unset(HAVE_DYNAMIC_BOOST_TEST CACHE)
|
|
check_cxx_source_compiles("
|
|
#define BOOST_TEST_DYN_LINK
|
|
#define BOOST_TEST_MODULE DYNLINK_TEST
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
int f(int x) { return 2 * x; }
|
|
|
|
BOOST_AUTO_TEST_CASE(DynlinkConfigureTest) {
|
|
BOOST_CHECK_MESSAGE(f(2) == 4,
|
|
\"Apparently, multiplication doesn't \"
|
|
\"work: f(2) = \" << f(2));
|
|
}" HAVE_DYNAMIC_BOOST_TEST)
|
|
cmake_pop_check_state ()
|
|
else (Boost_UNIT_TEST_FRAMEWORK_FOUND)
|
|
# no Boost, no compile
|
|
set (HAVE_DYNAMIC_BOOST_TEST 0)
|
|
endif (Boost_UNIT_TEST_FRAMEWORK_FOUND)
|
|
|
|
# save this for later
|
|
set (HAVE_DYNAMIC_BOOST_TEST "${HAVE_DYNAMIC_BOOST_TEST}"
|
|
CACHE BOOL "Whether Boost::Test is dynamically linked or not"
|
|
)
|
|
|
|
# include in config.h
|
|
list (APPEND TESTING_CONFIG_VARS "HAVE_DYNAMIC_BOOST_TEST")
|