Skip to content

Commit 5082acc

Browse files
authored
[compiler-rt] Add custom libc++ workaround for CMake < 3.26
The INSTALL_BYPRODUCTS ExternalProject_Add() argument was only added in CMake 3.26 and the current minimum is 3.20. Work around this by using an explicit ExternalProject_Add_Step() call for the install step with a BYPRODUCTS argument. We can't keep using the `install` name here since that is reserved by the CMake implementation and results in errors when used. This commit should be reverted once LLVM depends on CMake 3.26. Pull Request: #115677
1 parent 595f3e9 commit 5082acc

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,18 +706,30 @@ macro(add_custom_libcxx name prefix)
706706
-DLLVM_INCLUDE_TESTS=OFF
707707
-DLLVM_INCLUDE_DOCS=OFF
708708
${LIBCXX_CMAKE_ARGS}
709-
STEP_TARGETS configure build install
709+
STEP_TARGETS configure build
710710
BUILD_ALWAYS 1
711711
USES_TERMINAL_CONFIGURE 1
712712
USES_TERMINAL_BUILD 1
713713
USES_TERMINAL_INSTALL 1
714714
LIST_SEPARATOR |
715715
EXCLUDE_FROM_ALL TRUE
716+
)
717+
718+
# Once we depend on CMake 3.26, we can use the INSTALL_BYPRODUCTS argument
719+
# instead of having to fall back to ExternalProject_Add_Step()
720+
# Note: We can't use the normal name "install" here since that interferes
721+
# with the default ExternalProject_Add() logic and causes errors.
722+
ExternalProject_Add_Step(${name} install-cmake326-workaround
716723
# Ensure that DESTDIR=... set in the out environment does not affect this
717724
# target (we always need to install to the build directory).
718-
INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build ${prefix}/build --target install
719-
INSTALL_BYPRODUCTS "${prefix}/lib/libc++.a" "${prefix}/lib/libc++abi.a"
720-
)
725+
COMMAND env DESTDIR= ${CMAKE_COMMAND} --build ${prefix}/build --target install
726+
COMMENT "Installing ${name}..."
727+
BYPRODUCTS "${prefix}/lib/libc++.a" "${prefix}/lib/libc++abi.a"
728+
DEPENDEES build
729+
EXCLUDE_FROM_MAIN 1
730+
USES_TERMINAL 1
731+
)
732+
ExternalProject_Add_StepTargets(${name} install-cmake326-workaround)
721733

722734
if (CMAKE_GENERATOR MATCHES "Make")
723735
set(run_clean "$(MAKE)" "-C" "${prefix}" "clean")

compiler-rt/lib/fuzzer/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ if(OS_NAME MATCHES "Android|Linux|Fuchsia" AND
166166
-DLIBCXX_ABI_NAMESPACE=__Fuzzer
167167
-DLIBCXX_ENABLE_EXCEPTIONS=OFF)
168168
target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
169-
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-install)
169+
add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-install-cmake326-workaround)
170170
target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
171-
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-install)
171+
add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-install-cmake326-workaround)
172172
target_compile_options(RTfuzzer_interceptors.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
173-
add_dependencies(RTfuzzer_interceptors.${arch} libcxx_fuzzer_${arch}-install)
173+
add_dependencies(RTfuzzer_interceptors.${arch} libcxx_fuzzer_${arch}-install-cmake326-workaround)
174174
partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch})
175175
partially_link_libcxx(fuzzer_interceptors ${LIBCXX_${arch}_PREFIX} ${arch})
176176
partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch})

compiler-rt/lib/fuzzer/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
6464
COMPILER_RT_LIBCXX_PATH AND
6565
COMPILER_RT_LIBCXXABI_PATH)
6666
file(GLOB libfuzzer_headers ../*.h)
67-
set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch}-install ${libfuzzer_headers})
67+
set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch}-install-cmake326-workaround ${libfuzzer_headers})
6868
set(LIBFUZZER_TEST_RUNTIME_CFLAGS -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
6969
set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}/lib/libc++.a)
7070
endif()

compiler-rt/lib/msan/tests/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ macro(msan_compile obj_list source arch kind cflags)
6969
sanitizer_test_compile(
7070
${obj_list} ${source} ${arch}
7171
KIND ${kind}
72-
COMPILE_DEPS ${MSAN_UNITTEST_HEADERS} libcxx_msan_${arch}-install
72+
COMPILE_DEPS ${MSAN_UNITTEST_HEADERS} libcxx_msan_${arch}-install-cmake326-workaround
7373
DEPS msan
7474
CFLAGS -isystem ${MSAN_LIBCXX_DIR}/../include/c++/v1
7575
${MSAN_UNITTEST_INSTRUMENTED_CFLAGS} ${cflags}
@@ -117,10 +117,10 @@ macro(add_msan_tests_for_arch arch kind cflags)
117117
DEPS ${MSAN_INST_LOADABLE_OBJECTS})
118118

119119
set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST})
120-
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-install
120+
set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-install-cmake326-workaround
121121
${MSAN_LOADABLE_SO}
122122
"${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a")
123-
list(APPEND MSAN_TEST_DEPS msan libcxx_msan_${arch}-install)
123+
list(APPEND MSAN_TEST_DEPS msan libcxx_msan_${arch}-install-cmake326-workaround)
124124
get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
125125
add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
126126
OBJECTS ${MSAN_TEST_OBJECTS} "${MSAN_LIBCXX_DIR}/libc++.a" "${MSAN_LIBCXX_DIR}/libc++abi.a"

compiler-rt/lib/tsan/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if(COMPILER_RT_LIBCXX_PATH AND
3131
DEPS ${TSAN_RUNTIME_LIBRARIES}
3232
CFLAGS ${TARGET_CFLAGS} -fsanitize=thread
3333
USE_TOOLCHAIN)
34-
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-install)
34+
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-install-cmake326-workaround)
3535
endforeach()
3636

3737
add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps})

0 commit comments

Comments
 (0)