@@ -233,7 +233,11 @@ function(create_libc_unittest fq_target_name)
233
233
_get_common_test_compile_options (compile_options "${LIBC_UNITTEST_C_TEST} "
234
234
"${LIBC_UNITTEST_FLAGS} " )
235
235
# TODO: Ideally we would have a separate function for link options.
236
- set (link_options ${compile_options} )
236
+ set (link_options
237
+ ${compile_options}
238
+ ${LIBC_LINK_OPTIONS_DEFAULT}
239
+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
240
+ )
237
241
list (APPEND compile_options ${LIBC_UNITTEST_COMPILE_OPTIONS} )
238
242
239
243
if (SHOW_INTERMEDIATE_OBJECTS )
@@ -580,12 +584,26 @@ function(add_integration_test test_name)
580
584
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
581
585
"--cuda-path=${LIBC_CUDA_ROOT} " )
582
586
elseif (LIBC_CC_SUPPORTS_NOSTDLIBPP )
583
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
587
+ set (link_options
588
+ -nolibc
589
+ -nostartfiles
590
+ -nostdlib++
591
+ -static
592
+ ${LIBC_LINK_OPTIONS_DEFAULT}
593
+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
594
+ )
595
+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
584
596
else ()
585
597
# Older version of gcc does not support `nostdlib++` flag. We use
586
598
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
587
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib )
588
- list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
599
+ set (link_options
600
+ -nolibc
601
+ -nostartfiles
602
+ -static
603
+ ${LIBC_LINK_OPTIONS_DEFAULT}
604
+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
605
+ )
606
+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
589
607
endif ()
590
608
target_link_libraries (
591
609
${fq_build_target_name}
@@ -774,11 +792,26 @@ function(add_libc_hermetic test_name)
774
792
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
775
793
"--cuda-path=${LIBC_CUDA_ROOT} " )
776
794
elseif (LIBC_CC_SUPPORTS_NOSTDLIBPP )
777
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static )
795
+ set (link_options
796
+ -nolibc
797
+ -nostartfiles
798
+ -nostdlib++
799
+ -static
800
+ ${LIBC_LINK_OPTIONS_DEFAULT}
801
+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
802
+ )
803
+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
778
804
else ()
779
805
# Older version of gcc does not support `nostdlib++` flag. We use
780
806
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
781
- target_link_options (${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib )
807
+ set (link_options
808
+ -nolibc
809
+ -nostartfiles
810
+ -static
811
+ ${LIBC_LINK_OPTIONS_DEFAULT}
812
+ ${LIBC_TEST_LINK_OPTIONS_DEFAULT}
813
+ )
814
+ target_link_options (${fq_build_target_name} PRIVATE ${link_options} )
782
815
list (APPEND link_libraries ${LIBGCC_S_LOCATION} )
783
816
endif ()
784
817
target_link_libraries (
@@ -809,9 +842,16 @@ function(add_libc_hermetic test_name)
809
842
endif ()
810
843
811
844
if (NOT HERMETIC_TEST_NO_RUN_POSTBUILD )
812
- set (test_cmd ${HERMETIC_TEST_ENV}
845
+ if (LIBC_TEST_CMD )
846
+ # In the form of "<command> binary=@BINARY@", e.g. "qemu-system-arm -loader$<COMMA>file=@BINARY@"
847
+ string (REPLACE "@BINARY@" "$<TARGET_FILE:${fq_build_target_name} >" test_cmd_parsed ${LIBC_TEST_CMD} )
848
+ string (REPLACE " " ";" test_cmd "${test_cmd_parsed} " )
849
+ else ()
850
+ set (test_cmd ${HERMETIC_TEST_ENV}
813
851
$< $< BOOL:${LIBC_TARGET_OS_IS_GPU} > :${gpu_loader_exe} > ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
814
852
$< TARGET_FILE:${fq_build_target_name} > ${HERMETIC_TEST_ARGS} )
853
+ endif ()
854
+
815
855
add_custom_target (
816
856
${fq_target_name}
817
857
DEPENDS ${fq_target_name} .__cmd__
@@ -863,7 +903,9 @@ function(add_libc_test test_name)
863
903
# Tests like the file tests perform file operations on disk file. If we
864
904
# don't chain up the unit test and hermetic test, then those tests will
865
905
# step on each other's files.
866
- add_dependencies (${fq_test_name} .__hermetic__ ${fq_test_name} .__unit__ )
906
+ if (NOT LIBC_TEST_HERMETIC_ONLY )
907
+ add_dependencies (${fq_test_name} .__hermetic__ ${fq_test_name} .__unit__ )
908
+ endif ()
867
909
endif ()
868
910
endif ()
869
911
endfunction (add_libc_test )
0 commit comments