From bcb0e3872b50bbbd669285fe9b6156bac42a2690 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler Date: Mon, 6 Oct 2014 21:36:13 +0200 Subject: 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. --- Modules/FindThreads.cmake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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() -- cgit v0.12