cmake: fix tbb detection
authorMichael Wallner <mike@php.net>
Mon, 2 Nov 2020 11:55:52 +0000 (12:55 +0100)
committerMichael Wallner <mike@php.net>
Mon, 2 Nov 2020 11:55:52 +0000 (12:55 +0100)
CMake/CheckDependency.cmake
CMake/CheckTbb.cmake
test/CMakeLists.txt

index bb6fd7d0a68c9f5986b1cca6091e541858407641..f78390b4044fd8b6b9114a9e0bac501f82fc62e4 100644 (file)
@@ -3,51 +3,47 @@ find_package(PkgConfig)
 include(SafeString)
 include(CheckHeader)
 
-function(check_dependency_basic NAME LIB HEADER)
-       set(FOUND 1)
-       message("-- Checking for library '${LIB}' with header '${HEADER}' ...")
-       find_library(LIB${LIB} NAMES ${LIB})
-       if(NOT LIB${LIB})
-               set(FOUND 0)
-       endif()
-       if(HEADER)
-               safe_string(${HEADER} HEADER_CONST)
-               check_header(${HEADER})
-               if(NOT HAVE_${HEADER_CONST})
-                       set(FOUND 0)
-               else()
-                       find_path(${HEADER_CONST}_ROOT ${HEADER})
-                       if(NOT ${HEADER_CONST}_ROOT)
-                               set(FOUND 0)
-                       endif()
-               endif()
-       endif()
-       if(FOUND)
-               message("--   Found library '${LIB${LIB}}'")
-               message("--   Found include '${${HEADER_CONST}_ROOT}'")
-        set(${NAME} ${NAME} PARENT_SCOPE)
-        add_library(${NAME} INTERFACE IMPORTED)
-        set_target_properties(${NAME} PROPERTIES
-                INTERFACE_INCLUDE_DIRECTORIES ${${HEADER_CONST}_ROOT}
-                INTERFACE_LINK_LIBRARIES ${LIB${LIB}})
-       else()
-               message("--   No library '${LIB}' found")
-       endif()
-       set(${NAME}_FOUND ${FOUND} PARENT_SCOPE)
-endfunction()
-
 function(check_dependency NAME LIB HEADER)
     if(PKG_CONFIG_FOUND)
         pkg_check_modules(${NAME} lib${LIB}${ARGN} IMPORTED_TARGET)
         if(NOT ${NAME}_FOUND)
-            pkg_check_modules(${NAME} ${LIB}${ARGN})
+            pkg_check_modules(${NAME} ${LIB}${ARGN} IMPORTED_TARGET)
         endif()
         if(${NAME}_FOUND)
             set(${NAME} PkgConfig::${NAME} PARENT_SCOPE)
         endif()
     endif()
     if(NOT ${NAME}_FOUND)
-        check_dependency_basic(${NAME} ${LIB} ${HEADER})
+        set(FOUND 1)
+        message(STATUS "Checking for library '${LIB}' with header '${HEADER}' ...")
+        find_library(LIB${LIB} NAMES ${LIB})
+        if(NOT LIB${LIB})
+            set(FOUND 0)
+        endif()
+        if(HEADER)
+            safe_string(${HEADER} HEADER_CONST)
+            check_header(${HEADER})
+            if(NOT HAVE_${HEADER_CONST})
+                set(FOUND 0)
+            else()
+                find_path(${HEADER_CONST}_ROOT ${HEADER})
+                if(NOT ${HEADER_CONST}_ROOT)
+                    set(FOUND 0)
+                endif()
+            endif()
+        endif()
+        if(FOUND)
+            message(STATUS "  Found library '${LIB${LIB}}'")
+            message(STATUS "  Found include '${${HEADER_CONST}_ROOT}'")
+            set(${NAME} Imported::${NAME} PARENT_SCOPE)
+            add_library(Imported::${NAME} INTERFACE IMPORTED)
+            set_target_properties(Imported::${NAME} PROPERTIES
+                    INTERFACE_INCLUDE_DIRECTORIES ${${HEADER_CONST}_ROOT}
+                    INTERFACE_LINK_LIBRARIES ${LIB${LIB}})
+        else()
+            message("--   No library '${LIB}' found")
+        endif()
+        set(${NAME}_FOUND ${FOUND})
     endif()
 
     set(HAVE_${NAME} ${${NAME}_FOUND} PARENT_SCOPE)
index 11abb4ab0928602f19da00ba1f3281e404dbc066..31a0de1ddbc7b5ccf6f2bea0b2902d0a0ec5603c 100644 (file)
@@ -1,4 +1,4 @@
-function(CHECK_TBB)
+macro(CHECK_TBB)
     check_header(execution)
     # TBBConfig only sets TBB_FOUND to FALSE
     if(HAVE_EXECUTION)
@@ -12,9 +12,6 @@ function(CHECK_TBB)
             set(CMAKE_REQUIRED_FLAGS -std=c++17)
             check_compiles(HAVE_TBB "std::vector<char> a={1,2,3}; std::all_of(std::execution::par,a.begin(),a.end(),[](char i){return i>0;});" vector algorithm execution)
             cmake_pop_check_state(RESET)
-            if(HAVE_TBB)
-                set(HAVE_LIBTBB 1 PARENT_SCOPE)
-            endif()
         endif()
     endif()
-endfunction()
+endmacro()
index 75fb187b04e60eb71a4ce8cdbcb5dfd118e32d92..449223f0efd3fb62379cf48f7a8e5d24551e9733 100644 (file)
@@ -30,7 +30,6 @@ target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcac
 
 check_tbb()
 if(HAVE_TBB)
-    message("HAVE TBB")
     target_link_libraries(runtests PRIVATE ${LIBTBB})
 endif()