llvm-project
254 строки · 9.6 Кб
1include(BuiltinTests)
2include(CheckIncludeFiles)
3include(CheckCSourceCompiles)
4
5# Make all the tests only check the compiler
6set(TEST_COMPILE_ONLY On)
7
8# Check host compiler support for certain flags
9builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG)
10builtin_check_c_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG)
11builtin_check_c_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
12builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG)
13builtin_check_c_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG)
14builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG)
15builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG)
16builtin_check_c_compiler_flag(-fxray-instrument COMPILER_RT_HAS_XRAY_COMPILER_FLAG)
17builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
18builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
19builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
20builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
21builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
22builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
23builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
24
25builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
26"
27int foo(int x, int y) {
28_Atomic int result = x * y;
29return result;
30}
31")
32
33builtin_check_c_compiler_source(COMPILER_RT_HAS_ASM_LSE
34"
35asm(\".arch armv8-a+lse\");
36asm(\"cas w0, w1, [x2]\");
37")
38
39builtin_check_c_compiler_source(COMPILER_RT_HAS_AARCH64_SME
40"
41void foo(void) __arm_streaming_compatible {
42asm(\".arch armv9-a+sme\");
43asm(\"smstart\");
44}
45")
46
47check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV)
48
49if(ANDROID)
50set(OS_NAME "Android")
51else()
52set(OS_NAME "${CMAKE_SYSTEM_NAME}")
53endif()
54
55set(ARM64 aarch64)
56set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main)
57set(AVR avr)
58set(HEXAGON hexagon)
59set(X86 i386)
60set(X86_64 x86_64)
61set(LOONGARCH64 loongarch64)
62set(MIPS32 mips mipsel)
63set(MIPS64 mips64 mips64el)
64set(PPC32 powerpc powerpcspe)
65set(PPC64 powerpc64 powerpc64le)
66set(RISCV32 riscv32)
67set(RISCV64 riscv64)
68set(SPARC sparc)
69set(SPARCV9 sparcv9)
70set(WASM32 wasm32)
71set(WASM64 wasm64)
72set(VE ve)
73
74if(APPLE)
75set(ARM64 arm64 arm64e)
76set(ARM32 armv7 armv7k armv7s)
77set(X86_64 x86_64 x86_64h)
78endif()
79
80set(ALL_BUILTIN_SUPPORTED_ARCH
81${X86} ${X86_64} ${ARM32} ${ARM64} ${AVR}
82${HEXAGON} ${MIPS32} ${MIPS64} ${PPC32} ${PPC64}
83${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9}
84${WASM32} ${WASM64} ${VE} ${LOONGARCH64})
85
86include(CompilerRTUtils)
87include(CompilerRTDarwinUtils)
88
89if(APPLE)
90
91find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
92find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
93find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
94find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
95find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
96find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
97find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
98find_darwin_sdk_dir(DARWIN_xrossim_SYSROOT xrsimulator)
99find_darwin_sdk_dir(DARWIN_xros_SYSROOT xros)
100
101# Get supported architecture from SDKSettings.
102function(sdk_has_arch_support sdk_path os arch has_support)
103execute_process(COMMAND
104/usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
105OUTPUT_VARIABLE SDK_SUPPORTED_ARCHS
106RESULT_VARIABLE PLIST_ERROR
107ERROR_QUIET)
108if (PLIST_ERROR EQUAL 0 AND
109SDK_SUPPORTED_ARCHS MATCHES " ${arch}\n")
110message(STATUS "Found ${arch} support in ${sdk_path}/SDKSettings.plist")
111set("${has_support}" On PARENT_SCOPE)
112else()
113message(STATUS "No ${arch} support in ${sdk_path}/SDKSettings.plist")
114set("${has_support}" Off PARENT_SCOPE)
115endif()
116endfunction()
117
118set(DARWIN_EMBEDDED_PLATFORMS)
119set(DARWIN_osx_BUILTIN_MIN_VER 10.7)
120set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
121-mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
122set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
123# Add support for arm64 macOS if available in SDK.
124foreach(arch ${ARM64})
125sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
126if (MACOS_ARM_SUPPORT)
127list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
128endif()
129endforeach(arch)
130
131if(COMPILER_RT_ENABLE_IOS)
132list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
133set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
134set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
135set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
136${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
137set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
138set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
139find_darwin_sdk_version(iossim_sdk_version "iphonesimulator")
140if ("${iossim_sdk_version}" VERSION_GREATER 14.0 OR "${iossim_sdk_version}" VERSION_EQUAL 14.0)
141list(APPEND DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
142endif()
143endif()
144if(COMPILER_RT_ENABLE_WATCHOS)
145list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
146set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
147set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
148set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
149${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
150set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k arm64_32)
151set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
152find_darwin_sdk_version(watchossim_sdk_version "watchsimulator")
153if ("${watchossim_sdk_version}" VERSION_GREATER 7.0 OR "${watchossim_sdk_version}" VERSION_EQUAL 7.0)
154list(APPEND DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
155endif()
156endif()
157if(COMPILER_RT_ENABLE_TVOS)
158list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
159set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
160set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
161set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
162${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
163set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
164set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
165find_darwin_sdk_version(tvossim_sdk_version "appletvsimulator")
166if ("${tvossim_sdk_version}" VERSION_GREATER 14.0 OR "${tvossim_sdk_version}" VERSION_EQUAL 14.0)
167list(APPEND DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
168endif()
169endif()
170if(COMPILER_RT_ENABLE_XROS)
171list(APPEND DARWIN_EMBEDDED_PLATFORMS xros)
172set(DARWIN_xros_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
173set(DARWIN_xrossim_BUILTIN_ALL_POSSIBLE_ARCHS arm64)
174endif()
175
176set(BUILTIN_SUPPORTED_OS osx)
177
178# We're setting the flag manually for each target OS
179set(CMAKE_OSX_DEPLOYMENT_TARGET "")
180
181# NOTE: We deliberately avoid using `DARWIN_<os>_ARCHS` here because that is
182# used by `config-ix.cmake` in the context of building the rest of
183# compiler-rt where the global `${TEST_COMPILE_ONLY}` (used by
184# `darwin_test_archs()`) has a different value.
185darwin_test_archs(osx
186DARWIN_osx_BUILTIN_ARCHS
187${DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS}
188)
189message(STATUS "OSX supported builtin arches: ${DARWIN_osx_BUILTIN_ARCHS}")
190foreach(arch ${DARWIN_osx_BUILTIN_ARCHS})
191list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
192set(CAN_TARGET_${arch} 1)
193endforeach()
194
195foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
196if(DARWIN_${platform}sim_SYSROOT)
197set(DARWIN_${platform}sim_BUILTIN_MIN_VER
198${DARWIN_${platform}_BUILTIN_MIN_VER})
199set(DARWIN_${platform}sim_BUILTIN_MIN_VER_FLAG
200${DARWIN_${platform}_BUILTIN_MIN_VER_FLAG})
201
202set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
203
204darwin_test_archs(${platform}sim
205DARWIN_${platform}sim_BUILTIN_ARCHS
206${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
207)
208message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
209if(DARWIN_${platform}sim_BUILTIN_ARCHS)
210list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
211endif()
212foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
213list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
214set(CAN_TARGET_${arch} 1)
215endforeach()
216endif()
217
218if(DARWIN_${platform}_SYSROOT)
219darwin_test_archs(${platform}
220DARWIN_${platform}_BUILTIN_ARCHS
221${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
222)
223message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
224if(DARWIN_${platform}_BUILTIN_ARCHS)
225list(APPEND BUILTIN_SUPPORTED_OS ${platform})
226endif()
227foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
228list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
229set(CAN_TARGET_${arch} 1)
230endforeach()
231endif()
232endforeach()
233
234list_intersect(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH COMPILER_RT_SUPPORTED_ARCH)
235
236else()
237# If we're not building the builtins standalone, just rely on the tests in
238# config-ix.cmake to tell us what to build. Otherwise we need to do some leg
239# work here...
240if(COMPILER_RT_BUILTINS_STANDALONE_BUILD)
241test_targets()
242endif()
243# Architectures supported by compiler-rt libraries.
244filter_available_targets(BUILTIN_SUPPORTED_ARCH
245${ALL_BUILTIN_SUPPORTED_ARCH})
246endif()
247
248if (OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER)
249set(COMPILER_RT_HAS_CRT TRUE)
250else()
251set(COMPILER_RT_HAS_CRT FALSE)
252endif()
253
254message(STATUS "Builtin supported architectures: ${BUILTIN_SUPPORTED_ARCH}")
255