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