]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: define BUILD_BYPRODUCTS for Boost
authorKefu Chai <kchai@redhat.com>
Thu, 4 Mar 2021 07:46:42 +0000 (15:46 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 9 Mar 2021 11:13:22 +0000 (19:13 +0800)
so if a cmake generator needs any one of them, it knowns how to build
it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/BuildBoost.cmake

index ba86ecaa63ce12b29cf09002e8f9d1cd419c4742..30445db829bc2df9b72104f6516e00fd1c5e7d5a 100644 (file)
@@ -44,7 +44,7 @@ macro(list_replace list old new)
   unset(where)
 endmacro()
 
-function(do_build_boost version)
+function(do_build_boost root_dir version)
   cmake_parse_arguments(Boost_BUILD "" "" COMPONENTS ${ARGN})
   set(boost_features "variant=release")
   if(Boost_USE_MULTITHREADED)
@@ -140,7 +140,6 @@ function(do_build_boost version)
     ${boost_features})
   set(install_command
     ${b2} install)
-  set(boost_root_dir "${CMAKE_BINARY_DIR}/boost")
   if(EXISTS "${PROJECT_SOURCE_DIR}/src/boost/bootstrap.sh")
     check_boost_version("${PROJECT_SOURCE_DIR}/src/boost" ${version})
     set(source_dir
@@ -174,8 +173,9 @@ function(do_build_boost version)
     CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ${configure_command}
     BUILD_COMMAND CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ${build_command}
     BUILD_IN_SOURCE 1
+    BUILD_BYPRODUCTS ${Boost_LIBRARIES}
     INSTALL_COMMAND ${install_command}
-    PREFIX "${boost_root_dir}")
+    PREFIX "${root_dir}")
 endfunction()
 
 set(Boost_context_DEPENDENCIES thread chrono system date_time)
@@ -184,9 +184,12 @@ set(Boost_filesystem_DEPENDENCIES system)
 set(Boost_iostreams_DEPENDENCIES regex)
 set(Boost_thread_DEPENDENCIES chrono system date_time atomic)
 
+# define a macro, so the Boost_* variables are visible by its caller
 macro(build_boost version)
-  do_build_boost(${version} ${ARGN})
-  ExternalProject_Get_Property(Boost install_dir)
+  # add the Boost::${component} libraries, do this before adding the "Boost"
+  # target, so we can collect "Boost_LIBRARIES" which is then used by
+  # ExternalProject_Add(Boost ...)
+  set(install_dir "${CMAKE_BINARY_DIR}/boost")
   set(Boost_INCLUDE_DIRS ${install_dir}/include)
   set(Boost_INCLUDE_DIR ${install_dir}/include)
   set(Boost_VERSION ${version})
@@ -211,7 +214,6 @@ macro(build_boost version)
     else()
       add_library(Boost::${c} SHARED IMPORTED)
     endif()
-    add_dependencies(Boost::${c} Boost)
     if(c MATCHES "^python")
       set(c "python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}")
     endif()
@@ -229,7 +231,7 @@ macro(build_boost version)
       IMPORTED_LOCATION "${Boost_${upper_c}_LIBRARY}")
     if((c MATCHES "coroutine|context") AND (WITH_BOOST_VALGRIND))
       set_target_properties(Boost::${c} PROPERTIES
-       INTERFACE_COMPILE_DEFINITIONS "BOOST_USE_VALGRIND")
+        INTERFACE_COMPILE_DEFINITIONS "BOOST_USE_VALGRIND")
     endif()
     list(APPEND Boost_LIBRARIES ${Boost_${upper_c}_LIBRARY})
   endforeach()
@@ -245,6 +247,14 @@ macro(build_boost version)
     set(Boost_${c}_FOUND "TRUE")
   endforeach()
 
+  # download, bootstrap and build Boost
+  do_build_boost(${install_dir} ${version} ${ARGN})
+
+  # add dependencies from Boost::${component} to Boost
+  foreach(c ${Boost_BUILD_COMPONENTS})
+    add_dependencies(Boost::${c} Boost)
+  endforeach()
+
   # for header-only libraries
   add_library(Boost::boost INTERFACE IMPORTED)
   set_target_properties(Boost::boost PROPERTIES