cmake: better check for CPP17 parallelism
authorMichael Wallner <mike@php.net>
Fri, 11 Dec 2020 09:27:47 +0000 (10:27 +0100)
committerMichael Wallner <mike@php.net>
Fri, 11 Dec 2020 09:27:47 +0000 (10:27 +0100)
CMake/CheckCpp17Parallelism.cmake [new file with mode: 0644]
CMake/CheckTbb.cmake
test/CMakeLists.txt

diff --git a/CMake/CheckCpp17Parallelism.cmake b/CMake/CheckCpp17Parallelism.cmake
new file mode 100644 (file)
index 0000000..cc3f0d2
--- /dev/null
@@ -0,0 +1,30 @@
+configure_define(HAVE_CPP17_PARALLELISM)
+
+#
+# see CheckTbb.cmake on change
+#
+
+check_cxx_source_compiles("
+                #include <vector>
+                #include <algorithm>
+                #include <execution>
+                int main() {
+                    std::vector<char> 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()
index b3ea50f4501fb66d150a68bda73fe1775be74867..cd76ab3e4761980753c553917cd8d3e100951947 100644 (file)
@@ -27,7 +27,8 @@ if(HAVE_LIBTBB)
                 }
                 "
                 HAVE_TBB
-        )
+                )
+
     endif()
     cmake_pop_check_state()
 endif()
index 1f86466ad6eaeaa017336fd4db37ae9f33aee1ab..6e64777a5a80083c29a720ed42e76b499ae20731 100644 (file)
@@ -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})