diff options
author | Tue Ly <lntue.h@gmail.com> | 2022-05-06 01:58:24 +0300 |
---|---|---|
committer | Tue Ly <lntue.h@gmail.com> | 2022-05-08 20:33:45 +0300 |
commit | 13f358376a597077e93e11653b51648d4976b181 (patch) | |
tree | 5bd451ea7432fda62c066d40c1783deb4867bcdc /libc | |
parent | 7e3aa70668aeb28e0d76c0d2807300eab337e0a7 (diff) |
[libc] Add LINK_LIBRARIES option to add_fp_unittest and add_libc_unittest.
This is needed to prepare for adding FLAGS option.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D125055
Diffstat (limited to 'libc')
-rw-r--r-- | libc/cmake/modules/LLVMLibCTestRules.cmake | 23 | ||||
-rw-r--r-- | libc/test/src/CMakeLists.txt | 17 | ||||
-rw-r--r-- | libc/test/src/__support/File/CMakeLists.txt | 6 | ||||
-rw-r--r-- | libc/test/src/math/exhaustive/CMakeLists.txt | 16 | ||||
-rw-r--r-- | libc/test/src/stdio/CMakeLists.txt | 8 | ||||
-rw-r--r-- | libc/test/src/stdio/printf_core/CMakeLists.txt | 4 | ||||
-rw-r--r-- | libc/test/src/string/CMakeLists.txt | 3 |
7 files changed, 35 insertions, 42 deletions
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index 4fe6834aecf7..3a1b9891e988 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -63,7 +63,7 @@ endfunction(get_object_files_for_test) # HDRS <list of .h files for the test> # DEPENDS <list of dependencies> # COMPILE_OPTIONS <list of special compile options for this target> -# LINK_OPTIONS <list of special linking options for this target> +# LINK_LIBRARIES <list of linking libraries for this target> # ) function(add_libc_unittest target_name) if(NOT LLVM_INCLUDE_TESTS) @@ -72,10 +72,9 @@ function(add_libc_unittest target_name) 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 @@ function(add_libc_unittest target_name) ) 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 @@ function(add_libc_unittest target_name) ${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 index cbab9d121e2c..49f7bc0774dc 100644 --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -3,7 +3,7 @@ function(add_fp_unittest name) "MATH_UNITTEST" "NEED_MPFR" # Optional arguments "" # Single value arguments - "" # Multi-value arguments + "LINK_LIBRARIES" # Multi-value arguments ${ARGN} ) @@ -14,15 +14,16 @@ function(add_fp_unittest name) 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 index 461a040911c8..de8df1c0429e 100644 --- a/libc/test/src/__support/File/CMakeLists.txt +++ b/libc/test/src/__support/File/CMakeLists.txt @@ -15,10 +15,8 @@ add_libc_unittest( 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 index 150c7d22e550..f985dab25bf8 100644 --- a/libc/test/src/math/exhaustive/CMakeLists.txt +++ b/libc/test/src/math/exhaustive/CMakeLists.txt @@ -60,7 +60,7 @@ add_fp_unittest( libc.include.math libc.src.math.expf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -77,7 +77,7 @@ add_fp_unittest( libc.include.math libc.src.math.exp2f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -95,7 +95,7 @@ add_fp_unittest( libc.src.math.expf libc.src.math.expm1f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -112,7 +112,7 @@ add_fp_unittest( libc.include.math libc.src.math.logf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -129,7 +129,7 @@ add_fp_unittest( libc.include.math libc.src.math.log10f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -146,7 +146,7 @@ add_fp_unittest( libc.include.math libc.src.math.log1pf libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -163,7 +163,7 @@ add_fp_unittest( libc.include.math libc.src.math.log2f libc.src.__support.FPUtil.fputil - LINK_OPTIONS + LINK_LIBRARIES -lpthread ) @@ -182,6 +182,6 @@ add_fp_unittest( 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 index d0df9f3502f3..538cb3f1624f 100644 --- a/libc/test/src/stdio/CMakeLists.txt +++ b/libc/test/src/stdio/CMakeLists.txt @@ -59,14 +59,10 @@ add_libc_unittest( 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 index 23e3133522c3..2998e1d22183 100644 --- a/libc/test/src/stdio/printf_core/CMakeLists.txt +++ b/libc/test/src/stdio/printf_core/CMakeLists.txt @@ -7,10 +7,10 @@ add_libc_unittest( 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 index 4152290f6b84..50e0f924a83e 100644 --- a/libc/test/src/string/CMakeLists.txt +++ b/libc/test/src/string/CMakeLists.txt @@ -259,10 +259,11 @@ function(add_libc_multi_impl_test name) ${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() |