Skip to content

Commit

Permalink
Fix optional gcc dependency on TBB
Browse files Browse the repository at this point in the history
For implementing std::execution::par, gcc relies on the TBB library.
On systems without TBB installed it falls back to the non-parallel
implementation, but as soon as the TBB header is available it will try
to use it and require linking against TBB.
https://github.com/gcc-mirror/gcc/blob/releases/gcc-14.1.0/libstdc%2B%2B-v3/include/bits/c%2B%2Bconfig#L874-L882
Since TBB is a bigger dependency, making it a required dependency is not
an option, so this introduces the option ENABLE_TBB which by default is
off but can be used to add the dependency.

fixes #361
  • Loading branch information
wirew0rm committed Jun 20, 2024
1 parent 4b05d30 commit 1a37b5b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

add_library(gnuradio-options INTERFACE)

if (CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$") # if this hasn't been set before via e.g. emcmake
message(" Transpiling to WASM: using: Emscripten (${CMAKE_CXX_COMPILER})")
set(EMSCRIPTEN ON)
Expand All @@ -17,6 +19,7 @@ option(TIMETRACE "Enable clang's -ftime-trace" OFF)
option(ADDRESS_SANITIZER "Enable address sanitizer" OFF)
option(UB_SANITIZER "Enable undefined behavior sanitizer" OFF)
option(THREAD_SANITIZER "Enable thread sanitizer" OFF)
option(ENABLE_TBB "Enable the TBB dependency for std::execution::par in gcc" OFF)

if (EMSCRIPTEN)
set(ENABLE_BLOCK_PLUGINS OFF)
Expand Down Expand Up @@ -106,6 +109,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") # set default C++ STL to Clang's li
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
if (ENABLE_TBB)
find_package(TBB REQUIRED)
target_link_libraries(gnuradio-options INTERFACE TBB::tbb)
else ()
target_compile_definitions(gnuradio-options INTERFACE _GLIBCXX_USE_TBB_PAR_BACKEND=0)
endif ()
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "(Clang|GNU)")
Expand Down Expand Up @@ -139,7 +148,6 @@ endif ()
# Mainly for FMT
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

add_library(gnuradio-options INTERFACE)
include(cmake/CompilerWarnings.cmake)
set_project_warnings(gnuradio-options)

Expand Down Expand Up @@ -271,7 +279,6 @@ target_include_directories(fftw INTERFACE ${FFTW_PREFIX}/install/include ${PROJE
target_link_directories(fftw INTERFACE ${FFTW_PREFIX}/install/lib ${FFTW_PREFIX}/install/lib64)
add_dependencies(fftw fftw_ext)


## check for CPython and Numpy dependencies
set(PYTHON_FORCE_INCLUDE OFF)
if (PYTHON_FORCE_INCLUDE)
Expand Down

0 comments on commit 1a37b5b

Please sign in to comment.