summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-12-14 14:52:02 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-12-30 06:19:30 +0000
commitbde561c4813952847112600e5efe72d9015556f7 (patch)
treeb6e67b2e1f52ead4e40b2af593f8de97ce45fc7b /cmake
parent458db51c101bc3372e96b71bda7ca0f5ba2ae431 (diff)
downloadllvm-bde561c4813952847112600e5efe72d9015556f7.tar.gz
[compiler-rt][cmake] Factor out extend_install_path function
It is likely to become used again, if other projects want their own per-project install directory variables. `install` is removed from the name since it is not inherently about installing. Reviewed By: stephenneuendorffer Differential Revision: https://reviews.llvm.org/D115746
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/ExtendPath.cmake19
1 files changed, 19 insertions, 0 deletions
diff --git a/cmake/Modules/ExtendPath.cmake b/cmake/Modules/ExtendPath.cmake
new file mode 100644
index 000000000000..5db393a21e1c
--- /dev/null
+++ b/cmake/Modules/ExtendPath.cmake
@@ -0,0 +1,19 @@
+# Extend the path in `base_path` with the path in `current_segment`, returning
+# the result in `joined_path`. If `current_segment` is an absolute path then
+# just return it, in effect overriding `base_path`, and issue a warning.
+#
+# Note that the code returns a relative path (avoiding introducing leading
+# slashes) if `base_path` is empty.
+function(extend_path joined_path base_path current_segment)
+ if("${current_segment}" STREQUAL "")
+ set(temp_path "${base_path}")
+ elseif("${base_path}" STREQUAL "")
+ set(temp_path "${current_segment}")
+ elseif(IS_ABSOLUTE "${current_segment}")
+ message(WARNING "Since \"${current_segment}\" is absolute, it overrides install path: \"${base_path}\".")
+ set(temp_path "${current_segment}")
+ else()
+ set(temp_path "${base_path}/${current_segment}")
+ endif()
+ set(${joined_path} "${temp_path}" PARENT_SCOPE)
+endfunction()