[lld] 2b2a961 - lld: Let find_package(LLD) work

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 07:00:06 PDT 2020


Author: Matt Arsenault
Date: 2020-05-14T09:59:53-04:00
New Revision: 2b2a961309e65fb175fcf8d56507323fa6872425

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

LOG: lld: Let find_package(LLD) work

Install a cmake config file. Copied exactly from how clang exports.

I also wasn't sure whether the canonical capitalization is "lld" or
"LLD". The project() is still calling this lld, but most places seemed
to capitalize it.

Added: 
    lld/cmake/modules/CMakeLists.txt
    lld/cmake/modules/LLDConfig.cmake.in

Modified: 
    lld/CMakeLists.txt
    lld/cmake/modules/AddLLD.cmake

Removed: 
    


################################################################################
diff  --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index 0cddb52889c8..5090c935e75a 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -226,3 +226,5 @@ add_subdirectory(ELF)
 add_subdirectory(MachO)
 add_subdirectory(MinGW)
 add_subdirectory(wasm)
+
+add_subdirectory(cmake/modules)

diff  --git a/lld/cmake/modules/AddLLD.cmake b/lld/cmake/modules/AddLLD.cmake
index fa48b428d26b..23df41312403 100644
--- a/lld/cmake/modules/AddLLD.cmake
+++ b/lld/cmake/modules/AddLLD.cmake
@@ -13,7 +13,7 @@ macro(add_lld_library name)
   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
     if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
         NOT LLVM_DISTRIBUTION_COMPONENTS)
-      set(export_to_lldtargets EXPORT lldTargets)
+      set(export_to_lldtargets EXPORT LLDTargets)
       set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True)
     endif()
 
@@ -48,7 +48,7 @@ macro(add_lld_tool name)
   if (LLD_BUILD_TOOLS)
     if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
         NOT LLVM_DISTRIBUTION_COMPONENTS)
-      set(export_to_lldtargets EXPORT lldTargets)
+      set(export_to_lldtargets EXPORT LLDTargets)
       set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True)
     endif()
 

diff  --git a/lld/cmake/modules/CMakeLists.txt b/lld/cmake/modules/CMakeLists.txt
new file mode 100644
index 000000000000..fa505a533762
--- /dev/null
+++ b/lld/cmake/modules/CMakeLists.txt
@@ -0,0 +1,71 @@
+# Generate a list of CMake library targets so that other CMake projects can
+# link against them. LLVM calls its version of this file LLVMExports.cmake, but
+# the usual CMake convention seems to be ${Project}Targets.cmake.
+set(LLD_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/lld)
+set(lld_cmake_builddir "${CMAKE_BINARY_DIR}/${LLD_INSTALL_PACKAGE_DIR}")
+
+# Keep this in sync with llvm/cmake/CMakeLists.txt!
+set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+
+get_property(LLD_EXPORTS GLOBAL PROPERTY LLD_EXPORTS)
+export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}/LLDTargets.cmake)
+
+# Generate LLDConfig.cmake for the build tree.
+set(LLD_CONFIG_CMAKE_DIR "${lld_cmake_builddir}")
+set(LLD_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
+set(LLD_CONFIG_EXPORTS_FILE "${lld_cmake_builddir}/LLDTargets.cmake")
+set(LLD_CONFIG_INCLUDE_DIRS
+  "${LLD_SOURCE_DIR}/include"
+  "${LLD_BINARY_DIR}/include"
+  )
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in
+  ${lld_cmake_builddir}/LLDConfig.cmake
+  @ONLY)
+set(LLD_CONFIG_CMAKE_DIR)
+set(LLD_CONFIG_LLVM_CMAKE_DIR)
+set(LLD_CONFIG_EXPORTS_FILE)
+
+# Generate LLDConfig.cmake for the install tree.
+set(LLD_CONFIG_CODE "
+# Compute the installation prefix from this LLVMConfig.cmake file location.
+get_filename_component(LLD_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
+# Construct the proper number of get_filename_component(... PATH)
+# calls to compute the installation prefix.
+string(REGEX REPLACE "/" ";" _count "${LLD_INSTALL_PACKAGE_DIR}")
+foreach(p ${_count})
+  set(LLD_CONFIG_CODE "${LLD_CONFIG_CODE}
+get_filename_component(LLD_INSTALL_PREFIX \"\${LLD_INSTALL_PREFIX}\" PATH)")
+endforeach(p)
+set(LLD_CONFIG_CMAKE_DIR "\${LLD_INSTALL_PREFIX}/${LLD_INSTALL_PACKAGE_DIR}")
+set(LLD_CONFIG_LLVM_CMAKE_DIR "\${LLD_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
+set(LLD_CONFIG_EXPORTS_FILE "\${LLD_CMAKE_DIR}/LLDTargets.cmake")
+set(LLD_CONFIG_INCLUDE_DIRS "\${LLD_INSTALL_PREFIX}/include")
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake
+  @ONLY)
+set(LLD_CONFIG_CODE)
+set(LLD_CONFIG_CMAKE_DIR)
+set(LLD_CONFIG_EXPORTS_FILE)
+
+if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+  get_property(lld_has_exports GLOBAL PROPERTY LLD_HAS_EXPORTS)
+  if(lld_has_exports)
+    install(EXPORT LLDTargets DESTINATION ${LLD_INSTALL_PACKAGE_DIR}
+            COMPONENT lld-cmake-exports)
+  endif()
+
+  install(FILES
+    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake
+    DESTINATION ${LLD_INSTALL_PACKAGE_DIR}
+    COMPONENT lld-cmake-exports)
+
+  if(NOT LLVM_ENABLE_IDE)
+    # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
+    add_custom_target(lld-cmake-exports)
+    add_llvm_install_targets(install-lld-cmake-exports
+                             COMPONENT lld-cmake-exports)
+  endif()
+endif()

diff  --git a/lld/cmake/modules/LLDConfig.cmake.in b/lld/cmake/modules/LLDConfig.cmake.in
new file mode 100644
index 000000000000..a09d272d1dca
--- /dev/null
+++ b/lld/cmake/modules/LLDConfig.cmake.in
@@ -0,0 +1,13 @@
+# This file allows users to call find_package(LLD) and pick up our targets.
+
+ at LLD_CONFIG_CODE@
+
+find_package(LLVM REQUIRED CONFIG
+             HINTS "@LLD_CONFIG_LLVM_CMAKE_DIR@")
+
+set(LLD_EXPORTED_TARGETS "@LLD_EXPORTS@")
+set(LLD_CMAKE_DIR "@LLD_CONFIG_CMAKE_DIR@")
+set(LLD_INCLUDE_DIRS "@LLD_CONFIG_INCLUDE_DIRS@")
+
+# Provide all our library targets to users.
+include("@LLD_CONFIG_EXPORTS_FILE@")


        


More information about the llvm-commits mailing list