Skip to content

Commit 2c00a77

Browse files
committed
link TBB if libstdc++ uses it
1 parent fc1f879 commit 2c00a77

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ beman_install_library(${BEMAN_EXECUTION_TARGET_PREFIX} TARGETS ${BEMAN_EXECUTION
131131
)
132132
#===============================================================================
133133

134+
if(BEMAN_EXECUTION_BUILD_TESTS OR BEMAN_EXECUTION_BUILD_EXAMPLES)
135+
include(cmake/std_par.cmake)
136+
endif()
137+
134138
if(BEMAN_EXECUTION_BUILD_TESTS)
135139
enable_testing()
136140
add_subdirectory(tests/beman/execution)

‎cmake/std_par.cmake‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# gersemi: off
2+
# cmake/std_par.cmake
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
# gersemi: on
5+
6+
# Defines beman.execution.std_par: an INTERFACE target executables link to when
7+
# libstdc++'s <execution> needs TBB.
8+
if(NOT TARGET beman.execution.std_par)
9+
include(CheckCXXSourceCompiles)
10+
check_cxx_source_compiles(
11+
"#include <algorithm>
12+
#include <execution>
13+
#include <vector>
14+
int main() { std::vector<int> v{2, 1}; std::sort(std::execution::par, v.begin(), v.end()); }"
15+
BEMAN_EXECUTION_STD_PAR_LINKS
16+
)
17+
add_library(beman.execution.std_par INTERFACE)
18+
if(NOT BEMAN_EXECUTION_STD_PAR_LINKS)
19+
find_package(TBB REQUIRED)
20+
target_link_libraries(beman.execution.std_par INTERFACE TBB::tbb)
21+
endif()
22+
endif()

‎examples/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ if(PROJECT_IS_TOP_LEVEL)
1717
enable_testing()
1818
endif()
1919

20+
include(../cmake/std_par.cmake)
21+
2022
set(TODO suspend_never) #-dk:TODO including that causes ASAN errors
2123

2224
set(EXAMPLES
@@ -60,5 +62,6 @@ foreach(EXAMPLE ${EXAMPLES})
6062
PRIVATE beman::execution_headers
6163
)
6264
endif()
65+
target_link_libraries(${EXAMPLE_TARGET} PRIVATE beman.execution.std_par)
6366
add_test(NAME ${EXAMPLE_TARGET} COMMAND ${EXAMPLE_TARGET})
6467
endforeach()

‎tests/beman/execution/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ foreach(test ${execution_tests})
142142
else()
143143
target_link_libraries(${TEST_EXE} PRIVATE beman::execution_headers)
144144
endif()
145+
target_link_libraries(${TEST_EXE} PRIVATE beman.execution.std_par)
145146
target_compile_definitions(${TEST_EXE} PRIVATE NOMINMAX)
146147
add_test(NAME ${TEST_EXE} COMMAND $<TARGET_FILE:${TEST_EXE}>)
147148
endforeach()

0 commit comments

Comments
 (0)