[clang] RFC: [cmake] Export CLANG_RESOURCE_DIR in ClangConfig (PR #97197)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 30 02:06:43 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kim Gräsman (kimgr)

<details>
<summary>Changes</summary>

I recently opened #<!-- -->95747 to see if it would be advisable to expose `CLANG_RESOURCE_DIR` from `ClangConfig.cmake`.

Here's a patch to do the most naive thing I could think of, hopefully enough to trigger discussion.

Open questions/concerns:

* `ClangConfig.cmake` now defines `CLANG_RESOURCE_DIR` -- will that interfere with the CMake system's `CLANG_RESOURCE_DIR` (which is e.g. baked into config.h)
* The builddir vs. installdir distinction when generate `ClangConfig.cmake` isn't 100% clear to me, I guessed a little as to reasonable prefix paths


---
Full diff: https://github.com/llvm/llvm-project/pull/97197.diff


2 Files Affected:

- (modified) clang/cmake/modules/CMakeLists.txt (+9) 
- (modified) clang/cmake/modules/ClangConfig.cmake.in (+1) 


``````````diff
diff --git a/clang/cmake/modules/CMakeLists.txt b/clang/cmake/modules/CMakeLists.txt
index d2d68121371bf..4b0a38bd0fc1e 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -2,6 +2,7 @@ include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
+include(GetClangResourceDir)
 
 # 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
@@ -29,6 +30,10 @@ set(CLANG_CONFIG_INCLUDE_DIRS
   "${CLANG_SOURCE_DIR}/include"
   "${CLANG_BINARY_DIR}/include"
   )
+
+get_clang_resource_dir(resource_builddir PREFIX ${CLANG_BINARY_DIR})
+set(CLANG_CONFIG_RESOURCE_DIR ${resource_builddir})
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
@@ -60,6 +65,10 @@ extend_path(base_includedir "\${CLANG_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDED
 set(CLANG_CONFIG_INCLUDE_DIRS
   "${base_includedir}"
   )
+
+get_clang_resource_dir(resource_installdir PREFIX ${CLANG_INSTALL_PREFIX})
+set(CLANG_CONFIG_RESOURCE_DIR "${resource_installdir}")
+
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
diff --git a/clang/cmake/modules/ClangConfig.cmake.in b/clang/cmake/modules/ClangConfig.cmake.in
index 5f67681649c66..1b97e103c93ca 100644
--- a/clang/cmake/modules/ClangConfig.cmake.in
+++ b/clang/cmake/modules/ClangConfig.cmake.in
@@ -10,6 +10,7 @@ set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_INCLUDE_DIRS@")
 set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
+set(CLANG_RESOURCE_DIR "@CLANG_CONFIG_RESOURCE_DIR@")
 
 # Provide all our library targets to users.
 @CLANG_CONFIG_INCLUDE_EXPORTS@

``````````

</details>


https://github.com/llvm/llvm-project/pull/97197


More information about the cfe-commits mailing list