Skip to content

Commit 4135be7

Browse files
committed
[CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC.
* generate Clang configuration file with provided target sysroot (TOOLCHAIN_TARGET_SYSROOTFS) * explicitly pass provided target sysroot into the compiler-rt tests configuration. * added ability to configure a type of the build libraries -- shared or static (TOOLCHAIN_SHARED_LIBS, default OFF)
1 parent 81671fe commit 4135be7

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

clang/cmake/caches/CrossWinToARMLinux.cmake

+31-14
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@
66
# on Windows platform.
77
#
88
# NOTE: the build requires a development ARM Linux root filesystem to use
9-
# proper target platform depended library and header files:
10-
# - create <full-path-to-clang-configs> directory and put the clang configuration
11-
# file named <TOOLCHAIN_TARGET_TRIPLE>.cfg into it.
12-
# - add the `--sysroot=<path-to-develop-arm-linux-root-fs>` argument into
13-
# this configuration file.
14-
# - add other necessary target depended clang arguments there,
15-
# such as '-mcpu=cortex-a78' & etc.
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>
1617
#
1718
# See more details here: https://clang.llvm.org/docs/UsersManual.html#configuration-files
1819
#
1920
# Configure:
2021
# cmake -G Ninja ^
2122
# -DTOOLCHAIN_TARGET_TRIPLE=aarch64-unknown-linux-gnu ^
23+
# -DTOOLCHAIN_TARGET_SYSROOTFS=<path-to-develop-arm-linux-root-fs> ^
24+
# -DTOOLCHAIN_SHARED_LIBS=OFF ^
2225
# -DCMAKE_INSTALL_PREFIX=../install ^
23-
# -DCLANG_CONFIG_FILE_USER_DIR=<full-path-to-clang-configs> ^
2426
# -DCMAKE_CXX_FLAGS="-D__OPTIMIZE__" ^
2527
# -DREMOTE_TEST_HOST="<hostname>" ^
2628
# -DREMOTE_TEST_USER="<ssh_user_name>" ^
@@ -81,6 +83,20 @@ endif()
8183

8284
message(STATUS "Toolchain target triple: ${TOOLCHAIN_TARGET_TRIPLE}")
8385

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+
84100
if (NOT DEFINED LLVM_TARGETS_TO_BUILD)
85101
if ("${TOOLCHAIN_TARGET_TRIPLE}" MATCHES "^(armv|arm32)+")
86102
set(LLVM_TARGETS_TO_BUILD "ARM" CACHE STRING "")
@@ -183,20 +199,21 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CAN_EXECUTE_TESTS
183199

184200
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "")
185201
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_CXX_LIBRARY libcxx CACHE STRING "")
186-
# Tell Clang to seach C++ headers alongside with the just-built binaries for the C++ compiler-rt tests.
187-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++" CACHE STRING "")
188-
202+
# The compiler-rt tests disable the clang configuration files during the execution by setting CLANG_NO_DEFAULT_CONFIG=1
203+
# and drops out the --sysroot from there. Provide it explicity via the test flags here if target sysroot has been specified.
204+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_COMPILER_RT_TEST_COMPILER_CFLAGS "--stdlib=libc++ ${sysroot_flags}" CACHE STRING "")
205+
189206
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
190-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
207+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBUNWIND_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
191208

192209
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
193210
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
194211
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
195212
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
196-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
213+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXXABI_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
197214

198215
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
199-
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
216+
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_SHARED ${TOOLCHAIN_SHARED_LIBS} CACHE BOOL "")
200217
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ABI_VERSION ${LIBCXX_ABI_VERSION} CACHE STRING "")
201218
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI "libcxxabi" CACHE STRING "") #!!!
202219
set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")

0 commit comments

Comments
 (0)