Use pthread link library as required.
[SquirrelJME.git] / nanocoat / cmake / threads.cmake
blob2e981e647a174d6245e76a86db11bcf72d4c2411
1 # ---------------------------------------------------------------------------
2 # SquirrelJME
3 #     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
4 # ---------------------------------------------------------------------------
5 # SquirrelJME is under the Mozilla Public License Version 2.0.
6 # See license.mkd for licensing and copyright information.
7 # ---------------------------------------------------------------------------
8 # DESCRIPTION: Threading and atomics support
10 # For compatibility for Windows, do not use pthreads even if available
11 find_package(Threads)
12 if(WIN32)
13         add_compile_definitions(SJME_CONFIG_HAS_THREADS=1)
14         add_compile_definitions(SJME_CONFIG_HAS_THREADS_WIN32=1)
15 elseif(Threads_FOUND)
16         if(CMAKE_USE_PTHREADS_INIT)
17                 # Does pthread actually exist?
18                 try_compile(SQUIRRELJME_PTHREADS_VALID
19                         SOURCES "${CMAKE_CURRENT_LIST_DIR}/tryPThread.c"
20                         LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
22                 # Valid?
23                 if(SQUIRRELJME_PTHREADS_VALID)
24                         message("PThread: Valid!")
26                         add_compile_definitions(
27                                 SJME_CONFIG_HAS_THREADS=1)
28                         add_compile_definitions(
29                                 SJME_CONFIG_HAS_THREADS_PTHREAD=1)
31                         # Specific OSes?
32                         if (LINUX)
33                                 add_compile_definitions(
34                                         SJME_CONFIG_HAS_THREADS_PTHREAD_LINUX=1)
35                         elseif (APPLE OR BSD)
36                                 add_compile_definitions(
37                                         SJME_CONFIG_HAS_THREADS_PTHREAD_BSD=1)
38                         endif()
39                 else()
40                         message("PThread: Not available or misconfigured.")
41                 endif()
42         endif()
43 endif()