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: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c96c6f2988d..9f634af7143 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,7 +36,7 @@ set(TEST_PYTHON_EXE_EXTRA_ARGS) # Check if this a Blender managed Python installation, if so, don't add `*.pyc` files. if(LIBDIR) - cmake_path(IS_PREFIX LIBDIR "${TEST_PYTHON_EXE}" NORMALIZE _is_prefix) + path_is_prefix(LIBDIR TEST_PYTHON_EXE _is_prefix) if(_is_prefix) # Keep the Python in Blender's SVN LIBDIR pristine, to avoid conflicts on updating. set(TEST_PYTHON_EXE_EXTRA_ARGS "-B")