Files
CMake/Tests/RunCMake/GenEx-PATH/NATIVE_PATH.cmake.in
Timothy Finnegan 427be46424 GenEx $<PATH>: Add NATIVE_PATH sub-command.
Implements the generator expression $<PATH:MATIVE_PATH> which convert
path(s) into a native format with platform-specific slashes (``\`` on
Windows hosts and ``/`` elsewhere).

Fixes: #26515
2024-12-14 11:16:47 +01:00

49 lines
1.5 KiB
CMake

include ("${RunCMake_SOURCE_DIR}/check_errors.cmake")
unset (errors)
cmake_path(SET test_path "/x/y/z/../../a/d")
cmake_path(NATIVE_PATH test_path reference)
set(output [=[$<PATH:NATIVE_PATH,/x/y/z/../../a/d>]=])
if (NOT output STREQUAL reference)
list (APPEND errors "'${output}' instead of '${reference}'")
endif()
cmake_path(SET test_path "/x/y/z/../../a/d")
cmake_path(NATIVE_PATH test_path NORMALIZE reference)
set(output [=[$<PATH:NATIVE_PATH,NORMALIZE,/x/y/z/../../a/d>]=])
if (NOT output STREQUAL reference)
list (APPEND errors "'${output}' instead of '${reference}'")
endif()
######################################
## tests with list of paths
######################################
unset(reference)
foreach(path IN ITEMS "/x/y/z/../../a/d" "/x/y/z/../../b/e")
cmake_path(SET test_path "${path}")
cmake_path(NATIVE_PATH test_path result)
list(APPEND reference "${result}")
endforeach()
set(output [=[$<PATH:NATIVE_PATH,/x/y/z/../../a/d;/x/y/z/../../b/e>]=])
if (NOT output STREQUAL reference)
list (APPEND errors "'${output}' instead of '${reference}'")
endif()
unset(reference)
foreach(path IN ITEMS "/x/y/z/../../a/d" "/x/y/z/../../b/e")
cmake_path(SET test_path "${path}")
cmake_path(NATIVE_PATH test_path NORMALIZE result)
list(APPEND reference "${result}")
endforeach()
set(output [=[$<PATH:NATIVE_PATH,NORMALIZE,/x/y/z/../../a/d;/x/y/z/../../b/e>]=])
if (NOT output STREQUAL reference)
list (APPEND errors "'${output}' instead of '${reference}'")
endif()
check_errors("PATH:NATIVE_PATH" ${errors})