Skip to content

Commit

Permalink
can use bundled Boost.CallableTraits only if don't have real Boost an…
Browse files Browse the repository at this point in the history
…d TTG_FETCH_BOOST is not set
  • Loading branch information
evaleev committed Feb 1, 2024
1 parent 549ba94 commit f05530f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ option(TTG_EXAMPLES "Whether to build examples" OFF)
option(TTG_ENABLE_ASAN "Whether to enable address sanitizer" OFF)

option(TTG_FETCH_BOOST "Whether to fetch+build Boost, if missing" OFF)
option(TTG_IGNORE_BUNDLED_EXTERNALS "Whether to skip installation and use of bundled external depenedencies (Boost.CallableTraits)" OFF)
option(TTG_IGNORE_BUNDLED_EXTERNALS "Whether to skip installation and use of bundled external dependencies (Boost.CallableTraits)" OFF)
option(TTG_ENABLE_TRACE "Whether to enable ttg::trace() output" OFF)
# See https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/ExternalDependenciesVersions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# need Boost.CallableTraits (header only, part of Boost 1.66 released in Dec 2017) for wrap.h to work
set(TTG_TRACKED_BOOST_VERSION 1.66)
set(TTG_TRACKED_VG_CMAKE_KIT_TAG d5c0a6f9ff6dc97cbb5132912733e1eb1cf73f1e) # used to provide "real" FindOrFetchBoost
set(TTG_TRACKED_VG_CMAKE_KIT_TAG 7ea2d4d3f8854b9e417f297fd74d6fc49aa13fd5) # used to provide "real" FindOrFetchBoost
set(TTG_TRACKED_CATCH2_VERSION 3.5.0)
set(TTG_TRACKED_CEREAL_VERSION 1.3.0)
set(TTG_TRACKED_MADNESS_TAG 8788aea9758bfe6479cc23d39e6c77b7528009db)
Expand Down
29 changes: 21 additions & 8 deletions cmake/modules/FindOrFetchBoost.cmake
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
# Boost can be discovered by every (sub)package but only the top package can *build* it ...
# in either case must declare the components used by TA
# in either case must declare the components used by TTG
set(required_components
headers
callable_traits
)
set(optional_components
)
if (TTG_PARSEC_USE_BOOST_SERIALIZATION)
list(APPEND required_components
list(APPEND optional_components
serialization
iostreams
)
endif()

# if not allowed to fetch Boost make all Boost optional
if (NOT DEFINED Boost_FETCH_IF_MISSING AND TTG_FETCH_BOOST)
set(Boost_FETCH_IF_MISSING 1)
endif()
if (NOT Boost_FETCH_IF_MISSING)
foreach(__component IN LISTS required_components)
list(APPEND optional_components
${__component}
)
endforeach()
set(required_components )
endif()

if (DEFINED Boost_REQUIRED_COMPONENTS)
list(APPEND Boost_REQUIRED_COMPONENTS
${required_components})
list(REMOVE_DUPLICATES Boost_REQUIRED_COMPONENTS)
else()
set(Boost_REQUIRED_COMPONENTS "${required_components}" CACHE STRING "Components of Boost to discovered or built")
endif()
set(optional_components
)
if (DEFINED Boost_OPTIONAL_COMPONENTS)
list(APPEND Boost_OPTIONAL_COMPONENTS
${optional_components}
Expand All @@ -28,10 +42,6 @@ else()
set(Boost_OPTIONAL_COMPONENTS "${optional_components}" CACHE STRING "Optional components of Boost to discovered or built")
endif()

if (NOT DEFINED Boost_FETCH_IF_MISSING AND TTG_FETCH_BOOST)
set(Boost_FETCH_IF_MISSING 1)
endif()

# Bring ValeevGroup cmake toolkit, if not yet available
if (NOT DEFINED vg_cmake_kit_SOURCE_DIR)
include(FetchContent)
Expand All @@ -53,3 +63,6 @@ if (NOT DEFINED vg_cmake_kit_SOURCE_DIR)
endif()
include(${vg_cmake_kit_SOURCE_DIR}/modules/FindOrFetchBoost.cmake)

if (TARGET Boost::headers)
set(TTG_HAS_BOOST 1)
endif()
22 changes: 5 additions & 17 deletions cmake/ttg-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ set(TTG_EXT_VERSION "@TTG_EXT_VERSION@")

set(PaRSEC_CONFIG "@PaRSEC_CONFIG@")
set(MADNESS_CONFIG "@MADNESS_CONFIG@")
set(Boost_CONFIG "@Boost_CONFIG@")
set(CXX_COROUTINE_COMPONENT "@CXX_COROUTINE_COMPONENT@")

set(TTG_TRACKED_BOOST_VERSION "@TTG_TRACKED_BOOST_VERSION@")

set(TTG_HAS_BOOST @TTG_HAS_BOOST@)
set(TTG_IGNORE_BUNDLED_EXTERNALS @TTG_IGNORE_BUNDLED_EXTERNALS@)

# make TTG CMake modules discoverable + load AddTTGExecutable by default
Expand All @@ -19,6 +18,10 @@ include(AddTTGExecutable)

@PACKAGE_INIT@

if (TTG_HAS_BOOST)
@Boost_CONFIG_FILE_CONTENTS@
endif(TTG_HAS_BOOST)

if (NOT TARGET MADworld AND MADNESS_CONFIG)
get_filename_component(MADNESS_CONFIG_DIR "${MADNESS_CONFIG}" DIRECTORY)
find_package(MADNESS 0.10.1 CONFIG QUIET REQUIRED COMPONENTS world PATHS "${MADNESS_CONFIG_DIR}" NO_DEFAULT_PATH)
Expand All @@ -29,12 +32,6 @@ if (NOT TARGET PaRSEC::parsec AND PaRSEC_CONFIG)
find_package(PaRSEC CONFIG QUIET REQUIRED COMPONENTS parsec PATHS "${PaRSEC_CONFIG_DIR}" NO_DEFAULT_PATH)
endif()

# if Boost was discovered and used at TTG configure time discover Boost at the same path
if (NOT TARGET Boost::boost AND Boost_CONFIG)
get_filename_component(Boost_CONFIG_DIR "${Boost_CONFIG}" DIRECTORY)
find_package(Boost ${TTG_TRACKED_BOOST_VERSION} CONFIG QUIET REQUIRED OPTIONAL_COMPONENTS serialization PATHS "${Boost_CONFIG_DIR}" NO_DEFAULT_PATH)
endif()

# if C++ coroutines were used discover same version of them
if (NOT TARGET std::coroutine AND CXX_COROUTINE_COMPONENT)
find_package(CXXStdCoroutine MODULE QUIET REQUIRED COMPONENTS "${CXX_COROUTINE_COMPONENT}")
Expand All @@ -48,13 +45,4 @@ if(NOT TARGET ttg)
endif()
endif()

# if don't have Boost, use bundled Boost.CallableTraits
if (NOT TARGET Boost::boost)
if (TTG_IGNORE_BUNDLED_EXTERNALS)
find_package(Boost ${TTG_TRACKED_BOOST_VERSION} QUIET REQUIRED)
else()
target_compile_definitions(ttg INTERFACE TTG_USE_BUNDLED_BOOST_CALLABLE_TRAITS=1)
endif()
endif()

set(TTG_FOUND TRUE)
6 changes: 4 additions & 2 deletions ttg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ if (TARGET Boost::headers)
list(APPEND ttg-deps Boost::headers)
endif()
else () # if Boost::headers is missing must use bundled Boost.CallableTraits
list(APPEND ttg-defs "$<BUILD_INTERFACE:TTG_USE_BUNDLED_BOOST_CALLABLE_TRAITS=1>")
list(APPEND ttg-incs "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ttg/external>")
list(APPEND ttg-defs "TTG_USE_BUNDLED_BOOST_CALLABLE_TRAITS=1")
list(APPEND ttg-incs
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ttg/external>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ttg/external>")
endif ()
if (TARGET TTG_Libunwind)
list(APPEND ttg-deps TTG_Libunwind)
Expand Down

0 comments on commit f05530f

Please sign in to comment.