Skip to content

Commit fc0ee61

Browse files
committed
[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
1 parent f6b8f1c commit fc0ee61

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cmake/modules/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,26 @@ get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
88
export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
99

1010
# Generate ClangConfig.cmake for the build tree.
11+
set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
12+
set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
1113
configure_file(
1214
${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
1315
${clang_cmake_builddir}/ClangConfig.cmake
1416
@ONLY)
1517

1618
# Generate ClangConfig.cmake for the install tree.
19+
set(CLANG_CONFIG_CODE "
20+
# Compute the installation prefix from this LLVMConfig.cmake file location.
21+
get_filename_component(CLANG_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
22+
# Construct the proper number of get_filename_component(... PATH)
23+
# calls to compute the installation prefix.
24+
string(REGEX REPLACE "/" ";" _count "${CLANG_INSTALL_PACKAGE_DIR}")
25+
foreach(p ${_count})
26+
set(CLANG_CONFIG_CODE "${CLANG_CONFIG_CODE}
27+
get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" PATH)")
28+
endforeach(p)
29+
set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/\${CLANG_INSTALL_PACKAGE_DIR}")
30+
set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake")
1731
configure_file(
1832
${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
1933
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake

cmake/modules/ClangConfig.cmake.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66

77
find_package(LLVM REQUIRED CONFIG)
88

9+
@CLANG_CONFIG_CODE@
10+
11+
set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
12+
913
# Provide all our library targets to users.
10-
include("${CMAKE_CURRENT_LIST_DIR}/ClangTargets.cmake")
14+
include("@CLANG_CONFIG_EXPORTS_FILE@")

0 commit comments

Comments
 (0)