From fc0ee61d45c6e960d2e352ceab582512e06005a6 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Wed, 29 Jun 2016 21:59:19 +0000 Subject: [PATCH] [ClangConfig] Instead of hard coding the ClangTargets location to /ClangTargets.cmake, follow LLVM's example and use a pre-computed cmake variable @CLANG_CONFIG_EXPORTS_FILE@. This just makes ClangConfig more consistent with LLVMConfig. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274178 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/CMakeLists.txt | 14 ++++++++++++++ cmake/modules/ClangConfig.cmake.in | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 86ab001d2c..6b655b0796 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -8,12 +8,26 @@ 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_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in ${clang_cmake_builddir}/ClangConfig.cmake @ONLY) # Generate ClangConfig.cmake for the install tree. +set(CLANG_CONFIG_CODE " +# Compute the installation prefix from this LLVMConfig.cmake file location. +get_filename_component(CLANG_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 "${CLANG_INSTALL_PACKAGE_DIR}") +foreach(p ${_count}) + set(CLANG_CONFIG_CODE "${CLANG_CONFIG_CODE} +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_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake diff --git a/cmake/modules/ClangConfig.cmake.in b/cmake/modules/ClangConfig.cmake.in index d30a277d22..2095e5d282 100644 --- a/cmake/modules/ClangConfig.cmake.in +++ b/cmake/modules/ClangConfig.cmake.in @@ -6,5 +6,9 @@ find_package(LLVM REQUIRED CONFIG) +@CLANG_CONFIG_CODE@ + +set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@") + # Provide all our library targets to users. -include("${CMAKE_CURRENT_LIST_DIR}/ClangTargets.cmake") +include("@CLANG_CONFIG_EXPORTS_FILE@") -- 2.40.0