diff options
author | Campbell Barton <campbell@blender.org> | 2022-11-03 08:39:58 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-11-03 08:57:38 +0300 |
commit | d5ce854fb1c70febf49ebc1242c48dd1ffa3a4aa (patch) | |
tree | 80ce83ba0f36978673043a9cdaccefc9d27f9687 /build_files | |
parent | 65e4d169baa95e5f2dfbd65e5b4e995851a857df (diff) |
CMake: workaround unsupported cmake_path(IS_PREFIX ..) in v3.20
Add a macro that implements something similar to cmake_path's IS_PREFIX
which isn't supported in older versions of CMake.
This caused the build-bot to fail.
Diffstat (limited to 'build_files')
-rw-r--r-- | build_files/cmake/macros.cmake | 19 | ||||
-rw-r--r-- | build_files/cmake/platform/platform_unix.cmake | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index d81767b4009..73883376060 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -57,6 +57,25 @@ macro(path_ensure_trailing_slash unset(_path_sep) endmacro() +# Our own version of `cmake_path(IS_PREFIX ..)`. +# This can be removed when 3.20 or greater is the minimum supported version. +macro(path_is_prefix + path_prefix path result_var + ) + # Remove when CMAKE version is bumped to "3.20" or greater. + # `cmake_path(IS_PREFIX ${path_prefix} ${path} NORMALIZE result_var)` + # Get the normalized paths (needed to remove `..`). + get_filename_component(_abs_prefix "${${path_prefix}}" ABSOLUTE) + get_filename_component(_abs_suffix "${${path}}" ABSOLUTE) + string(LENGTH "${_abs_prefix}" _len) + string(SUBSTRING "${_abs_suffix}" 0 "${_len}" _substr) + string(COMPARE EQUAL "${_abs_prefix}" "${_substr}" "${result_var}") + unset(_abs_prefix) + unset(_abs_suffix) + unset(_len) + unset(_substr) +endmacro() + # foo_bar.spam --> foo_barMySuffix.spam macro(file_suffix file_name_new file_name file_suffix diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake index 343ed6d8ef4..f1ce3221440 100644 --- a/build_files/cmake/platform/platform_unix.cmake +++ b/build_files/cmake/platform/platform_unix.cmake @@ -151,7 +151,7 @@ if(WITH_PYTHON) # Installing into `site-packages`, warn when installing into `./../lib/` # which script authors almost certainly don't want. if(EXISTS ${LIBDIR}) - cmake_path(IS_PREFIX LIBDIR "${PYTHON_SITE_PACKAGES}" NORMALIZE _is_prefix) + path_is_prefix(LIBDIR PYTHON_SITE_PACKAGES _is_prefix) if(_is_prefix) message(WARNING " Building Blender with the following configuration: |