From bde561c4813952847112600e5efe72d9015556f7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 14 Dec 2021 14:52:02 -0500 Subject: [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 --- cmake/Modules/ExtendPath.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cmake/Modules/ExtendPath.cmake (limited to 'cmake') 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() -- cgit v1.2.1