diff options
author | Siva Chandra Reddy <sivachandra@google.com> | 2023-05-16 17:19:10 +0000 |
---|---|---|
committer | Siva Chandra Reddy <sivachandra@google.com> | 2023-05-17 21:13:50 +0000 |
commit | 4dc205f016e3dd2eb1182886a77676f24e39e329 (patch) | |
tree | 0bdb52a8263f8fd13d5d3f64ce2ca15359e9c0f4 /libc/cmake | |
parent | 42987dfa3a85e0cec987b9f07a8ffe61073ddc52 (diff) | |
download | llvm-4dc205f016e3dd2eb1182886a77676f24e39e329.tar.gz |
[libc] Add a convenience CMake function `add_unittest_framework_library`.
This function is used to add unit test and hermetic test framework libraries.
It avoids the duplicated code to add compile options to each every test
framework libraries.
Reviewed By: jhuber6
Differential Revision: https://reviews.llvm.org/D150727
Diffstat (limited to 'libc/cmake')
-rw-r--r-- | libc/cmake/modules/LLVMLibCTestRules.cmake | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake index 820c21f56d31..ab1f46cfd2dc 100644 --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -167,8 +167,15 @@ function(create_libc_unittest fq_target_name) CXX_STANDARD ${LIBC_UNITTEST_CXX_STANDARD} ) + set(link_libraries ${link_object_files}) # Test object files will depend on LINK_LIBRARIES passed down from `add_fp_unittest` - set(link_libraries ${link_object_files} ${LIBC_UNITTEST_LINK_LIBRARIES}) + foreach(lib IN LISTS LIBC_UNITTEST_LINK_LIBRARIES) + if(TARGET ${lib}.unit) + list(APPEND link_libraries ${lib}.unit) + else() + list(APPEND link_libraries ${lib}) + endif() + endforeach() set_target_properties(${fq_build_target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) @@ -179,7 +186,7 @@ function(create_libc_unittest fq_target_name) ) # LibcUnitTest should not depend on anything in LINK_LIBRARIES. - list(APPEND link_libraries LibcUnitTest) + list(APPEND link_libraries LibcDeathTestExecutors.unit LibcTest.unit) target_link_libraries(${fq_build_target_name} PRIVATE ${link_libraries}) @@ -659,6 +666,15 @@ function(add_libc_hermetic_test test_name) target_compile_options(${fq_build_target_name} PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} ${HERMETIC_TEST_COMPILE_OPTIONS}) + set(link_libraries "") + foreach(lib IN LISTS HERMETIC_TEST_LINK_LIBRARIES) + if(TARGET ${lib}.hermetic) + list(APPEND link_libraries ${lib}.hermetic) + else() + list(APPEND link_libraries ${lib}) + endif() + endforeach() + if(LIBC_TARGET_ARCHITECTURE_IS_GPU) target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static) else() @@ -667,13 +683,14 @@ function(add_libc_hermetic_test test_name) target_link_libraries( ${fq_build_target_name} PRIVATE - ${HERMETIC_TEST_LINK_LIBRARIES} libc.startup.${LIBC_TARGET_OS}.crt1 - LibcHermeticTest + ${link_libraries} + LibcTest.hermetic + LibcHermeticTestSupport.hermetic # The NVIDIA 'nvlink' linker does not currently support static libraries. $<$<NOT:$<BOOL:${LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX}>>:${fq_target_name}.__libc__>) add_dependencies(${fq_build_target_name} - LibcHermeticTest + LibcTest.hermetic ${fq_deps_list}) # Tests on the GPU require an external loader utility to launch the kernel. |