diff --git a/CMakeLists.txt b/CMakeLists.txt index c71f314..3c96404 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # Copyright 2018 Mike Dev # Copyright 2019 Peter Dimov -# Copyright 2020-2021 Andrey Semashev +# Copyright 2020-2022 Andrey Semashev # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt @@ -12,28 +12,13 @@ include(CheckCXXSourceCompiles) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -# Generates a list of include paths for all Boost libraries in \a result variable. Uses unified Boost include tree, if available. -function(generate_boost_include_paths result) - if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../boost" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../../boost/version.hpp") - set(${result} "${CMAKE_CURRENT_SOURCE_DIR}/../.." PARENT_SCOPE) - return() - endif() - file(GLOB path_list LIST_DIRECTORIES True "${CMAKE_CURRENT_SOURCE_DIR}/../*") - foreach(path IN LISTS path_list) - if (IS_DIRECTORY "${path}/include") - list(APPEND include_list "${path}/include") - endif() - endforeach() - set(${result} ${include_list} PARENT_SCOPE) -endfunction() - # Note: We can't use the Boost::library targets in the configure checks as they may not yet be included # by the superproject when this CMakeLists.txt is included. We also don't want to hardcode include paths # of the needed libraries and their dependencies, recursively, as this is too fragile and requires maintenance. # Instead, we collect include paths of all libraries and use them in the configure checks. This works faster # if there is a unified Boost include tree in the filesystem (i.e. if `b2 headers` was run or we're in the # official monolithic Boost distribution tree). -generate_boost_include_paths(BOOST_LIBRARY_INCLUDES) +include(cmake/BoostLibraryIncludes.cmake) set(boost_atomic_sources src/lock_pool.cpp) diff --git a/cmake/BoostLibraryIncludes.cmake b/cmake/BoostLibraryIncludes.cmake new file mode 100644 index 0000000..b875bbd --- /dev/null +++ b/cmake/BoostLibraryIncludes.cmake @@ -0,0 +1,37 @@ +# Copyright 2022 Andrey Semashev +# +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt +# +# After including this module, BOOST_LIBRARY_INCLUDES variable is set to the list of include +# directories for all Boost libraries. If the monolithic include directory is found, it is +# used instead. + +if (NOT CMAKE_VERSION VERSION_LESS 3.10) + include_guard() +endif() + +# Generates a list of include paths for all Boost libraries in \a result variable. Uses unified Boost include tree, if available. +function(generate_boost_include_paths result) + if (IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../../../boost" AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../../boost/version.hpp") + get_filename_component(include_dir "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) + set(${result} "${include_dir}" PARENT_SCOPE) + return() + endif() + file(GLOB path_list LIST_DIRECTORIES True "${CMAKE_CURRENT_LIST_DIR}/../../../libs/*") + foreach(path IN LISTS path_list) + if (IS_DIRECTORY "${path}/include") + get_filename_component(include_dir "${path}/include" ABSOLUTE) + list(APPEND include_list "${include_dir}") + endif() + endforeach() + set(${result} ${include_list} PARENT_SCOPE) +endfunction() + +if (NOT DEFINED BOOST_LIBRARY_INCLUDES) + generate_boost_include_paths(__BOOST_LIBRARY_INCLUDES) + # Save the paths in a global property to avoid scanning the filesystem if this module is used in multiple libraries + set(BOOST_LIBRARY_INCLUDES ${__BOOST_LIBRARY_INCLUDES} CACHE INTERNAL "List of all Boost library include paths") + unset(__BOOST_LIBRARY_INCLUDES) + # message(STATUS "Boost library includes: ${BOOST_LIBRARY_INCLUDES}") +endif()