[PATCH] D154212: [cmake] Add LLVM_UNITTEST_LINK_FLAGS option

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 30 06:07:37 PDT 2023


nikic created this revision.
nikic added reviewers: mgorny, phosek, Ericson2314.
Herald added subscribers: ekilmer, StephenFan.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add an option to specify additional linker flags for unit tests only. For example, this allows doing 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. (E.g. we're using ld.bfd with LLVMgold.so, which isn't one of the supported configurations.)


https://reviews.llvm.org/D154212

Files:
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1610,6 +1610,11 @@
     endif()
   endif()
 
+  set(LLVM_UNITTEST_LINK_FLAGS "" CACHE STRING
+      "Additional linker flags for unit tests")
+  set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+               LINK_FLAGS " ${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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154212.536201.patch
Type: text/x-patch
Size: 658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230630/1b503112/attachment.bin>


More information about the llvm-commits mailing list