1 # CrossWinToARMLinux.cmake
3 # Set up a CMakeCache for a cross Windows to ARM Linux toolchain build.
5 # This cache file can be used to build a cross toolchain to ARM Linux
8 # NOTE: the build requires a development ARM Linux root filesystem to use
9 # proper target platform depended library and header files.
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>
16 # -DCLANG_CONFIG_FILE_SYSTEM_DIR=<full-path-to-clang-configs>
18 # See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files
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
32 # cmake --build . --target install
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
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}/../../../"
55 if (NOT DEFINED LLVM_ENABLE_ASSERTIONS)
56 set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
58 if (NOT DEFINED LLVM_ENABLE_PROJECTS)
59 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
61 if (NOT DEFINED LLVM_ENABLE_RUNTIMES)
62 set(LLVM_ENABLE_RUNTIMES "compiler-rt;libunwind;libcxxabi;libcxx" CACHE STRING "")
65 if (NOT DEFINED TOOLCHAIN_TARGET_TRIPLE)
66 set(TOOLCHAIN_TARGET_TRIPLE "aarch64-unknown-linux-gnu")
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")
77 # We suppose missed vendor's part.
78 if (TOOLCHAIN_TARGET_TRIPLE_LEN LESS 4)
79 list(INSERT TOOLCHAIN_TARGET_TRIPLE 1 "unknown")
81 string(REPLACE ";" "-" TOOLCHAIN_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}")
84 message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}")
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})
95 # Build the shared libraries for libc++/libc++abi/libunwind.
96 if (NOT DEFINED TOOLCHAIN_SHARED_LIBS)
97 set(TOOLCHAIN_SHARED_LIBS OFF)
100 if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
101 if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+")
102 set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
104 if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(aarch64|arm64)+")
105 set(LLVM_TARGETS_TO_BUILD "AArch64" CACHE STRING "")
109 message(STATUS "Toolchain target to build: ${LLVM_TARGETS_TO_BUILD}")
111 # Allow to override libc++ ABI version (1 is default).
112 if (NOT DEFINED LIBCXX_ABI_VERSION)
113 set(LIBCXX_ABI_VERSION 1)
116 message(STATUS "Toolchain's Libc++ ABI version: ${LIBCXX_ABI_VERSION}")
118 if (NOT DEFINED CMAKE_BUILD_TYPE)
119 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
122 set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: " CACHE STRING "")
123 # Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
124 set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
125 set(CMAKE_CXX_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
127 set(LLVM_DEFAULT_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
128 set(LLVM_TARGET_ARCH "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
129 set(LLVM_LIT_ARGS "-vv ${LLVM_LIT_ARGS}" CACHE STRING "" FORCE)
131 set(CLANG_DEFAULT_CXX_STDLIB "libc++" CACHE STRING "")
132 set(CLANG_DEFAULT_LINKER "lld" CACHE STRING "")
133 set(CLANG_DEFAULT_OBJCOPY "llvm-objcopy" CACHE STRING "")
134 set(CLANG_DEFAULT_RTLIB "compiler-rt" CACHE STRING "")
135 set(CLANG_DEFAULT_UNWINDLIB "libunwind" CACHE STRING "")
137 if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY AND WIN32)
138 #Note: Always specify MT DLL for the LLDB build configurations on Windows host.
139 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
140 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL" CACHE STRING "")
142 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" CACHE STRING "")
144 # Grab all ucrt/vcruntime related DLLs into the binary installation folder.
145 set(CMAKE_INSTALL_UCRT_LIBRARIES ON CACHE BOOL "")
148 # Set up RPATH for the target runtime/builtin libraries.
149 # See some details here: https://reviews.llvm.org/D91099
150 if (NOT DEFINED RUNTIMES_INSTALL_RPATH)
151 set(RUNTIMES_INSTALL_RPATH "\$ORIGIN/../lib;${CMAKE_INSTALL_PREFIX}/lib")
154 set(LLVM_BUILTIN_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
156 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
157 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
158 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
159 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_CMAKE_DIR "${LLVM_PROJECT_DIR}/llvm/cmake/modules" CACHE PATH "")
161 if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
162 foreach(lang C;CXX;ASM)
163 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS "${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
166 foreach(type SHARED;MODULE;EXE)
167 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
170 set(LLVM_RUNTIME_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
171 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
173 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_ENABLE_RUNTIMES "${LLVM_ENABLE_RUNTIMES}" CACHE STRING "")
175 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
176 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
177 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
179 if (DEFINED TOOLCHAIN_TARGET_COMPILER_FLAGS)
180 foreach(lang C;CXX;ASM)
181 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${lang}_FLAGS "${TOOLCHAIN_TARGET_COMPILER_FLAGS}" CACHE STRING "")
184 foreach(type SHARED;MODULE;EXE)
185 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
188 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
189 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
190 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
191 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
192 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
193 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_CRT ON CACHE BOOL "")
194 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
195 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
196 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_INCLUDE_TESTS ON CACHE BOOL "")
197 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
199 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
200 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "")
201 # The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1
202 # and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified.
203 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "")
205 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
206 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
208 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
209 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
210 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
211 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
212 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
214 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
215 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
216 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION ${LIBCXX_ABI_VERSION} CACHE STRING "")
217 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
218 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
219 # Merge libc++ and libc++abi libraries into the single libc++ library file.
220 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
221 # Forcely disable the libc++ benchmarks on Windows build hosts
222 # (current benchmark test configuration does not support the cross builds there).
224 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
227 # Avoid searching for the python3 interpreter during the runtimes configuration for the cross builds.
228 # It starts searching the python3 package using the target's sysroot path, that usually is not compatible with the build host.
229 find_package(Python3 COMPONENTS Interpreter)
230 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_Python3_EXECUTABLE ${Python3_EXECUTABLE} CACHE PATH "")
232 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
233 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
234 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
236 # Remote test configuration.
237 if(DEFINED REMOTE_TEST_HOST)
238 # Allow override with the custom values.
239 if(NOT DEFINED DEFAULT_TEST_EXECUTOR)
240 set(DEFAULT_TEST_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/libcxx/utils/ssh.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}")
243 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_EMULATOR
244 "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
247 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
248 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
249 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
252 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default}" CACHE INTERNAL "")
253 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default}" CACHE INTERNAL "")
254 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default}" CACHE INTERNAL "")
256 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
257 set(LLVM_TOOLCHAIN_TOOLS
273 set(LLVM_DISTRIBUTION_COMPONENTS
280 ${LLVM_TOOLCHAIN_TOOLS}