summaryrefslogtreecommitdiffstats
path: root/Modules/FindThreads.cmake
diff options
context:
space:
mode:
authorTimo Rothenpieler <btbn@btbn.de>2014-10-06 19:36:13 (GMT)
committerRolf Eike Beer <eike@sf-mail.de>2014-10-08 15:57:34 (GMT)
commitbcb0e3872b50bbbd669285fe9b6156bac42a2690 (patch)
treeb7a6d875a98e81d9719d4c095c895192943badd8 /Modules/FindThreads.cmake
parent46368eddfdca1ee83a0126e4b3dfde575125f3e1 (diff)
downloadCMake-bcb0e3872b50bbbd669285fe9b6156bac42a2690.zip
CMake-bcb0e3872b50bbbd669285fe9b6156bac42a2690.tar.gz
CMake-bcb0e3872b50bbbd669285fe9b6156bac42a2690.tar.bz2
FindThreads: introduce an imported target to link to
This not only holds the library, but can also hold compiler flags needed, e.g. the -pthread flag preferred by gcc on some platforms. There was no clean way to get that compiler flag from the module until now.
Diffstat (limited to 'Modules/FindThreads.cmake')
-rw-r--r--Modules/FindThreads.cmake18
1 files changed, 18 insertions, 0 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index aac9c0e..108b56f 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -14,6 +14,12 @@
# CMAKE_USE_PTHREADS_INIT - are we using pthreads
# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
#
+# The following import target is created
+#
+# ::
+#
+# Threads::Threads
+#
# For systems with multiple thread libraries, caller can set
#
# ::
@@ -178,3 +184,15 @@ endif()
set(CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
+
+if(THREADS_FOUND AND NOT TARGET Threads::Threads)
+ add_library(Threads::Threads INTERFACE IMPORTED)
+
+ if(THREADS_HAVE_PTHREAD_ARG)
+ set_property(TARGET Threads::Threads PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
+ endif()
+
+ if(CMAKE_THREAD_LIBS_INIT)
+ set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
+endif()