From 9535165149d16a2a944a81f4888d3ab0a7358027 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 27 Feb 2018 21:11:10 +0800 Subject: [PATCH] cmake: add implicit dependencies between boost libs so the dependencies can be included when linking against the one which depends on them. for example, libboost_filesystem depends on libboost_system, if we don't link against the latter, linker will bail out when linking an executable using Boost::filesystem. Signed-off-by: Kefu Chai --- cmake/modules/BuildBoost.cmake | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmake/modules/BuildBoost.cmake b/cmake/modules/BuildBoost.cmake index e71f389e0f6a5..12105575cb2fa 100644 --- a/cmake/modules/BuildBoost.cmake +++ b/cmake/modules/BuildBoost.cmake @@ -168,6 +168,12 @@ function(do_build_boost version) PREFIX "${boost_root_dir}") endfunction() +set(Boost_context_DEPENDENCIES thread chrono system date_time) +set(Boost_coroutine_DEPENDENCIES context system) +set(Boost_filesystem_DEPENDENCIES system) +set(Boost_iostreams_DEPENDENCIES regex) +set(Boost_thread_DEPENDENCIES chrono system date_time atomic) + macro(build_boost version) do_build_boost(${version} ${ARGN}) ExternalProject_Get_Property(Boost install_dir) @@ -177,6 +183,16 @@ macro(build_boost version) # target file(MAKE_DIRECTORY ${Boost_INCLUDE_DIRS}) cmake_parse_arguments(Boost_BUILD "" "" COMPONENTS ${ARGN}) + foreach(c ${Boost_BUILD_COMPONENTS}) + list(APPEND components ${c}) + if(Boost_${c}_DEPENDENCIES) + list(APPEND components ${Boost_${c}_DEPENDENCIES}) + list(REMOVE_DUPLICATES components) + endif() + endforeach() + set(Boost_BUILD_COMPONENTS ${components}) + unset(components) + foreach(c ${Boost_BUILD_COMPONENTS}) string(TOUPPER ${c} upper_c) if(Boost_USE_STATIC_LIBS) @@ -204,6 +220,16 @@ macro(build_boost version) IMPORTED_LOCATION "${Boost_${upper_c}_LIBRARY}") list(APPEND Boost_LIBRARIES ${Boost_${upper_c}_LIBRARY}) endforeach() + foreach(c ${Boost_BUILD_COMPONENTS}) + if(Boost_${c}_DEPENDENCIES) + foreach(dep ${Boost_${c}_DEPENDENCIES}) + list(APPEND dependencies Boost::${dep}) + endforeach() + set_target_properties(Boost::${c} PROPERTIES + INTERFACE_LINK_LIBRARIES "${dependencies}") + unset(dependencies) + endif() + endforeach() # for header-only libraries if(CMAKE_VERSION VERSION_LESS 3.3) -- 2.39.5