File: CheckCXXStdThread.cmake

package info (click to toggle)
warzone2100 4.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 660,320 kB
  • sloc: cpp: 676,209; ansic: 391,201; javascript: 78,238; python: 16,632; php: 4,294; sh: 4,094; makefile: 2,629; lisp: 1,492; cs: 489; xml: 404; perl: 224; ruby: 156; java: 89
file content (59 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# Copyright © 2021 pastdue ( https://github.com/past-due/ ) and contributors
# License: MIT License ( https://opensource.org/licenses/MIT )
#
# Script Version: 2021-05-21a
#

INCLUDE(CheckCXXSourceRuns)
INCLUDE(CheckCXXSourceCompiles)

# CHECK_CXX_STD_THREAD( <_RESULT>
#						  [QUIET] )
#
# CHECK_CXX_STD_THREAD checks if std::thread seems to be supported by the current (specified) compiler + linker.
#
function(CHECK_CXX_STD_THREAD _RESULT)
	set(_options QUIET)
	set(_oneValueArgs)
	set(_multiValueArgs)
	CMAKE_PARSE_ARGUMENTS(_parsedArguments "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})

	set(_check_cached_status)
	if(DEFINED "${_RESULT}")
		set(_check_cached_status " (cached)")
	endif()

	find_package(Threads QUIET)
	if (TARGET Threads::Threads)
		set(CMAKE_REQUIRED_LIBRARIES "Threads::Threads")
	endif()
	if(_parsedArguments_QUIET)
		set(CMAKE_REQUIRED_QUIET OFF)
	endif()
	set(_test_source
		"#include<thread>\n \
		void foo() { /* do nothing */ }\n \
		int main() {\n \
			std::thread a (foo);\n \
			a.join();\n \
			return 0;\n \
		}"
	)
	if(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_GENERATOR_PLATFORM)
		CHECK_CXX_SOURCE_RUNS("${_test_source}" ${_RESULT})
	else()
		CHECK_CXX_SOURCE_COMPILES("${_test_source}" ${_RESULT})
	endif()
	if(_parsedArguments_QUIET)
		unset(CMAKE_REQUIRED_QUIET)
	endif()
	if(NOT _parsedArguments_QUIET)
		if(${_RESULT})
			message( STATUS "std::thread support... YES${_check_cached_status}" )
		else()
			message( STATUS "std::thread support... no${_check_cached_status}" )
		endif()
	endif()
	set(CMAKE_REQUIRED_LIBRARIES "")
endfunction(CHECK_CXX_STD_THREAD)