8c6243a832ccf4adf161e486c811d03b0eb38ed4
[lldb.git] / compiler-rt / cmake / builtin-config-ix.cmake
1 include(BuiltinTests)
2 include(CheckCSourceCompiles)
3
4 # Make all the tests only check the compiler
5 set(TEST_COMPILE_ONLY On)
6
7 # Check host compiler support for certain flags
8 builtin_check_c_compiler_flag(-fPIC                 COMPILER_RT_HAS_FPIC_FLAG)
9 builtin_check_c_compiler_flag(-fPIE                 COMPILER_RT_HAS_FPIE_FLAG)
10 builtin_check_c_compiler_flag(-fno-builtin          COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
11 builtin_check_c_compiler_flag(-std=c11              COMPILER_RT_HAS_STD_C11_FLAG)
12 builtin_check_c_compiler_flag(-fvisibility=hidden   COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG)
13 builtin_check_c_compiler_flag(-fomit-frame-pointer  COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG)
14 builtin_check_c_compiler_flag(-ffreestanding        COMPILER_RT_HAS_FREESTANDING_FLAG)
15 builtin_check_c_compiler_flag(-fxray-instrument     COMPILER_RT_HAS_XRAY_COMPILER_FLAG)
16
17 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
18 "
19 int foo(int x, int y) {
20  _Atomic int result = x * y;
21  return result;
22 }
23 ")
24
25 builtin_check_c_compiler_source(COMPILER_RT_HAS_FLOAT16
26 "
27 _Float16 foo(_Float16 x) {
28  return x;
29 }
30 "
31 )
32
33 set(ARM64 aarch64)
34 set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k)
35 set(HEXAGON hexagon)
36 set(X86 i386)
37 set(X86_64 x86_64)
38 set(MIPS32 mips mipsel)
39 set(MIPS64 mips64 mips64el)
40 set(PPC32 powerpc)
41 set(PPC64 powerpc64 powerpc64le)
42 set(RISCV32 riscv32)
43 set(RISCV64 riscv64)
44 set(SPARC sparc)
45 set(SPARCV9 sparcv9)
46 set(WASM32 wasm32)
47 set(WASM64 wasm64)
48 set(VE ve)
49
50 if(APPLE)
51   set(ARM64 arm64 arm64e)
52   set(ARM32 armv7 armv7k armv7s)
53   set(X86_64 x86_64 x86_64h)
54 endif()
55
56 set(ALL_BUILTIN_SUPPORTED_ARCH
57   ${X86} ${X86_64} ${ARM32} ${ARM64}
58   ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC32} ${PPC64}
59   ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9}
60   ${WASM32} ${WASM64} ${VE})
61
62 include(CompilerRTUtils)
63 include(CompilerRTDarwinUtils)
64
65 if(APPLE)
66
67   find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
68   find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
69   find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
70   find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
71   find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
72   find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
73   find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
74
75   # Get supported architecture from SDKSettings.
76   function(sdk_has_arch_support sdk_path os arch has_support)
77     execute_process(COMMAND
78         /usr/libexec/PlistBuddy -c "Print :SupportedTargets:${os}:Archs" ${sdk_path}/SDKSettings.plist
79       OUTPUT_VARIABLE SDK_SUPPORTED_ARCHS
80       RESULT_VARIABLE PLIST_ERROR)
81     if (PLIST_ERROR EQUAL 0 AND
82         SDK_SUPPORTED_ARCHS MATCHES " ${arch}\n")
83       message(STATUS "Found ${arch} support in ${sdk_path}/SDKSettings.plist")
84       set("${has_support}" On PARENT_SCOPE)
85     else()
86       message(STATUS "No ${arch} support in ${sdk_path}/SDKSettings.plist")
87       set("${has_support}" Off PARENT_SCOPE)
88     endif()
89   endfunction()
90
91   set(DARWIN_EMBEDDED_PLATFORMS)
92   set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
93   set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
94       -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
95   set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
96   # Add support for arm64 macOS if available in SDK.
97   foreach(arch ${ARM64})
98     sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT)
99     if (MACOS_ARM_SUPPORT)
100      list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch})
101     endif()
102   endforeach(arch)
103
104   if(COMPILER_RT_ENABLE_IOS)
105     list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
106     set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
107     set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
108     set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
109       ${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_BUILTIN_MIN_VER})
110     set(DARWIN_ios_BUILTIN_ALL_POSSIBLE_ARCHS ${ARM64} ${ARM32})
111     set(DARWIN_iossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
112   endif()
113   if(COMPILER_RT_ENABLE_WATCHOS)
114     list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
115     set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
116     set(DARWIN_watchos_BUILTIN_MIN_VER 2.0)
117     set(DARWIN_watchos_BUILTIN_MIN_VER_FLAG
118       ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_BUILTIN_MIN_VER})
119     set(DARWIN_watchos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 armv7k)
120     set(DARWIN_watchossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86})
121   endif()
122   if(COMPILER_RT_ENABLE_TVOS)
123     list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
124     set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
125     set(DARWIN_tvos_BUILTIN_MIN_VER 9.0)
126     set(DARWIN_tvos_BUILTIN_MIN_VER_FLAG
127       ${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_BUILTIN_MIN_VER})
128     set(DARWIN_tvos_BUILTIN_ALL_POSSIBLE_ARCHS armv7 arm64)
129     set(DARWIN_tvossim_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64})
130   endif()
131
132   set(BUILTIN_SUPPORTED_OS osx)
133
134   # We're setting the flag manually for each target OS
135   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
136
137   # NOTE: We deliberately avoid using `DARWIN_<os>_ARCHS` here because that is
138   # used by `config-ix.cmake` in the context of building the rest of
139   # compiler-rt where the global `${TEST_COMPILE_ONLY}` (used by
140   # `darwin_test_archs()`) has a different value.
141   darwin_test_archs(osx
142     DARWIN_osx_BUILTIN_ARCHS
143     ${DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS}
144   )
145   message(STATUS "OSX supported builtin arches: ${DARWIN_osx_BUILTIN_ARCHS}")
146   foreach(arch ${DARWIN_osx_BUILTIN_ARCHS})
147     list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
148     set(CAN_TARGET_${arch} 1)
149   endforeach()
150
151   foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
152     if(DARWIN_${platform}sim_SYSROOT)
153       set(DARWIN_${platform}sim_BUILTIN_MIN_VER
154         ${DARWIN_${platform}_BUILTIN_MIN_VER})
155       set(DARWIN_${platform}sim_BUILTIN_MIN_VER_FLAG
156         ${DARWIN_${platform}_BUILTIN_MIN_VER_FLAG})
157
158       set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
159
160       darwin_test_archs(${platform}sim
161         DARWIN_${platform}sim_BUILTIN_ARCHS
162         ${DARWIN_${platform}sim_BUILTIN_ALL_POSSIBLE_ARCHS}
163       )
164       message(STATUS "${platform} Simulator supported builtin arches: ${DARWIN_${platform}sim_BUILTIN_ARCHS}")
165       if(DARWIN_${platform}sim_BUILTIN_ARCHS)
166         list(APPEND BUILTIN_SUPPORTED_OS ${platform}sim)
167       endif()
168       foreach(arch ${DARWIN_${platform}sim_BUILTIN_ARCHS})
169         list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
170         set(CAN_TARGET_${arch} 1)
171       endforeach()
172     endif()
173
174     if(DARWIN_${platform}_SYSROOT)
175       darwin_test_archs(${platform}
176         DARWIN_${platform}_BUILTIN_ARCHS
177         ${DARWIN_${platform}_BUILTIN_ALL_POSSIBLE_ARCHS}
178       )
179       message(STATUS "${platform} supported builtin arches: ${DARWIN_${platform}_BUILTIN_ARCHS}")
180       if(DARWIN_${platform}_BUILTIN_ARCHS)
181         list(APPEND BUILTIN_SUPPORTED_OS ${platform})
182       endif()
183       foreach(arch ${DARWIN_${platform}_BUILTIN_ARCHS})
184         list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
185         set(CAN_TARGET_${arch} 1)
186       endforeach()
187     endif()
188   endforeach()
189
190   list_intersect(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH COMPILER_RT_SUPPORTED_ARCH)
191
192 else()
193   # If we're not building the builtins standalone, just rely on the  tests in
194   # config-ix.cmake to tell us what to build. Otherwise we need to do some leg
195   # work here...
196   if(COMPILER_RT_BUILTINS_STANDALONE_BUILD)
197     test_targets()
198   endif()
199   # Architectures supported by compiler-rt libraries.
200   filter_available_targets(BUILTIN_SUPPORTED_ARCH
201     ${ALL_BUILTIN_SUPPORTED_ARCH})
202 endif()
203
204 message(STATUS "Builtin supported architectures: ${BUILTIN_SUPPORTED_ARCH}")