diff --git a/CMakeLists.txt b/CMakeLists.txt index 6769952..14bd39e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,25 @@ hint_flag(CXX_EXTRA_LINKER_FLAGS " # Honor user's CXX_EXTRA_LINK_FLAGS set(CXX_EXTRA_LINK_FLAGS ${CXX_EXTRA_FLAGS} ${CXX_EXTRA_LINK_FLAGS}) +option(USE_TBB "Enable oneTBB library for *supported* models. Enabling this on models that + don't explicitly link against TBB is a no-op, see description of your selected + model on how this is used." OFF) + +if (USE_TBB) + include(FetchContent) + FetchContent_Declare( + TBB + GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git + GIT_TAG faaf43c4ab22cb4b4267d65d5e218fa58800eea8 + ) + # Not using FetchContent_MakeAvailable because we need EXCLUDE_FROM_ALL + FetchContent_GetProperties(TBB) + if (NOT TBB_POPULATED) + FetchContent_Populate(TBB) + add_subdirectory(${tbb_SOURCE_DIR} ${tbb_BINARY_DIR} EXCLUDE_FROM_ALL) + endif () +endif () + # include our macros include(cmake/register_models.cmake) diff --git a/src/std-data/model.cmake b/src/std-data/model.cmake index 6f87bc9..3f79f13 100644 --- a/src/std-data/model.cmake +++ b/src/std-data/model.cmake @@ -23,6 +23,10 @@ register_flag_optional(NVHPC_OFFLOAD ccall - Compile for all supported compute capabilities" "") +register_flag_optional(USE_TBB + "No-op if ONE_TBB_DIR is set. Link against an in-tree oneTBB via FetchContent_Declare, see top level CMakeLists.txt for details." + "OFF") + macro(setup) set(CMAKE_CXX_STANDARD 17) @@ -35,5 +39,7 @@ macro(setup) if(USE_VECTOR) register_definitions(USE_VECTOR) endif() - + if (USE_TBB) + register_link_library(TBB::tbb) + endif () endmacro() diff --git a/src/std-indices/model.cmake b/src/std-indices/model.cmake index 6f87bc9..7dc22b9 100644 --- a/src/std-indices/model.cmake +++ b/src/std-indices/model.cmake @@ -23,6 +23,11 @@ register_flag_optional(NVHPC_OFFLOAD ccall - Compile for all supported compute capabilities" "") +register_flag_optional(USE_TBB + "Link against an in-tree oneTBB via FetchContent_Declare, see top level CMakeLists.txt for details." + "OFF") + + macro(setup) set(CMAKE_CXX_STANDARD 17) @@ -35,5 +40,7 @@ macro(setup) if(USE_VECTOR) register_definitions(USE_VECTOR) endif() - + if (USE_TBB) + register_link_library(TBB::tbb) + endif () endmacro() diff --git a/src/std-ranges/model.cmake b/src/std-ranges/model.cmake index ac56962..65e5489 100644 --- a/src/std-ranges/model.cmake +++ b/src/std-ranges/model.cmake @@ -7,6 +7,10 @@ register_flag_optional(USE_VECTOR "Whether to use std::vector for storage or use aligned_alloc. C++ vectors are *zero* initialised where as aligned_alloc is uninitialised before first use." "OFF") +register_flag_optional(USE_TBB + "No-op if ONE_TBB_DIR is set. Link against an in-tree oneTBB via FetchContent_Declare, see top level CMakeLists.txt for details." + "OFF") + macro(setup) # TODO this needs to eventually be removed when CMake adds proper C++20 support or at least update the flag used here @@ -20,4 +24,7 @@ macro(setup) if(USE_VECTOR) register_definitions(USE_VECTOR) endif() + if (USE_TBB) + register_link_library(TBB::tbb) + endif () endmacro() diff --git a/src/tbb/model.cmake b/src/tbb/model.cmake index c1ff9aa..eeb1637 100644 --- a/src/tbb/model.cmake +++ b/src/tbb/model.cmake @@ -19,15 +19,20 @@ register_flag_optional(USE_VECTOR "Whether to use std::vector for storage or use aligned_alloc. C++ vectors are *zero* initialised where as aligned_alloc is uninitialised before first use." "OFF") +register_flag_optional(USE_TBB + "No-op if ONE_TBB_DIR is set. Link against an in-tree oneTBB via FetchContent_Declare, see top level CMakeLists.txt for details." + "OFF") + macro(setup) if(ONE_TBB_DIR) set(TBB_ROOT "${ONE_TBB_DIR}") # see https://github.com/Kitware/VTK/blob/0a31a9a3c1531ae238ac96a372fec4be42282863/CMake/FindTBB.cmake#L34 # docs on Intel's website refers to TBB_DIR which is not correct + find_package(TBB REQUIRED) endif() + # No need to handle USE_TBB as both ONE_TBB_DIR and USE_TBB will create the TBB::tbb target # see https://github.com/oneapi-src/oneTBB/blob/master/cmake/README.md#tbbconfig---integration-of-binary-packages - find_package(TBB REQUIRED) register_link_library(TBB::tbb) register_definitions(PARTITIONER_${PARTITIONER}) if(USE_VECTOR)