[libc-commits] [libc] 13f3583 - [libc] Add LINK_LIBRARIES option to add_fp_unittest and add_libc_unittest.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Sun May 8 10:34:28 PDT 2022


Author: Tue Ly
Date: 2022-05-08T17:33:45Z
New Revision: 13f358376a597077e93e11653b51648d4976b181

URL: https://github.com/llvm/llvm-project/commit/13f358376a597077e93e11653b51648d4976b181
DIFF: https://github.com/llvm/llvm-project/commit/13f358376a597077e93e11653b51648d4976b181.diff

LOG: [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

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/test/src/CMakeLists.txt
    libc/test/src/__support/File/CMakeLists.txt
    libc/test/src/math/exhaustive/CMakeLists.txt
    libc/test/src/stdio/CMakeLists.txt
    libc/test/src/stdio/printf_core/CMakeLists.txt
    libc/test/src/string/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 4fe6834aecf73..3a1b9891e988b 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 cbab9d121e2c6..49f7bc0774dcf 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 461a040911c84..de8df1c0429e3 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 150c7d22e5503..f985dab25bf89 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 d0df9f3502f39..538cb3f1624f0 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 23e3133522c36..2998e1d221832 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 4152290f6b848..50e0f924a83ed 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()


        


More information about the libc-commits mailing list