MacOS pthreads does not have pthread_yield().
[SquirrelJME.git] / nanocoat / cmake / threads.cmake
blobabb1161440b4b763f522191a4dea2c997a9aa063
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                         "${CMAKE_CURRENT_BINARY_DIR}"
20                         SOURCES "${CMAKE_CURRENT_LIST_DIR}/tryPThread.c"
21                         LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
23                 # Valid?
24                 if(SQUIRRELJME_PTHREADS_VALID)
25                         message("PThread: Valid!")
27                         add_compile_definitions(
28                                 SJME_CONFIG_HAS_THREADS=1)
29                         add_compile_definitions(
30                                 SJME_CONFIG_HAS_THREADS_PTHREAD=1)
32                         # Specific OSes?
33                         if (LINUX)
34                                 add_compile_definitions(
35                                         SJME_CONFIG_HAS_THREADS_PTHREAD_LINUX=1)
36                         elseif(APPLE OR BSD)
37                                 if(APPLE)
38                                         add_compile_definitions(
39                                                 SJME_CONFIG_HAS_THREADS_PTHREAD_MACOS=1)
40                                 endif()
42                                 add_compile_definitions(
43                                         SJME_CONFIG_HAS_THREADS_PTHREAD_BSD=1)
44                         endif()
45                 else()
46                         message("PThread: Not available or misconfigured.")
47                 endif()
48         endif()
49 endif()