[llvm] c0011f0 - [cmake] Add LLVM_UNITTEST_LINK_FLAGS option

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 00:19:41 PDT 2023


Author: Nikita Popov
Date: 2023-07-05T09:19:33+02:00
New Revision: c0011f027d68aa255359892abc5b110af9ebcccf

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

LOG: [cmake] Add LLVM_UNITTEST_LINK_FLAGS option

Add an option to specify additional linker flags for unit tests only.
For example, this allows using something like
-DLLVM_UNITTEST_LINK_FLAGS="-Wl,-plugin-opt=O0" if you're doing LTO
builds, or -DLLVM_UNITTEST_LINK_FLAGS="-fno-lto" if you're using
fat LTO objects.

The build system already does this itself if the LLVM_ENABLE_LTO
flag is used, but this does not cover all possible LTO configurations.

Differential Revision: https://reviews.llvm.org/D154212

Added: 
    

Modified: 
    llvm/cmake/modules/AddLLVM.cmake
    llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 926336e4a7aa86..230620c37027a1 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1610,6 +1610,8 @@ function(add_unittest test_suite test_name)
     endif()
   endif()
 
+  target_link_options(${test_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS}")
+
   set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
   set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
   # libpthreads overrides some standard library symbols, so main

diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index bc3af213603733..df487423bf2c12 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1317,6 +1317,9 @@ endif()
 set(LLVM_THIRD_PARTY_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/../third-party CACHE STRING
     "Directory containing third party software used by LLVM (e.g. googletest)")
 
+set(LLVM_UNITTEST_LINK_FLAGS "" CACHE STRING
+    "Additional linker flags for unit tests")
+
 if(LLVM_ENABLE_LLVM_LIBC)
   check_library_exists(llvmlibc printf "" HAVE_LLVM_LIBC)
   if(NOT HAVE_LLVM_LIBC)


        


More information about the llvm-commits mailing list