1# SPDX-License-Identifier: Apache-2.0
2#
3# Copyright (c) 2024 Google LLC.
4
5# FindThreads module for locating threads implementation.
6#
7# The module defines the following variables:
8#
9# 'Threads_FOUND'
10# Indicates if threads are supported.
11#
12# 'CMAKE_THREAD_LIBS_INIT'
13# The threads library to use. Zephyr provides threads implementation and no
14# special flags are needed, so this will be empty.
15#
16# 'CMAKE_USE_PTHREADS_INIT'
17# Indicates if threads are pthread compatible.
18#
19# This module is compatible with FindThreads module from CMake.
20# The original implementation tries to find threads library using various
21# methods (e.g. checking if pthread library is present or compiling example
22# program to check if the implementation is provided by libc), but it's not
23# able to detect pthread implementation provided by Zephyr.
24
25include(FindPackageHandleStandardArgs)
26
27set(Threads_FOUND FALSE)
28
29if(DEFINED CONFIG_POSIX_THREADS)
30  set(Threads_FOUND TRUE)
31  set(CMAKE_THREAD_LIBS_INIT )
32  set(CMAKE_USE_PTHREADS_INIT 1)
33endif()
34
35find_package_handle_standard_args(Threads DEFAULT_MSG Threads_FOUND)
36
37if(Threads_FOUND AND NOT TARGET Threads::Threads)
38  # This is just an empty interface, because we don't need to provide any
39  # options. Nevertheless this library must exist, because third-party modules
40  # can link it to their own libraries.
41  add_library(Threads::Threads INTERFACE IMPORTED)
42endif()
43