summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorMichal Gorny <mgorny@gentoo.org>2017-01-31 14:15:40 +0000
committerMichal Gorny <mgorny@gentoo.org>2017-01-31 14:15:40 +0000
commit53b77ccbdd1c2aa882960223d254150e4b60c942 (patch)
tree317f3148f0fb3864157bf94352310fa0d65eabfb /cmake
parentdde2f76999d72948383b2a89961589f68c03302b (diff)
[cmake] Hint find_package() to prefer LLVM installed alongside clang
Include a path hint for find_package() in ClangConfig.cmake to ensure that CMake prefers LLVM installed alongside clang over the default search path. If two versions of LLVM are installed in the system, and one of them is in PATH, CMake's find_package() magic prefers the CMake directory alongside that install by default. Adding a relative hint makes it possible to prioritize to the install from which find_package() is called. If you want to build e.g. LLDB against another install of LLVM, you can pass LLVM_CONFIG override. In this case, LLDB queries the prefix from llvm-config and uses the CMake files located there. However, when including ClangConfig, the implicit find_package() nevertheless prefers PATH-found LLVM over the one used previously by LLDB, and two versions of LLVMConfig end up being loaded. This could be fixed on LLDB end up by explicitly forcing custom package search location. However, it seems simpler and safer to add a hint to ClangConfig than to track every usage of ClangConfig. Differential Revision: https://reviews.llvm.org/D29304 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293632 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/CMakeLists.txt7
-rw-r--r--cmake/modules/ClangConfig.cmake.in5
2 files changed, 10 insertions, 2 deletions
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index b784c0d215..564205c460 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -4,17 +4,23 @@
set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_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(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
# Generate ClangConfig.cmake for the build tree.
set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
${clang_cmake_builddir}/ClangConfig.cmake
@ONLY)
set(CLANG_CONFIG_CMAKE_DIR)
+set(CLANG_CONFIG_LLVM_CMAKE_DIR)
set(CLANG_CONFIG_EXPORTS_FILE)
# Generate ClangConfig.cmake for the install tree.
@@ -29,6 +35,7 @@ foreach(p ${_count})
get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" PATH)")
endforeach(p)
set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
diff --git a/cmake/modules/ClangConfig.cmake.in b/cmake/modules/ClangConfig.cmake.in
index a946944dd9..b7a86cc568 100644
--- a/cmake/modules/ClangConfig.cmake.in
+++ b/cmake/modules/ClangConfig.cmake.in
@@ -1,9 +1,10 @@
# This file allows users to call find_package(Clang) and pick up our targets.
-find_package(LLVM REQUIRED CONFIG)
-
@CLANG_CONFIG_CODE@
+find_package(LLVM REQUIRED CONFIG
+ HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
+
set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")