@@ -232,14 +232,44 @@ endif()
232232
233233######### TBB decisions ############################################
234234if ( SPIRIT_USE_STDPAR )
235- include ( FindTBB )
236- if ( TBB_FOUND )
237- set ( SPIRIT_COMPILE_DEFINITIONS ${SPIRIT_COMPILE_DEFINITIONS} -DSPIRIT_USE_STDPAR )
238- message ( STATUS ">> using TBB for parallel STL" )
235+ include (CheckCXXSourceCompiles )
236+ set ( SOURCE_CXX17_PARALLEL_ALGORITHM "
237+ #include <execution>
238+ int main()
239+ {
240+ std::execution::seq;
241+ std::execution::par;
242+ std::execution::par_unseq;
243+ return 0;
244+ }
245+ " )
246+ check_cxx_source_compiles ( "${SOURCE_CXX17_PARALLEL_ALGORITHM} "
247+ HAVE_BUILTIN_CXX17_PARALLEL_ALGORITHM )
248+
249+ if ( NOT HAVE_BUILTIN_CXX17_PARALLEL_ALGORITHM )
250+ # Try to find TBB module
251+ find_package ( TBB )
252+ if ( TBB_FOUND )
253+ set ( TBB_LIB TBB::tbb )
254+ message ( STATUS ">> using TBB for parallel STL" )
255+ else ()
256+ set ( TBB_LIB )
257+ message ( WARNING ">> TBB could not be found." )
258+ endif ()
259+ # All of these symbols are required to use this feature.
260+ # So, if this compiles even if TBB was not found it should be fine.
261+ list ( APPEND CMAKE_REQUIRED_LIBRARIES ${TBB_LIB} )
262+ check_cxx_source_compiles ( "${SOURCE_CXX17_PARALLEL_ALGORITHM} "
263+ HAVE_TBB_CXX17_PARALLEL_ALGORITHM )
264+ set ( HAVE_CXX17_PARALLEL_ALGORITHM ${HAVE_TBB_CXX17_PARALLEL_ALGORITHM} )
239265 else ()
240- message ( WARNING ">> TBB could not be found." )
241- set ( SPIRIT_USE_STDPAR OFF )
266+ set ( HAVE_CXX17_PARALLEL_ALGORITHM ${HAVE_BUILTIN_CXX17_PARALLEL_ALGORITHM} )
267+ endif ()
268+
269+ if ( NOT HAVE_CXX17_PARALLEL_ALGORITHM )
270+ message ( FATAL_ERROR "C++17 execution policies are required for SPIRIT_USE_STDPAR=ON" )
242271 endif ()
272+ set ( SPIRIT_COMPILE_DEFINITIONS ${SPIRIT_COMPILE_DEFINITIONS} -DSPIRIT_USE_STDPAR )
243273endif ()
244274######### TBB decisions ############################################
245275
0 commit comments