forked from apple/foundationdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompilerChecks.cmake
62 lines (57 loc) · 1.76 KB
/
CompilerChecks.cmake
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
60
61
62
include(CheckCXXCompilerFlag)
function(env_set var_name default_value type docstring)
set(val ${default_value})
if(DEFINED ENV{${var_name}})
set(val $ENV{${var_name}})
endif()
set(${var_name} ${val} CACHE ${type} "${docstring}")
endfunction()
function(default_linker var_name)
if(APPLE)
set("${var_name}" "DEFAULT" PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
find_program(lld_path ld.lld "Path to LLD - is only used to determine default linker")
if(lld_path)
set("${var_name}" "LLD" PARENT_SCOPE)
else()
set("${var_name}" "DEFAULT" PARENT_SCOPE)
endif()
else()
set("${var_name}" "DEFAULT" PARENT_SCOPE)
endif()
endfunction()
function(use_libcxx out)
if(APPLE OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set("${out}" ON PARENT_SCOPE)
else()
set("${out}" OFF PARENT_SCOPE)
endif()
endfunction()
function(static_link_libcxx out)
if(USE_TSAN)
# Libc/libstdc++ static linking is not supported for tsan
set("${out}" OFF PARENT_SCOPE)
elseif(APPLE)
set("${out}" OFF PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
default_linker(linker)
if(NOT linker STREQUAL "LLD")
set("${out}" OFF PARENT_SCOPE)
return()
endif()
find_library(libcxx_a libc++.a)
find_library(libcxx_abi libc++abi.a)
if(libcxx_a AND libcxx_abi)
set("${out}" ON PARENT_SCOPE)
else()
set("${out}" OFF PARENT_SCOPE)
endif()
else()
set("${out}" ON PARENT_SCOPE)
endif()
endfunction()
function(check_swift_source_compiles SOURCE VAR)
file(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/src.swift" "${SOURCE}")
try_compile(build_result "${CMAKE_BINARY_DIR}/CMakeTmp" "${CMAKE_BINARY_DIR}/CMakeTmp/src.swift")
set(${VAR} ${build_result} PARENT_SCOPE)
endfunction()