From: Michael Wallner Date: Fri, 11 Dec 2020 09:27:47 +0000 (+0100) Subject: cmake: better check for CPP17 parallelism X-Git-Tag: 1.1.0-beta1~69 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=f875d401486e0e12d30b28e9d62220fdf6cd8561;p=m6w6%2Flibmemcached cmake: better check for CPP17 parallelism --- diff --git a/CMake/CheckCpp17Parallelism.cmake b/CMake/CheckCpp17Parallelism.cmake new file mode 100644 index 00000000..cc3f0d2a --- /dev/null +++ b/CMake/CheckCpp17Parallelism.cmake @@ -0,0 +1,30 @@ +configure_define(HAVE_CPP17_PARALLELISM) + +# +# see CheckTbb.cmake on change +# + +check_cxx_source_compiles(" + #include + #include + #include + int main() { + std::vector a = {1,2,3}; + std::all_of(std::execution::par, a.begin(), a.end(), [](char i) { + return i>0; + }); + } + " + HAVE_CPP17_PARALLELISM + ) + +if(HAVE_CPP17_PARALLELISM) + add_library(cpp17::paralleslism INTERFACE IMPORTED) + # noting to be done +else() + include(CheckTbb) + set(HAVE_CPP17_PARALLELISM "${HAVE_TBB}") + if(HAVE_TBB) + add_library(cpp17::parallelism ALIAS "${LIBTBB}") + endif() +endif() diff --git a/CMake/CheckTbb.cmake b/CMake/CheckTbb.cmake index b3ea50f4..cd76ab3e 100644 --- a/CMake/CheckTbb.cmake +++ b/CMake/CheckTbb.cmake @@ -27,7 +27,8 @@ if(HAVE_LIBTBB) } " HAVE_TBB - ) + ) + endif() cmake_pop_check_state() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1f86466a..6e64777a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,10 +60,10 @@ target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcac # parallelism if(NOT (thread IN_LIST ENABLE_SANITIZERS)) - include(CheckTbb) -endif() -if(HAVE_TBB) - target_link_libraries(runtests PRIVATE ${LIBTBB}) + include(CheckCpp17Parallelism) + if(HAVE_CPP17_PARALLELISM) + target_link_libraries(runtests PRIVATE cpp17::parallelism) + endif() endif() add_dependencies(runtests ${CLIENTS})