From 43a2494058885d504d86a0b309281a6b1b1d4a65 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 4 Nov 2020 15:59:55 +1100 Subject: CMake: add path_ensure_trailing_slash utility macro --- build_files/cmake/macros.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'build_files') diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 8498c68c21c..ea348b06a07 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -60,6 +60,19 @@ function(list_assert_duplicates unset(_len_after) endfunction() +# Adds a native path separator to the end of the path: +# +# - 'example' -> 'example/' +# - '/example///' -> '/example/' +# +macro(path_ensure_trailing_slash + path_new path_input + ) + file(TO_NATIVE_PATH "/" _path_sep) + string(REGEX REPLACE "[${_path_sep}]+$" "" ${path_new} ${path_input}) + set(${path_new} "${${path_new}}${_path_sep}") + unset(_path_sep) +endmacro() # foo_bar.spam --> foo_barMySuffix.spam macro(file_suffix -- cgit v1.2.3