From af83a2add5687d0c2f70e538612b7e86ccbf47a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Sat, 2 Mar 2024 20:08:44 +0100 Subject: [PATCH] [lld] Fixes for unitests in standalone builds (#83670) 1. Replace the obsolete `llvm_add_unittests()` CMake function with an explicit check for `TARGET llvm_gtest`. This is more consistent with the rest of the code, and it makes it possible to avoid checking out `third-party` tree. 2. Add `LLDUnitTests` test dependency to standalone builds. It is defined unconditionally, and actually necessary to ensure that unit tests will be built. --- lld/CMakeLists.txt | 4 +++- lld/test/CMakeLists.txt | 3 +-- llvm/cmake/modules/AddLLVM.cmake | 10 ---------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt index 595c286abd91..cd8ba627306e 100644 --- a/lld/CMakeLists.txt +++ b/lld/CMakeLists.txt @@ -192,7 +192,9 @@ add_subdirectory(tools/lld) if (LLVM_INCLUDE_TESTS) add_custom_target(LLDUnitTests) - llvm_add_unittests(LLD_UNITTESTS_ADDED) + if (TARGET llvm_gtest) + add_subdirectory(unittests) + endif() add_subdirectory(test) endif() diff --git a/lld/test/CMakeLists.txt b/lld/test/CMakeLists.txt index 558da2b4421a..bb6164f19dce 100644 --- a/lld/test/CMakeLists.txt +++ b/lld/test/CMakeLists.txt @@ -38,11 +38,10 @@ configure_lit_site_cfg( "LLD_SOURCE_DIR" ) -set(LLD_TEST_DEPS lld) +set(LLD_TEST_DEPS lld LLDUnitTests) if (NOT LLD_BUILT_STANDALONE) list(APPEND LLD_TEST_DEPS FileCheck - LLDUnitTests count dsymutil llc diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 0f1734a64ee6..828de4bd9940 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -2509,13 +2509,3 @@ function(setup_host_tool tool_name setting_name exe_var_name target_var_name) add_custom_target(${target_var_name} DEPENDS ${exe_name}) endif() endfunction() - -# Adds the unittests folder if gtest is available. -function(llvm_add_unittests tests_added) - if (EXISTS ${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include/gtest/gtest.h) - add_subdirectory(unittests) - set(${tests_added} ON PARENT_SCOPE) - else() - message(WARNING "gtest not found, unittests will not be available") - endif() -endfunction()