@@ -96,6 +96,7 @@ set(ENABLE_LIBC_TESTS ${ENABLE_LIBC_TESTS_def} CACHE BOOL "Enable libc tests (pi
9696set (ENABLE_COMPILER_RT_TESTS ${ENABLE_COMPILER_RT_TESTS_def} CACHE BOOL "Enable compiler-rt tests." )
9797set (ENABLE_LIBCXX_TESTS ${ENABLE_LIBCXX_TESTS_def} CACHE BOOL "Enable libcxx tests." )
9898set (LLVM_BINARY_DIR "" CACHE PATH "Path to LLVM toolchain root to build libraries with" )
99+ set (LIBC_HDRGEN "" CACHE PATH "Path to prebuilt lbc-hdrgen if not included in LLVM binaries set by LLVM_BINARY_DIR" )
99100
100101# Temporary location to collect the libraries as they are built.
101102set (TEMP_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR} /tmp_install" )
@@ -137,16 +138,23 @@ else()
137138 else ()
138139 set (target_triple "arm-none-eabi" )
139140 endif ()
140- if (flags MATCHES "-mfloat-abi=hard" )
141+ if (COMPILE_FLAGS MATCHES "-mfloat-abi=hard" )
141142 # Also, compiler-rt looks in the ABI component of the
142143 # triple to decide whether to use the hard float ABI.
143144 set (target_triple "${target_triple} hf" )
144145 endif ()
145146 set (cpu_family arm)
146147endif ()
147148
149+ # Create a single target for all testing. If no testing is enabled, this
150+ # will simply do nothing.
151+ add_custom_target (check-all )
152+
148153# If any testing is enabled, prepare test executor settings.
149154if (ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
155+ # Flags required to link tests.
156+ set (test_link_flags "-nostartfiles -lcrt0-semihost -lsemihost -T picolibcpp.ld" )
157+
150158 if (TEST_EXECUTOR STREQUAL qemu)
151159 if (TARGET_ARCH MATCHES "^aarch64" )
152160 find_program (QEMU_EXECUTABLE qemu-system -aarch64)
@@ -198,7 +206,6 @@ if (ENABLE_LIBC_TESTS OR ENABLE_COMPILER_RT_TESTS OR ENABLE_LIBCXX_TESTS)
198206endif ()
199207
200208set (compile_arch_flags "--target=${target_triple} ${COMPILE_FLAGS} " )
201- set (link_flags "-nostartfiles -lcrt0-semihost -lsemihost -T picolibcpp.ld" )
202209# Compiling the libraries benefits from some extra optimization
203210# flags, and requires a sysroot.
204211set (lib_compile_flags "${compile_arch_flags} -ffunction-sections -fdata-sections -fno-ident --sysroot ${TEMP_LIB_DIR} " )
@@ -238,7 +245,7 @@ if(VARIANT STREQUAL "armv6m_soft_nofp")
238245endif ()
239246
240247if (ENABLE_COMPILER_RT_TESTS)
241- set (compiler_rt_test_flags "${lib_compile_flags} ${link_flags } " )
248+ set (compiler_rt_test_flags "${lib_compile_flags} ${test_link_flags } " )
242249 set (compiler_rt_lit_args "${LLVM_LIT_ARGS} --xunit-xml-output=results.junit.xml" )
243250 set (
244251 compiler_rt_test_cmake_args
@@ -298,6 +305,7 @@ ExternalProject_Add(
298305)
299306
300307add_custom_target (check-compiler-rt)
308+ add_dependencies (check-all check-compiler-rt)
301309if (ENABLE_COMPILER_RT_TESTS)
302310 ExternalProject_Add_Step(
303311 compiler_rt
@@ -357,7 +365,7 @@ if(C_LIBRARY STREQUAL picolibc)
357365 to_meson_list("${picolibc_flags} " picolibc_meson_flags)
358366
359367 if (ENABLE_LIBC_TESTS)
360- set (picolibc_test_executor_bin ${CMAKE_CURRENT_SOURCE_DIR} /picolibc-test -wrapper.py)
368+ set (picolibc_test_executor_bin ${CMAKE_CURRENT_SOURCE_DIR} /test -support/ picolibc-test -wrapper.py)
361369 to_meson_list("${test_executor_params} " meson_test_executor_params)
362370 endif ()
363371
@@ -394,6 +402,7 @@ if(C_LIBRARY STREQUAL picolibc)
394402 )
395403
396404 add_custom_target (check-picolibc)
405+ add_dependencies (check-all check-picolibc)
397406 if (ENABLE_LIBC_TESTS)
398407 # meson builds the tests at the same time as the library.
399408 # So reconfigure to enable tests at a later point.
@@ -416,7 +425,7 @@ if(C_LIBRARY STREQUAL picolibc)
416425 check
417426 COMMAND ${MESON_EXECUTABLE} test -C <BINARY_DIR>
418427 COMMAND ${Python3_EXECUTABLE}
419- ${TOOLCHAIN_SOURCE_DIR } /test -support/modify-picolibc-xml.py
428+ ${CMAKE_CURRENT_SOURCE_DIR } /test -support/modify-picolibc-xml.py
420429 --picolibc-build -dir <BINARY_DIR>
421430 --variant ${VARIANT}
422431 USES_TERMINAL TRUE
@@ -542,6 +551,8 @@ if(C_LIBRARY STREQUAL llvmlibc)
542551 DESTINATION
543552 ${LIBC_CFG_DIR}
544553 )
554+
555+ set (lib_compile_flags "${lib_compile_flags} -Wno-error=atomic-alignment" )
545556
546557 set (common_llvmlibc_cmake_args
547558 -DCMAKE_AR=${LLVM_BINARY_DIR} /bin/llvm-ar${CMAKE_EXECUTABLE_SUFFIX}
@@ -568,6 +579,9 @@ if(C_LIBRARY STREQUAL llvmlibc)
568579 # If libc-hdrgen is provided, there is no need to build it,
569580 # but a target is still needed to satisfy the dependency.
570581 add_custom_target (libc_hdrgen)
582+ elseif (EXISTS ${LLVM_BINARY_DIR} /bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX} )
583+ set (LIBC_HDRGEN ${LLVM_BINARY_DIR} /bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX} )
584+ add_custom_target (libc_hdrgen)
571585 else ()
572586 ExternalProject_Add(
573587 libc_hdrgen
@@ -576,10 +590,8 @@ if(C_LIBRARY STREQUAL llvmlibc)
576590 -DLLVM_ENABLE_RUNTIMES=libc
577591 -DLLVM_LIBC_FULL_BUILD=ON
578592 -DCMAKE_BUILD_TYPE=Debug
579- STEP_TARGETS build install
580593 BUILD_COMMAND ${CMAKE_COMMAND} --build . --target libc-hdrgen
581594 INSTALL_COMMAND ${CMAKE_COMMAND} -E true
582- # Always run the build command so that incremental builds are correct.
583595 CONFIGURE_HANDLED_BY_BUILD TRUE
584596 )
585597 ExternalProject_Get_property(libc_hdrgen BINARY_DIR)
@@ -674,7 +686,7 @@ if(ENABLE_CXX_LIBS)
674686 -DLIBUNWIND_TEST_CONFIG=${CMAKE_CURRENT_SOURCE_DIR} /test -support/llvm-libunwind-picolibc.cfg.in
675687 -DLIBUNWIND_TEST_PARAMS=executor=${lit_test_executor}
676688 -DRUNTIME_TEST_ARCH_FLAGS=${compile_arch_flags}
677- -DRUNTIME_TEST_LINK_FLAGS=${link_flags }
689+ -DRUNTIME_TEST_LINK_FLAGS=${test_link_flags }
678690 -DLLVM_LIT_ARGS=${cxxlibs_lit_args}
679691 )
680692 endif ()
@@ -750,8 +762,11 @@ if(ENABLE_CXX_LIBS)
750762 CONFIGURE_HANDLED_BY_BUILD TRUE
751763 )
752764 add_custom_target (check-cxx)
765+ add_dependencies (check-all check-cxx)
753766 add_custom_target (check-cxxabi)
767+ add_dependencies (check-all check-cxxabi)
754768 add_custom_target (check-unwind)
769+ add_dependencies (check-all check-unwind)
755770 if (ENABLE_LIBCXX_TESTS)
756771 foreach (check_target check-cxx check-cxxabi check-unwind)
757772 ExternalProject_Add_Step(
@@ -772,9 +787,9 @@ if(ENABLE_CXX_LIBS)
772787 endforeach ()
773788 endif ()
774789
775- install (
776- DIRECTORY ${TEMP_LIB_DIR} /
777- DESTINATION .
778- )
779-
780790endif ()
791+
792+ install (
793+ DIRECTORY ${TEMP_LIB_DIR} /
794+ DESTINATION .
795+ )
0 commit comments