aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-01 19:15:18 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-03 23:35:21 +0100
commitb5724a654a4aadeabcfa3de3847768239931c687 (patch)
treef59b4340d6af01b41d589af4ff6fd44bd1784001 /cmake
parent66340e08d7388a65102710d71ce4ad13bbbe7467 (diff)
downloadliberty-b5724a654a4aadeabcfa3de3847768239931c687.tar.gz
liberty-b5724a654a4aadeabcfa3de3847768239931c687.tar.xz
liberty-b5724a654a4aadeabcfa3de3847768239931c687.zip
Compile tests with pthreads support
Diffstat (limited to 'cmake')
-rw-r--r--cmake/AddThreads.cmake23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmake/AddThreads.cmake b/cmake/AddThreads.cmake
new file mode 100644
index 0000000..72a4e08
--- /dev/null
+++ b/cmake/AddThreads.cmake
@@ -0,0 +1,23 @@
+# Public Domain
+
+# We're looking for pthreads only, while preferring the -pthread flag
+set (CMAKE_THREAD_PREFER_PTHREAD ON)
+set (THREADS_PREFER_PTHREAD_FLAG ON)
+find_package (Threads)
+
+# Prepares the given target for threads
+function (add_threads target)
+ if (NOT Threads_FOUND OR NOT CMAKE_USE_PTHREADS_INIT)
+ message (FATAL_ERROR "pthreads not found")
+ endif (NOT Threads_FOUND OR NOT CMAKE_USE_PTHREADS_INIT)
+
+ if (THREADS_HAVE_PTHREAD_ARG)
+ set_property (TARGET ${target} PROPERTY
+ COMPILE_OPTIONS "-pthread")
+ set_property (TARGET ${target} PROPERTY
+ INTERFACE_COMPILE_OPTIONS "-pthread")
+ endif (THREADS_HAVE_PTHREAD_ARG)
+ if (CMAKE_THREAD_LIBS_INIT)
+ target_link_libraries (${target} "${CMAKE_THREAD_LIBS_INIT}")
+ endif (CMAKE_THREAD_LIBS_INIT)
+endfunction (add_threads)