[PATCH] D131878: [llvm] [cmake] Move LLVM_INSTALL_PACKAGE_DIR top-level to fix llvm-config

Michał Górny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 01:03:15 PDT 2022


mgorny created this revision.
mgorny added reviewers: Ericson2314, sebastian-ne, phosek, MaskRay, tstellar.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.
Herald added a project: LLVM.

Move the `LLVM_INSTALL_PACKAGE_DIR` declaration from llvm/cmake/modules
directory to the top-level llvm/CMakeLists.txt, in order to fix
the regression in `llvm-config --cmakedir` output for installed LLVM.
Since the tools directory is processed by CMake prior to
llvm/cmake/modules, the llvm-config executable ended up using
the variable prior to it being defined and incorrectly used an empty
path, resulting in e.g.:

  $ llvm-config --cmakedir
  /usr/lib/llvm/16/

With this patch, the path is defined (and therefore the default value
is being set) prior to adding the tools subdirectory and llvm-config
starts working correctly:

  $ llvm-config --cmakedir
  /usr/lib/llvm/16/lib64/cmake/llvm

This fixes a regression introduced by D130539 <https://reviews.llvm.org/D130539>.  Thanks to Petr Polezhaev
for reporting the problem @ https://bugs.gentoo.org/865165


https://reviews.llvm.org/D131878

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/CMakeLists.txt


Index: llvm/cmake/modules/CMakeLists.txt
===================================================================
--- llvm/cmake/modules/CMakeLists.txt
+++ llvm/cmake/modules/CMakeLists.txt
@@ -1,10 +1,7 @@
-include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
 
-set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
-  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
 
Index: llvm/CMakeLists.txt
===================================================================
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -339,6 +339,10 @@
 
 set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
 
+include(GNUInstallPackageDir)
+set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
+  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
+
 set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
     "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
 mark_as_advanced(LLVM_TOOLS_INSTALL_DIR)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131878.452598.patch
Type: text/x-patch
Size: 1294 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220815/0009689f/attachment.bin>


More information about the llvm-commits mailing list