[PATCH] D81443: llvm: cmake: llvm_config: support INTERFACE_LIBRARY targets

Alexei Colin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 18:50:29 PDT 2020


acolin created this revision.
acolin added reviewers: LLVM, Bigcheese, axw, labath.
acolin added a project: LLVM.
Herald added subscribers: llvm-commits, dexonsmith, mgorny.

Currently, llvm_config(target) method cannot be used with a target of type INTERFACE_LIBRARY like so:

  add_library(Halide_LLVM INTERFACE)
  set(LLVM_USE_SHARED "USE_SHARED")
  llvm_config(Halide_LLVM ${LLVM_USE_SHARED} ${LLVM_COMPONENTS})

CMake throws an error:

      -- Using LLVMConfig.cmake in: /usr/lib/llvm/10/lib64/cmake/llvm
  CMake Error at /usr/lib/llvm/10/lib64/cmake/llvm/LLVM-Config.cmake:91 (target_link_libraries):
    INTERFACE library can only be used with the INTERFACE keyword of
    target_link_libraries
  Call Stack (most recent call first):
    dependencies/llvm/CMakeLists.txt:135 (llvm_config)

llvm_config() method seems to be the preferred way to link a library/app against libLLVM.so, as opposed to hardcoding the LLVM library name into a manual call to target_link_libraries(). But, can't use llvm_config() if the target happens to be of type INTERFACE_LIBRARY instead of SHARED_LIBRARY, for example.

This patch adds support for INTERFACE_LIBRARY target type to llvm_config().

This would be useful to Halide's cmake script (https://halide-lang.org).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81443

Files:
  llvm/cmake/modules/LLVM-Config.cmake


Index: llvm/cmake/modules/LLVM-Config.cmake
===================================================================
--- llvm/cmake/modules/LLVM-Config.cmake
+++ llvm/cmake/modules/LLVM-Config.cmake
@@ -87,7 +87,13 @@
       endif()
     endif()
 
-    target_link_libraries(${executable} PRIVATE LLVM)
+    get_target_property(t ${executable} TYPE)
+    if(t STREQUAL "INTERFACE_LIBRARY")
+      set(link_mode "INTERFACE")
+    else()
+      set(link_mode "PRIVATE")
+    endif()
+    target_link_libraries(${executable} ${link_mode} LLVM)
   endif()
 
   explicit_llvm_config(${executable} ${link_components})
@@ -99,7 +105,7 @@
 
   llvm_map_components_to_libnames(LIBRARIES ${link_components})
   get_target_property(t ${executable} TYPE)
-  if(t STREQUAL "STATIC_LIBRARY")
+  if(t STREQUAL "STATIC_LIBRARY" OR t STREQUAL "INTERFACE_LIBRARY")
     target_link_libraries(${executable} INTERFACE ${LIBRARIES})
   elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY")
     target_link_libraries(${executable} PRIVATE ${LIBRARIES})


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81443.269393.patch
Type: text/x-patch
Size: 1067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200609/6a1c836e/attachment.bin>


More information about the llvm-commits mailing list