summaryrefslogtreecommitdiff
path: root/flang/cmake
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-01-03 02:25:06 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-01-07 20:16:18 +0000
commit44e3365775101fec3fd355eda339282258d74415 (patch)
treeab8ebea8266a13bcb3115c3ef0ffcd4405de23e5 /flang/cmake
parentb99833dc745758042f230add35c75faf4070529f (diff)
downloadllvm-44e3365775101fec3fd355eda339282258d74415.tar.gz
[CMake] Factor out config prefix finding logic
See the docs in the new function for details. I think I found every instance of this copy pasted code. Polly could also use it, but currently does something different, so I will save the behavior change for a future revision. We get the shared, non-installed CMake modules following the pattern established in D116472. It might be good to have LLD and Flang also use this, but that would be a functional change and so I leave it as future work. Reviewed By: beanz, lebedev.ri Differential Revision: https://reviews.llvm.org/D116521
Diffstat (limited to 'flang/cmake')
-rw-r--r--flang/cmake/modules/CMakeLists.txt12
1 files changed, 2 insertions, 10 deletions
diff --git a/flang/cmake/modules/CMakeLists.txt b/flang/cmake/modules/CMakeLists.txt
index 06466c066674..170568c80dde 100644
--- a/flang/cmake/modules/CMakeLists.txt
+++ b/flang/cmake/modules/CMakeLists.txt
@@ -1,4 +1,5 @@
include(ExtendPath)
+include(FindPrefixFromConfig)
# 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,16 +30,7 @@ set(FLANG_CONFIG_CMAKE_DIR)
set(FLANG_CONFIG_LLVM_CMAKE_DIR)
# Generate FlangConfig.cmake for the install tree.
-set(FLANG_CONFIG_CODE "
- # Compute the installation prefix from this LLVMConfig.cmake file location.
- get_filename_component(FLANG_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 "${FLANG_INSTALL_PACKAGE_DIR}")
-foreach(p ${_count})
- set(FLANG_CONFIG_CODE "${FLANG_CONFIG_CODE}
- get_filename_component(FLANG_INSTALL_PREFIX \"\${FLANG_INSTALL_PREFIX}\" PATH)")
-endforeach(p)
+find_prefix_from_config(FLANG_CONFIG_CODE FLANG_INSTALL_PREFIX "${FLANG_INSTALL_PACKAGE_DIR}")
set(FLANG_CONFIG_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${FLANG_INSTALL_PACKAGE_DIR}")
set(FLANG_CONFIG_LLVM_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")