diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -63,7 +63,7 @@ # HDRS # DEPENDS # COMPILE_OPTIONS -# LINK_OPTIONS +# LINK_LIBRARIES # ) function(add_libc_unittest target_name) if(NOT LLVM_INCLUDE_TESTS) @@ -72,10 +72,9 @@ cmake_parse_arguments( "LIBC_UNITTEST" - "NO_RUN_POSTBUILD" # Optional arguments + "NO_RUN_POSTBUILD;NO_LIBC_UNITTEST_TEST_MAIN" # Optional arguments "SUITE;CXX_STANDARD" # Single value arguments - "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_OPTIONS" # Multi-value arguments - "NO_LIBC_UNITTEST_TEST_MAIN" + "SRCS;HDRS;DEPENDS;COMPILE_OPTIONS;LINK_LIBRARIES" # Multi-value arguments ${ARGN} ) if(NOT LIBC_UNITTEST_SRCS) @@ -147,13 +146,8 @@ ) endif() - target_link_libraries(${fq_target_name} PRIVATE ${link_object_files}) - if(LIBC_UNITTEST_LINK_OPTIONS) - target_link_options( - ${fq_target_name} - PRIVATE ${LIBC_UNITTEST_LINK_OPTIONS} - ) - endif() + # Test object files will depend on LINK_LIBRARIES passed down from `add_fp_unittest` + list(PREPEND LIBC_UNITTEST_LINK_LIBRARIES ${link_object_files}) set_target_properties(${fq_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) @@ -163,12 +157,15 @@ ${fq_deps_list} ) + # LibcUnitTest and libc_test_utils should not depend on anything in LINK_LIBRARIES. if(NO_LIBC_UNITTEST_TEST_MAIN) - target_link_libraries(${fq_target_name} PRIVATE LibcUnitTest libc_test_utils) + list(APPEND LIBC_UNITTEST_LINK_LIBRARIES LibcUnitTest libc_test_utils) else() - target_link_libraries(${fq_target_name} PRIVATE LibcUnitTest LibcUnitTestMain libc_test_utils) + list(APPEND LIBC_UNITTEST_LINK_LIBRARIES LibcUnitTest LibcUnitTestMain libc_test_utils) endif() + target_link_libraries(${fq_target_name} PRIVATE ${LIBC_UNITTEST_LINK_LIBRARIES}) + if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD) add_custom_command( TARGET ${fq_target_name} diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -3,7 +3,7 @@ "MATH_UNITTEST" "NEED_MPFR" # Optional arguments "" # Single value arguments - "" # Multi-value arguments + "LINK_LIBRARIES" # Multi-value arguments ${ARGN} ) @@ -14,15 +14,16 @@ endif() endif() - add_libc_unittest(${name} ${MATH_UNITTEST_UNPARSED_ARGUMENTS}) - get_fq_target_name(${name} fq_target_name) - if (NOT TARGET ${fq_target_name}) - return() - endif() if(MATH_UNITTEST_NEED_MPFR) - target_link_libraries(${fq_target_name} PRIVATE libcMPFRWrapper -lmpfr -lgmp) + list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper -lmpfr -lgmp) endif() - target_link_libraries(${fq_target_name} PRIVATE LibcFPTestHelpers) + list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers) + + add_libc_unittest( + ${name} + "${MATH_UNITTEST_UNPARSED_ARGUMENTS}" + LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}" + ) endfunction(add_fp_unittest) add_subdirectory(__support) diff --git a/libc/test/src/__support/File/CMakeLists.txt b/libc/test/src/__support/File/CMakeLists.txt --- a/libc/test/src/__support/File/CMakeLists.txt +++ b/libc/test/src/__support/File/CMakeLists.txt @@ -15,10 +15,8 @@ libc.include.stdio libc.include.stdlib libc.src.__support.File.file -) - -target_link_libraries( - libc.test.src.__support.File.file_test PRIVATE LibcMemoryHelpers + LINK_LIBRARIES + LibcMemoryHelpers ) if (TARGET libc.src.__support.File.platform_file) diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt --- a/libc/test/src/math/exhaustive/CMakeLists.txt +++ b/libc/test/src/math/exhaustive/CMakeLists.txt @@ -60,7 +60,7 @@ libc.include.math libc.src.math.expf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -77,7 +77,7 @@ libc.include.math libc.src.math.exp2f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -95,7 +95,7 @@ libc.src.math.expf libc.src.math.expm1f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -112,7 +112,7 @@ libc.include.math libc.src.math.logf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -129,7 +129,7 @@ libc.include.math libc.src.math.log10f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -146,7 +146,7 @@ libc.include.math libc.src.math.log1pf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -163,7 +163,7 @@ libc.include.math libc.src.math.log2f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -182,6 +182,6 @@ libc.src.__support.FPUtil.fputil COMPILE_OPTIONS -O3 - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt --- a/libc/test/src/stdio/CMakeLists.txt +++ b/libc/test/src/stdio/CMakeLists.txt @@ -59,14 +59,10 @@ libc.src.stdio.fread libc.src.stdio.fseek libc.src.stdio.fwrite + LINK_LIBRARIES + LibcMemoryHelpers ) -if(TARGET libc.test.src.stdio.fopencookie_test) - target_link_libraries( - libc.test.src.stdio.fopencookie_test PRIVATE LibcMemoryHelpers - ) -endif() - add_subdirectory(printf_core) add_subdirectory(testdata) diff --git a/libc/test/src/stdio/printf_core/CMakeLists.txt b/libc/test/src/stdio/printf_core/CMakeLists.txt --- a/libc/test/src/stdio/printf_core/CMakeLists.txt +++ b/libc/test/src/stdio/printf_core/CMakeLists.txt @@ -7,10 +7,10 @@ DEPENDS libc.src.stdio.printf_core.parser libc.src.__support.arg_list + LINK_LIBRARIES + LibcPrintfHelpers ) -target_link_libraries(libc.test.src.stdio.printf_core.parser_test PRIVATE LibcPrintfHelpers) - add_libc_unittest( string_writer_test SUITE diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt --- a/libc/test/src/string/CMakeLists.txt +++ b/libc/test/src/string/CMakeLists.txt @@ -259,10 +259,11 @@ ${fq_config_name} COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE} + LINK_LIBRARIES + LibcMemoryHelpers ${ARGN} ) get_fq_target_name(${fq_config_name}_test fq_target_name) - target_link_libraries(${fq_target_name} PRIVATE LibcMemoryHelpers) else() message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'") endif()