Use the CMake Threads package
authorCharles Giessen <charles@lunarg.com>
Wed, 3 Nov 2021 20:28:03 +0000 (14:28 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 9 Mar 2022 22:06:30 +0000 (15:06 -0700)
Instead of manually linking to pthreads, use find_package(Threads) to get the
platform specific name for the threading library and link to it. Use the
THREADS_PREFER_PTHREAD_FLAG to ensure we prefer pthreads before anything
else. Note that this commit is a part of a series of commits and not
intended to work by itself.

CMakeLists.txt
loader/CMakeLists.txt

index bfe08902d83f0af130e4186578345e4471614513..e3c7c94ce854d5c48f7175977b97f4c9e44309b5 100644 (file)
@@ -87,6 +87,9 @@ endif()
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
 find_package(PythonInterp 3 QUIET)
 
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+
 option(BUILD_TESTS "Build Tests" OFF)
 
 if(BUILD_TESTS)
index acea3da5e43153aee81aafe367d3a98434403e53..f867a9a13cdfd1f99872e9705ab01bfa7509ed47 100644 (file)
@@ -289,7 +289,7 @@ else()
                           VERSION ${LOADER_GENERATED_HEADER_VERSION})
     target_link_libraries(vulkan ${CMAKE_DL_LIBS} m)
     if (NOT ANDROID)
-        target_link_libraries(vulkan pthread)
+        target_link_libraries(vulkan Threads::Threads)
     endif()
     # Used to make alloca() and secure_getenv() available
     target_compile_definitions(vulkan PRIVATE _GNU_SOURCE)