Debian Codegraph @

clang/cmake/caches/CrossWinToARMLinux.cmake

raw
1 # CrossWinToARMLinux.cmake
2 #
3 # Set up a CMakeCache for a cross Windows to ARM Linux toolchain build.
4 #
5 # This cache file can be used to build a cross toolchain to ARM Linux
6 # on Windows platform.
7 #
8 # NOTE: the build requires a development ARM Linux root filesystem to use
9 # proper target platform depended library and header files.
10 #
11 # The build generates a proper clang configuration file with stored
12 # --sysroot argument for specified target triple. Also it is possible
13 # to specify configuration path via CMake arguments, such as
14 # -DCLANG_CONFIG_FILE_USER_DIR=<full-path-to-clang-configs>
15 # and/or
16 # -DCLANG_CONFIG_FILE_SYSTEM_DIR=<full-path-to-clang-configs>
17 #
18 # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files
19 #
20 # Configure:
21 # cmake -G Ninja ^
22 # -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^
23 # -DTOOLCHAIN_TARGET_SYSROOTFS=<path-to-develop-arm-linux-root-fs> ^
24 # -DTOOLCHAIN_SHARED_LIBS=OFF ^
25 # -DCMAKE_INSTALL_PREFIX=../install ^
26 # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^
27 # -DREMOTE_TEST_HOST="<hostname>" ^
28 # -DREMOTE_TEST_USER="<ssh_user_name>" ^
29 # -C<llvm_src_root>/llvm-project/clang/cmake/caches/CrossWinToARMLinux.cmake ^
30 # <llvm_src_root>/llvm-project/llvm
31 # Build:
32 # cmake --build . --target install
33 # Tests:
34 # cmake --build . --target check-llvm
35 # cmake --build . --target check-clang
36 # cmake --build . --target check-lld
37 # cmake --build . --target check-compiler-rt-<TOOLCHAIN_TARGET_TRIPLE>
38 # cmake --build . --target check-cxxabi-<TOOLCHAIN_TARGET_TRIPLE>
39 # cmake --build . --target check-unwind-<TOOLCHAIN_TARGET_TRIPLE>
40 # cmake --build . --target check-cxx-<TOOLCHAIN_TARGET_TRIPLE>
41 # (another way to execute the tests)
42 # python bin/llvm-lit.py -v --threads=32 runtimes/runtimes-<TOOLCHAIN_TARGET_TRIPLE>bins/libunwind/test 2>&1 | tee libunwind-tests.log
43 # python bin/llvm-lit.py -v --threads=32 runtimes/runtimes-<TOOLCHAIN_TARGET_TRIPLE>-bins/libcxxabi/test 2>&1 | tee libcxxabi-tests.log
44 # python bin/llvm-lit.py -v --threads=32 runtimes/runtimes-<TOOLCHAIN_TARGET_TRIPLE>-bins/libcxx/test 2>&1 | tee libcxx-tests.log
45
46
47 # LLVM_PROJECT_DIR is the path to the llvm-project directory.
48 # The right way to compute it would probably be to use "${CMAKE_SOURCE_DIR}/../",
49 # but CMAKE_SOURCE_DIR is set to the wrong value on earlier CMake versions
50 # that we still need to support (for instance, 3.10.2).
51 get_filename_component(LLVM_PROJECT_DIR
52 "${CMAKE_CURRENT_LIST_DIR}/../../../"
53 ABSOLUTE)
54
55 if (NOT DEFINED LLVM_ENABLE_ASSERTIONS)
56 set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
57 endif()
58 if (NOT DEFINED LLVM_ENABLE_PROJECTS)
59 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
60 endif()
61 if (NOT DEFINED LLVM_ENABLE_RUNTIMES)
62 set(LLVM_ENABLE_RUNTIMES "compiler-rt;libunwind;libcxxabi;libcxx" CACHE STRING "")
63 endif()
64
65 if (NOT DEFINED TOOLCHAIN_TARGET_TRIPLE)
66 set(TOOLCHAIN_TARGET_TRIPLE "aarch64-unknown-linux-gnu")
67 else()
68 #NOTE: we must normalize specified target triple to a fully specified triple,
69 # including the vendor part. It is necessary to synchronize the runtime library
70 # installation path and operable target triple by Clang to get a correct runtime
71 # path through `-print-runtime-dir` Clang option.
72 string(REPLACE "-" ";" TOOLCHAIN_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}")
73 list(LENGTH TOOLCHAIN_TARGET_TRIPLE TOOLCHAIN_TARGET_TRIPLE_LEN)
74 if (TOOLCHAIN_TARGET_TRIPLE_LEN LESS 3)
75 message(FATAL_ERROR "invalid target triple")
76 endif()
77 # We suppose missed vendor's part.
78 if (TOOLCHAIN_TARGET_TRIPLE_LEN LESS 4)
79 list(INSERT TOOLCHAIN_TARGET_TRIPLE 1 "unknown")
80 endif()
81 string(REPLACE ";" "-" TOOLCHAIN_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}")
82 endif()
83
84 message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}")
85
86 if (DEFINED TOOLCHAIN_TARGET_SYSROOTFS)
87 message(STATUS "Toolchain target sysroot: ${TOOLCHAIN_TARGET_SYSROOTFS}")
88 # Store the --sysroot argument for the compiler-rt test flags.
89 set(sysroot_flags --sysroot='${TOOLCHAIN_TARGET_SYSROOTFS}')
90 # Generate the clang configuration file for the specified target triple
91 # and store --sysroot in this file.
92 file(WRITE "${CMAKE_BINARY_DIR}/bin/${TOOLCHAIN_TARGET_TRIPLE}.cfg" ${sysroot_flags})
93 endif()
94
95 # Build the shared libraries for libc++/libc++abi/libunwind.
96 if (NOT DEFINED TOOLCHAIN_SHARED_LIBS)
97 set(TOOLCHAIN_SHARED_LIBS OFF)
98 endif()
99 # Enable usage of the static libunwind and libc++abi libraries.
100 if (NOT DEFINED TOOLCHAIN_USE_STATIC_LIBS)
101 set(TOOLCHAIN_USE_STATIC_LIBS ON)
102 endif()
103
104 if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
105 if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+")
106 set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
107 endif()
108 if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(aarch64|arm64)+")
109 set(LLVM_TARGETS_TO_BUILD "AArch64" CACHE STRING "")
110 endif()
111 endif()
112
113 message(STATUS "Toolchain target to build: ${LLVM_TARGETS_TO_BUILD}")
114
115 # Allow to override libc++ ABI version (1 is default).
116 if (NOT DEFINED LIBCXX_ABI_VERSION)
117 set(LIBCXX_ABI_VERSION 1)
118 endif()
119
120 message(STATUS "Toolchain's Libc++ ABI version: ${LIBCXX_ABI_VERSION}")
121
122 if (NOT DEFINED CMAKE_BUILD_TYPE)
123 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
124 endif()
125
126 set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: " CACHE STRING "")
127 # Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
128 set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
129 set(CMAKE_CXX_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
130
131 set(LLVM_DEFAULT_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
132 set(LLVM_TARGET_ARCH "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
133 set(LLVM_LIT_ARGS "-vv ${LLVM_LIT_ARGS}" CACHE STRING "" FORCE)
134
135 set(CLANG_DEFAULT_CXX_STDLIB "libc++" CACHE STRING "")
136 set(CLANG_DEFAULT_LINKER "lld" CACHE STRING "")
137 set(CLANG_DEFAULT_OBJCOPY "llvm-objcopy" CACHE STRING "")
138 set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
139 set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
140
141 if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND WIN32)
142 #Note: Always specify MT DLL for the LLDB build configurations on Windows host.
143 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
144 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL" CACHE STRING "")
145 else()
146 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" CACHE STRING "")
147 endif()
148 # Grab all ucrt/vcruntime related DLLs into the binary installation folder.
149 set(CMAKE_INSTALL_UCRT_LIBRARIES ON CACHE BOOL "")
150 endif()
151
152 # Set up RPATH for the target runtime/builtin libraries.
153 # See some details here: https://reviews.llvm.org/D91099
154 if (NOT DEFINED RUNTIMES_INSTALL_RPATH)
155 set(RUNTIMES_INSTALL_RPATH "\$ORIGIN/../lib;${CMAKE_INSTALL_PREFIX}/lib")
156 endif()
157
158 set(LLVM_BUILTIN_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
159
160 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
161 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
162 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
163 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_CMAKE_DIR "${LLVM_PROJECT_DIR}/llvm/cmake/modules" CACHE PATH "")
164
165 if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
166 foreach(lang C;CXX;ASM)
167 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS "${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
168 endforeach()
169 endif()
170 foreach(type SHARED;MODULE;EXE)
171 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
172 endforeach()
173
174 set(LLVM_RUNTIME_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
175 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
176
177 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_ENABLE_RUNTIMES "${LLVM_ENABLE_RUNTIMES}" CACHE STRING "")
178
179 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
180 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
181 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
182
183 if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
184 foreach(lang C;CXX;ASM)
185 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS "${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
186 endforeach()
187 endif()
188 foreach(type SHARED;MODULE;EXE)
189 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
190 endforeach()
191
192 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
193 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
194 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
195 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
196 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
197 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_CRT ON CACHE BOOL "")
198 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
199 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
200 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_INCLUDE_TESTS ON CACHE BOOL "")
201 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
202
203 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
204 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "")
205 # The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1
206 # and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified.
207 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "")
208
209 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
210 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
211
212 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
213 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
214 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
215 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
216 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
217
218 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
219 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
220 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION ${LIBCXX_ABI_VERSION} CACHE STRING "")
221 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
222 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
223 # Merge libc++ and libc++abi libraries into the single libc++ library file.
224 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ${TOOLCHAIN_USE_STATIC_LIBS} CACHE BOOL "")
225 # Forcely disable the libc++ benchmarks on Windows build hosts
226 # (current benchmark test configuration does not support the cross builds there).
227 if (WIN32)
228 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
229 endif(WIN32)
230
231 # Avoid searching for the python3 interpreter during the runtimes configuration for the cross builds.
232 # It starts searching the python3 package using the target's sysroot path, that usually is not compatible with the build host.
233 find_package(Python3 COMPONENTS Interpreter)
234 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_Python3_EXECUTABLE ${Python3_EXECUTABLE} CACHE PATH "")
235
236 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
237 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
238 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
239
240 # Remote test configuration.
241 if(DEFINED REMOTE_TEST_HOST)
242 # Allow override with the custom values.
243 if(NOT DEFINED DEFAULT_TEST_EXECUTOR)
244 set(DEFAULT_TEST_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/libcxx/utils/ssh.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}")
245 endif()
246
247 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_EMULATOR
248 "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
249 CACHE STRING "")
250
251 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
252 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
253 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
254 endif()
255
256 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default}" CACHE INTERNAL "")
257 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default}" CACHE INTERNAL "")
258 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default}" CACHE INTERNAL "")
259
260 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
261 set(LLVM_TOOLCHAIN_TOOLS
262 llvm-ar
263 llvm-cov
264 llvm-cxxfilt
265 llvm-dwarfdump
266 llvm-lib
267 llvm-nm
268 llvm-objdump
269 llvm-pdbutil
270 llvm-profdata
271 llvm-ranlib
272 llvm-readobj
273 llvm-size
274 llvm-symbolizer
275 CACHE STRING "")
276
277 set(LLVM_DISTRIBUTION_COMPONENTS
278 clang
279 lld
280 LTO
281 clang-format
282 builtins
283 runtimes
284 ${LLVM_TOOLCHAIN_TOOLS}
285 CACHE STRING "")