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.
13 # -DTOOLCHAIN_TARGET_TRIPLE=armv7-unknown-linux-gnueabihf ^
14 # -DCMAKE_INSTALL_PREFIX=../install ^
15 # -DDEFAULT_SYSROOT=<path-to-develop-arm-linux-root-fs> ^
16 # -DLLVM_AR=<llvm_obj_root>/bin/llvm-ar[.exe] ^
17 # -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^
18 # -DREMOTE_TEST_HOST="<hostname>" ^
19 # -DREMOTE_TEST_USER="<ssh_user_name>" ^
20 # -C<llvm_src_root>/llvm-project/clang/cmake/caches/CrossWinToARMLinux.cmake ^
21 # <llvm_src_root>/llvm-project/llvm
23 # cmake --build . --target install
25 # cmake --build . --target check-llvm
26 # cmake --build . --target check-clang
27 # cmake --build . --target check-lld
28 # cmake --build . --target check-compiler-rt-<TOOLCHAIN_TARGET_TRIPLE>
29 # cmake --build . --target check-cxxabi-<TOOLCHAIN_TARGET_TRIPLE>
30 # cmake --build . --target check-unwind-<TOOLCHAIN_TARGET_TRIPLE>
31 # cmake --build . --target check-cxx-<TOOLCHAIN_TARGET_TRIPLE>
33 # LLVM_PROJECT_DIR is the path to the llvm-project directory.
34 # The right way to compute it would probably be to use "${CMAKE_SOURCE_DIR}/../",
35 # but CMAKE_SOURCE_DIR is set to the wrong value on earlier CMake versions
36 # that we still need to support (for instance, 3.10.2).
37 get_filename_component(LLVM_PROJECT_DIR
38 "${CMAKE_CURRENT_LIST_DIR}/../../../"
41 if (NOT DEFINED DEFAULT_SYSROOT)
42 message(WARNING "DEFAULT_SYSROOT must be specified for the cross toolchain build.")
45 if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
46 set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
48 if (NOT DEFINED LLVM_ENABLE_ASSERTIONS)
49 set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
51 if (NOT DEFINED LLVM_ENABLE_PROJECTS)
52 set(LLVM_ENABLE_PROJECTS "clang;clang-tools-extra;lld" CACHE STRING "")
54 if (NOT DEFINED LLVM_ENABLE_RUNTIMES)
55 set(LLVM_ENABLE_RUNTIMES "compiler-rt;libunwind;libcxxabi;libcxx" CACHE STRING "")
58 if (NOT DEFINED TOOLCHAIN_TARGET_TRIPLE)
59 set(TOOLCHAIN_TARGET_TRIPLE "armv7-unknown-linux-gnueabihf")
61 #NOTE: we must normalize specified target triple to a fully specified triple,
62 # including the vendor part. It is necessary to synchronize the runtime library
63 # installation path and operable target triple by Clang to get a correct runtime
64 # path through `-print-runtime-dir` Clang option.
65 string(REPLACE "-" ";" TOOLCHAIN_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}")
66 list(LENGTH TOOLCHAIN_TARGET_TRIPLE TOOLCHAIN_TARGET_TRIPLE_LEN)
67 if (TOOLCHAIN_TARGET_TRIPLE_LEN LESS 3)
68 message(FATAL_ERROR "invalid target triple")
70 # We suppose missed vendor's part.
71 if (TOOLCHAIN_TARGET_TRIPLE_LEN LESS 4)
72 list(INSERT TOOLCHAIN_TARGET_TRIPLE 1 "unknown")
74 string(REPLACE ";" "-" TOOLCHAIN_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}")
77 if (NOT DEFINED CMAKE_BUILD_TYPE)
78 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
81 message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}")
83 set(CMAKE_CROSSCOMPILING ON CACHE BOOL "")
84 set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: " CACHE STRING "")
85 # Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
86 set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
87 set(CMAKE_CXX_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
89 set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
90 set(LLVM_DEFAULT_TARGET_TRIPLE "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
91 set(LLVM_TARGET_ARCH "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
92 set(LLVM_LIT_ARGS "-vv ${LLVM_LIT_ARGS}" CACHE STRING "" FORCE)
94 set(CLANG_DEFAULT_LINKER "lld" CACHE STRING "")
97 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "")
100 # Set up RPATH for the target runtime/builtin libraries.
101 # See some details here: https://reviews.llvm.org/D91099
102 if (NOT DEFINED RUNTIMES_INSTALL_RPATH)
103 set(RUNTIMES_INSTALL_RPATH "\$ORIGIN/../lib;${CMAKE_INSTALL_PREFIX}/lib")
106 set(LLVM_BUILTIN_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
108 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
109 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSROOT "${DEFAULT_SYSROOT}" CACHE STRING "")
110 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
111 set(BUILTINS_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
114 set(LLVM_RUNTIME_TARGETS "${TOOLCHAIN_TARGET_TRIPLE}" CACHE STRING "")
116 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LLVM_ENABLE_RUNTIMES "${LLVM_ENABLE_RUNTIMES}" CACHE STRING "")
118 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSTEM_NAME "Linux" CACHE STRING "")
119 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_SYSROOT "${DEFAULT_SYSROOT}" CACHE STRING "")
120 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_INSTALL_RPATH "${RUNTIMES_INSTALL_RPATH}" CACHE STRING "")
121 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
123 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
124 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
125 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
126 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
127 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
128 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_CRT OFF CACHE BOOL "")
129 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
130 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_DEFAULT_TARGET_ONLY ON CACHE BOOL "")
131 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_INCLUDE_TESTS ON CACHE BOOL "")
132 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "")
134 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
136 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
137 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
139 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
140 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
141 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
142 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
143 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
145 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
146 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
147 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
148 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
149 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
152 find_package(Python3 COMPONENTS Interpreter)
154 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
155 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
156 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_TEST_PARAMS}")
158 # Remote test configuration.
159 if(DEFINED REMOTE_TEST_HOST)
160 # Allow override with the custom values.
161 if(NOT DEFINED DEFAULT_TEST_EXECUTOR)
162 set(DEFAULT_TEST_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/libcxx/utils/ssh.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}")
165 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_EMULATOR
166 "\\\"${Python3_EXECUTABLE}\\\" \\\"${LLVM_PROJECT_DIR}/llvm/utils/remote-exec.py\\\" --host=${REMOTE_TEST_USER}@${REMOTE_TEST_HOST}"
169 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
170 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
171 list(APPEND RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default "executor=${DEFAULT_TEST_EXECUTOR}")
174 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_TEST_PARAMS_default}" CACHE INTERNAL "")
175 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_TEST_PARAMS_default}" CACHE INTERNAL "")
176 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS "${RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_TEST_PARAMS_default}" CACHE INTERNAL "")
178 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
179 set(LLVM_TOOLCHAIN_TOOLS
195 set(LLVM_DISTRIBUTION_COMPONENTS
202 ${LLVM_TOOLCHAIN_TOOLS}