From ed21ad181e0c3fd9fc1a8094fc2f8b8daafefc6d Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Mon, 9 Nov 2020 16:16:07 +0100 Subject: cmake_path: various enhancements to subcommands/keywords This change address partly the remarks done in issue #21385 --- Help/command/cmake_path.rst | 132 +++++++++------------ Source/cmCMakePathCommand.cxx | 99 +++++++--------- ...D_STRING-OUTPUT_VARIABLE-invalid-arg-result.txt | 1 + ...APPEND_STRING-OUTPUT_VARIABLE-no-arg-result.txt | 1 + .../cmake_path/APPEND_STRING-wrong-path-result.txt | 1 + Tests/RunCMake/cmake_path/APPEND_STRING.cmake | 20 ++++ .../CMAKE_PATH-OUTPUT_VARIABLE-no-arg-result.txt | 1 - .../CMAKE_PATH-invalid-output-result.txt | 1 - .../CMAKE_PATH-missing-output-result.txt | 1 - .../CMAKE_PATH-unexpected-arg-result.txt | 1 - .../cmake_path/CMAKE_PATH-wrong-path-result.txt | 1 - Tests/RunCMake/cmake_path/CMAKE_PATH.cmake | 43 ------- .../cmake_path/COMPARE-EQUAL-wrong-path-result.txt | 1 - .../COMPARE-NOT_EQUAL-wrong-path-result.txt | 1 - Tests/RunCMake/cmake_path/COMPARE.cmake | 8 +- .../CONCAT-OUTPUT_VARIABLE-invalid-arg-result.txt | 1 - .../CONCAT-OUTPUT_VARIABLE-no-arg-result.txt | 1 - .../cmake_path/CONCAT-wrong-path-result.txt | 1 - Tests/RunCMake/cmake_path/CONCAT.cmake | 20 ---- Tests/RunCMake/cmake_path/PROXIMATE_PATH.cmake | 41 ------- Tests/RunCMake/cmake_path/RunCMakeTest.cmake | 30 ++--- .../cmake_path/SET-missing-output-result.txt | 1 + .../cmake_path/SET-unexpected-arg-result.txt | 1 + Tests/RunCMake/cmake_path/SET.cmake | 43 +++++++ 24 files changed, 186 insertions(+), 265 deletions(-) create mode 100644 Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-invalid-arg-result.txt create mode 100644 Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-no-arg-result.txt create mode 100644 Tests/RunCMake/cmake_path/APPEND_STRING-wrong-path-result.txt create mode 100644 Tests/RunCMake/cmake_path/APPEND_STRING.cmake delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH-OUTPUT_VARIABLE-no-arg-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH-invalid-output-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH-missing-output-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH-unexpected-arg-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH-wrong-path-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CMAKE_PATH.cmake delete mode 100644 Tests/RunCMake/cmake_path/COMPARE-EQUAL-wrong-path-result.txt delete mode 100644 Tests/RunCMake/cmake_path/COMPARE-NOT_EQUAL-wrong-path-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-invalid-arg-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-no-arg-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CONCAT-wrong-path-result.txt delete mode 100644 Tests/RunCMake/cmake_path/CONCAT.cmake delete mode 100644 Tests/RunCMake/cmake_path/PROXIMATE_PATH.cmake create mode 100644 Tests/RunCMake/cmake_path/SET-missing-output-result.txt create mode 100644 Tests/RunCMake/cmake_path/SET-unexpected-arg-result.txt create mode 100644 Tests/RunCMake/cmake_path/SET.cmake diff --git a/Help/command/cmake_path.rst b/Help/command/cmake_path.rst index cb84dd1..2d37ae0 100644 --- a/Help/command/cmake_path.rst +++ b/Help/command/cmake_path.rst @@ -1,7 +1,7 @@ cmake_path ---------- -.. versionadded:: 3.19 +.. versionadded:: 3.20 Filesystem path manipulation command. @@ -66,8 +66,8 @@ The following exceptions apply: in cross-compiling environment. For all commands, ```` placeholder expect a variable name. An error -will be raised if the variable does not exist, except for `APPEND`_ and -`CMAKE_PATH`_ sub-commands. ```` placeholder expect a string literal. +will be raised if the variable does not exist, except for `SET`_ and `APPEND`_ +sub-commands. ```` placeholder expect a string literal. ``[...]`` placeholder expect zero or more arguments. ```` placeholder expect a variable name. @@ -79,10 +79,10 @@ placeholder expect a variable name. To initialize a path variable, three possibilities can be used: 1. :command:`set` command. -2. :ref:`cmake_path(APPEND) ` command. Can be used to build a path from - already available path fragments. -3. :ref:`cmake_path(CMAKE_PATH) ` command. Mainly used to build a +2. :ref:`cmake_path(SET) ` command. Mainly used to build a path variable from a native path. +3. :ref:`cmake_path(APPEND) ` command. Can be used to build a path from + already available path fragments. .. code-block:: cmake @@ -90,13 +90,13 @@ To initialize a path variable, three possibilities can be used: set (path1 "${CMAKE_CURRENT_SOURCE_DIR}/data") - cmake_path(APPEND path2 "${CMAKE_CURRENT_SOURCE_DIR}" "data") + cmake_path(SET path2 "${CMAKE_CURRENT_SOURCE_DIR}/data") - cmake_path(CMAKE_PATH path3 "${CMAKE_CURRENT_SOURCE_DIR}/data") + cmake_path(APPEND path3 "${CMAKE_CURRENT_SOURCE_DIR}" "data") `Modification`_ and `Generation`_ sub-commands store the result in-place or in -the variable specified by ``OUTPUT_VARIABLE`` option. All other sub-commands, -except `CMAKE_PATH`_, store the result in the required ```` variable. +the variable specified by ``OUTPUT_VARIABLE`` option. All other sub-commands +store the result in the required ```` variable. Sub-commands supporting ``NORMALIZE`` option will :ref:`normalize ` the path. @@ -117,8 +117,9 @@ Synopsis cmake_path(`GET`_ :ref:`PARENT_PATH ` ) `Modification`_ + cmake_path(`SET`_ [NORMALIZE] ) cmake_path(`APPEND`_ [...] [OUTPUT_VARIABLE ]) - cmake_path(`CONCAT`_ [...] [OUTPUT_VARIABLE ]) + cmake_path(`APPEND_STRING`_ [...] [OUTPUT_VARIABLE ]) cmake_path(`REMOVE_FILENAME`_ [OUTPUT_VARIABLE ]) cmake_path(`REPLACE_FILENAME`_ [OUTPUT_VARIABLE ]) cmake_path(`REMOVE_EXTENSION`_ [LAST_ONLY] @@ -130,19 +131,16 @@ Synopsis cmake_path(`NORMAL_PATH`_ [OUTPUT_VARIABLE ]) cmake_path(`RELATIVE_PATH`_ [BASE_DIRECTORY ] [OUTPUT_VARIABLE ]) - cmake_path(`PROXIMATE_PATH`_ [BASE_DIRECTORY ] - [OUTPUT_VARIABLE ]) cmake_path(`ABSOLUTE_PATH`_ [BASE_DIRECTORY ] [NORMALIZE] [OUTPUT_VARIABLE ]) `Conversion`_ - cmake_path(`CMAKE_PATH`_ [NORMALIZE] ) cmake_path(`NATIVE_PATH`_ [NORMALIZE] ) cmake_path(`CONVERT`_ `TO_CMAKE_PATH_LIST`_ ) cmake_path(`CONVERT`_ `TO_NATIVE_PATH_LIST`_ ) `Comparison`_ - cmake_path(`COMPARE`_ ) + cmake_path(`COMPARE`_ ) `Query`_ cmake_path(`HAS_ROOT_NAME`_ ) @@ -388,6 +386,36 @@ For Example: Modification ^^^^^^^^^^^^ +.. _cmake_path-SET: +.. _SET: + +.. code-block:: cmake + + cmake_path(SET [NORMALIZE] ) + +Assign the ```` path to ````. Moreover, if ```` is a +native path, it is converted into cmake-style path with forward-slashes +(``/``). On Windows, the long filename marker is taken into account. + +When ``NORMALIZE`` option is specified, the path is :ref:`normalized +` before the conversion. + +For Example: + + .. code-block:: cmake + + set (native_path "c:\\a\\b/..\\c") + cmake_path (SET path "${native_path}") + message ("CMake path is \"${path}\"") + + cmake_path (SET path NORMALIZE "${native_path}") + message ("Normalized CMake path is \"${path}\"") + + Will display:: + + CMake path is "c:/a/b/../c" + Normalized CMake path is "c:/a/c" + .. _APPEND: .. code-block:: cmake @@ -419,13 +447,13 @@ For each ```` argument, the following algorithm (pseudo-code) applies: appends omitting any root-name to -.. _CONCAT: +.. _APPEND_STRING: .. code-block:: cmake - cmake_path(CONCAT [...] [OUTPUT_VARIABLE ]) + cmake_path(APPEND_STRING [...] [OUTPUT_VARIABLE ]) -Concatenates all the ```` arguments to the ```` without +Append all the ```` arguments to the ```` without ``directory-separator``. .. _REMOVE_FILENAME: @@ -500,7 +528,7 @@ Replaces the :ref:`extension ` with ````. (`HAS_EXTENSION`_ is true), it is removed. 2. A ``dot`` character is appended to ````, if ```` is not empty or does not begin with a ``dot`` character. - 3. ```` is appended as if `CONCAT`_ was used. + 3. ```` is appended as if `APPEND_STRING`_ was used. Equivalent to the following: @@ -509,9 +537,9 @@ Equivalent to the following: cmake_path(REMOVE_EXTENSION path) if (NOT "input" MATCHES "^\\.") - cmake_path(CONCAT path ".") + cmake_path(APPEND_STRING path ".") endif() - cmake_path(CONCAT path "input"); + cmake_path(APPEND_STRING path "input"); Generation ^^^^^^^^^^ @@ -557,19 +585,6 @@ Returns ```` made relative to ``BASE_DIRECTORY`` argument. If For reference, the algorithm used to compute the relative path is described `here `_. -.. _PROXIMATE_PATH: - -.. code-block:: cmake - - cmake_path(PROXIMATE_PATH [BASE_DIRECTORY ] - [OUTPUT_VARIABLE ]) - -If the value of `RELATIVE_PATH`_ is not an empty path, return -it. Otherwise return ````. - -If ``BASE_DIRECTORY`` is not specified, the default base directory will be -:variable:`CMAKE_CURRENT_SOURCE_DIR`. - .. _ABSOLUTE_PATH: .. code-block:: cmake @@ -593,35 +608,6 @@ command. Conversion ^^^^^^^^^^ -.. _cmake_path-CMAKE_PATH: -.. _CMAKE_PATH: - -.. code-block:: cmake - - cmake_path(CMAKE_PATH [NORMALIZE] ) - -Converts a native ```` path into cmake-style path with forward-slashes -(``/``). On Windows, the long filename marker is taken into account. - -When ``NORMALIZE`` option is specified, the path is :ref:`normalized -` before the conversion. - -For Example: - - .. code-block:: cmake - - set (native_path "c:\\a\\b/..\\c") - cmake_path (CMAKE_PATH path "${native_path}") - message ("CMake path is \"${path}\"") - - cmake_path (CMAKE_PATH path NORMALIZE "${native_path}") - message ("Normalized CMake path is \"${path}\"") - - Will display:: - - CMake path is "c:/a/b/../c" - Normalized CMake path is "c:/a/c" - .. _cmake_path-NATIVE_PATH: .. _NATIVE_PATH: @@ -644,9 +630,9 @@ When ``NORMALIZE`` option is specified, the path is :ref:`normalized cmake_path(CONVERT TO_CMAKE_PATH_LIST [NORMALIZE]) Converts a native ```` path into cmake-style path with forward-slashes -(``/``). On Windows, the long filename marker is taken into account. The input can -be a single path or a system search path like ``$ENV{PATH}``. A search path -will be converted to a cmake-style list separated by ``;`` characters. The +(``/``). On Windows, the long filename marker is taken into account. The input +can be a single path or a system search path like ``$ENV{PATH}``. A search +path will be converted to a cmake-style list separated by ``;`` characters. The result of the conversion is stored in the ```` variable. When ``NORMALIZE`` option is specified, the path is :ref:`normalized @@ -691,8 +677,8 @@ Comparison .. code-block:: cmake - cmake_path(COMPARE EQUAL ) - cmake_path(COMPARE NOT_EQUAL ) + cmake_path(COMPARE EQUAL ) + cmake_path(COMPARE NOT_EQUAL ) Compares the lexical representations of the path and another path. @@ -700,16 +686,14 @@ For testing equality, the following algorithm (pseudo-code) apply: .. code-block:: cmake - # is the contents of - - IF (NOT .root_name() STREQUAL .root_name()) + IF (NOT .root_name() STREQUAL .root_name()) returns FALSE - ELSEIF (.has_root_directory() XOR .has_root_directory()) + ELSEIF (.has_root_directory() XOR .has_root_directory()) returns FALSE ENDIF() - returns TRUE or FALSE if the relative portion of is - lexicographically equal or not to the relative portion of . + returns TRUE or FALSE if the relative portion of is + lexicographically equal or not to the relative portion of . Comparison is performed path component-wise Query diff --git a/Source/cmCMakePathCommand.cxx b/Source/cmCMakePathCommand.cxx index 720f582..85e7d9e 100644 --- a/Source/cmCMakePathCommand.cxx +++ b/Source/cmCMakePathCommand.cxx @@ -250,9 +250,48 @@ bool HandleGetCommand(std::vector const& args, return true; } +bool HandleSetCommand(std::vector const& args, + cmExecutionStatus& status) +{ + if (args.size() < 3 || args.size() > 4) { + status.SetError("SET must be called with two or three arguments."); + return false; + } + + if (args[1].empty()) { + status.SetError("Invalid name for path variable."); + return false; + } + + static NormalizeParser const parser; + + const auto arguments = parser.Parse(args); + + if (parser.GetInputs().size() != 1) { + status.SetError("SET called with unexpected arguments."); + return false; + } + + auto path = + cmCMakePath(parser.GetInputs().front(), cmCMakePath::native_format); + + if (arguments.Normalize) { + path = path.Normal(); + } + + status.GetMakefile().AddDefinition(args[1], path.GenericString()); + + return true; +} + bool HandleAppendCommand(std::vector const& args, cmExecutionStatus& status) { + if (args[1].empty()) { + status.SetError("Invalid name for path variable."); + return false; + } + static OutputVariableParser const parser{}; const auto arguments = parser.Parse(args); @@ -272,8 +311,8 @@ bool HandleAppendCommand(std::vector const& args, return true; } -bool HandleConcatCommand(std::vector const& args, - cmExecutionStatus& status) +bool HandleAppendStringCommand(std::vector const& args, + cmExecutionStatus& status) { static OutputVariableParser const parser{}; @@ -546,16 +585,6 @@ bool HandleRelativePathCommand(std::vector const& args, }); } -bool HandleProximatePathCommand(std::vector const& args, - cmExecutionStatus& status) -{ - return HandleTransformPathCommand( - args, status, - [](const cmCMakePath& path, const std::string& base) -> cmCMakePath { - return path.Proximate(base); - }); -} - bool HandleAbsolutePathCommand(std::vector const& args, cmExecutionStatus& status) { @@ -567,40 +596,6 @@ bool HandleAbsolutePathCommand(std::vector const& args, true); } -bool HandleCMakePathCommand(std::vector const& args, - cmExecutionStatus& status) -{ - if (args.size() < 3 || args.size() > 4) { - status.SetError("CMAKE_PATH must be called with two or three arguments."); - return false; - } - - static NormalizeParser const parser; - - const auto arguments = parser.Parse(args); - - if (parser.GetInputs().size() != 1) { - status.SetError("CMAKE_PATH called with unexpected arguments."); - return false; - } - - if (args[1].empty()) { - status.SetError("Invalid name for output variable."); - return false; - } - - auto path = - cmCMakePath(parser.GetInputs().front(), cmCMakePath::native_format); - - if (arguments.Normalize) { - path = path.Normal(); - } - - status.GetMakefile().AddDefinition(args[1], path.GenericString()); - - return true; -} - bool HandleNativePathCommand(std::vector const& args, cmExecutionStatus& status) { @@ -737,12 +732,7 @@ bool HandleCompareCommand(std::vector const& args, return false; } - std::string inputPath; - if (!getInputPath(args[1], status, inputPath)) { - return false; - } - - cmCMakePath path1(inputPath); + cmCMakePath path1(args[1]); cmCMakePath path2(args[3]); auto result = op->second(path1, path2); @@ -987,17 +977,16 @@ bool cmCMakePathCommand(std::vector const& args, static cmSubcommandTable const subcommand{ { "GET"_s, HandleGetCommand }, + { "SET"_s, HandleSetCommand }, { "APPEND"_s, HandleAppendCommand }, - { "CONCAT"_s, HandleConcatCommand }, + { "APPEND_STRING"_s, HandleAppendStringCommand }, { "REMOVE_FILENAME"_s, HandleRemoveFilenameCommand }, { "REPLACE_FILENAME"_s, HandleReplaceFilenameCommand }, { "REMOVE_EXTENSION"_s, HandleRemoveExtensionCommand }, { "REPLACE_EXTENSION"_s, HandleReplaceExtensionCommand }, { "NORMAL_PATH"_s, HandleNormalPathCommand }, { "RELATIVE_PATH"_s, HandleRelativePathCommand }, - { "PROXIMATE_PATH"_s, HandleProximatePathCommand }, { "ABSOLUTE_PATH"_s, HandleAbsolutePathCommand }, - { "CMAKE_PATH"_s, HandleCMakePathCommand }, { "NATIVE_PATH"_s, HandleNativePathCommand }, { "CONVERT"_s, HandleConvertCommand }, { "COMPARE"_s, HandleCompareCommand }, diff --git a/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-invalid-arg-result.txt b/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-invalid-arg-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-invalid-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-no-arg-result.txt b/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-no-arg-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/cmake_path/APPEND_STRING-OUTPUT_VARIABLE-no-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/cmake_path/APPEND_STRING-wrong-path-result.txt b/Tests/RunCMake/cmake_path/APPEND_STRING-wrong-path-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/cmake_path/APPEND_STRING-wrong-path-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/cmake_path/APPEND_STRING.cmake b/Tests/RunCMake/cmake_path/APPEND_STRING.cmake new file mode 100644 index 0000000..ea5f2dd --- /dev/null +++ b/Tests/RunCMake/cmake_path/APPEND_STRING.cmake @@ -0,0 +1,20 @@ + +include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") +unset (errors) + +set (path "/a/b") +cmake_path (APPEND_STRING path "cd") +if (NOT path STREQUAL "/a/bcd") + list (APPEND errors "'${path}' instead of 'a/bcd'") +endif() + +set (path "/a/b") +cmake_path (APPEND_STRING path "cd" "ef" OUTPUT_VARIABLE output) +if (NOT path STREQUAL "/a/b") + list (APPEND errors "input changed unexpectedly") +endif() +if (NOT output STREQUAL "/a/bcdef") + list (APPEND errors "'${output}' instead of 'a/bcdef'") +endif() + +check_errors (APPEND_STRING ${errors}) diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH-OUTPUT_VARIABLE-no-arg-result.txt b/Tests/RunCMake/cmake_path/CMAKE_PATH-OUTPUT_VARIABLE-no-arg-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH-OUTPUT_VARIABLE-no-arg-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH-invalid-output-result.txt b/Tests/RunCMake/cmake_path/CMAKE_PATH-invalid-output-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH-invalid-output-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH-missing-output-result.txt b/Tests/RunCMake/cmake_path/CMAKE_PATH-missing-output-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH-missing-output-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH-unexpected-arg-result.txt b/Tests/RunCMake/cmake_path/CMAKE_PATH-unexpected-arg-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH-unexpected-arg-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH-wrong-path-result.txt b/Tests/RunCMake/cmake_path/CMAKE_PATH-wrong-path-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH-wrong-path-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CMAKE_PATH.cmake b/Tests/RunCMake/cmake_path/CMAKE_PATH.cmake deleted file mode 100644 index b9320f3..0000000 --- a/Tests/RunCMake/cmake_path/CMAKE_PATH.cmake +++ /dev/null @@ -1,43 +0,0 @@ - -include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") -unset (errors) - -cmake_path(CMAKE_PATH path "/x/y/z/../../a/d") -if (NOT path STREQUAL "/x/y/z/../../a/d") - list (APPEND errors "'${path}' instead of '/x/y/z/../../a/d'") -endif() -cmake_path(CMAKE_PATH path NORMALIZE "/x/y/z/../../a/d") -if (NOT path STREQUAL "/x/a/d") - list (APPEND errors "'${path}' instead of '/x/a/d'") -endif() - -if (WIN32) - cmake_path(CMAKE_PATH path "/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "/x/y/z/../../a/d") - list (APPEND errors "'${path}' instead of '/x/y/z/../../a/d'") - endif() - cmake_path(CMAKE_PATH path NORMALIZE "/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "/x/a/d") - list (APPEND errors "'${path}' instead of '/x/a/d'") - endif() - - cmake_path(CMAKE_PATH path "//?/c:/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "c:/x/y/z/../../a/d") - list (APPEND errors "'${path}' instead of 'c:/x/y/z/../../a/d'") - endif() - cmake_path(CMAKE_PATH path NORMALIZE "//?/c:/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "c:/x/a/d") - list (APPEND errors "'${path}' instead of 'c:/x/a/d'") - endif() - - cmake_path(CMAKE_PATH path "\\\\?\\UNC/host/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "//host/x/y/z/../../a/d") - list (APPEND errors "'${path}' instead of '//host/x/y/z/../../a/d'") - endif() - cmake_path(CMAKE_PATH path NORMALIZE "\\\\?\\UNC\\host/x\\y/z\\..\\../a/d") - if (NOT path STREQUAL "//host/x/a/d") - list (APPEND errors "'${path}' instead of '//host/x/a/d'") - endif() -endif() - -check_errors (CMAKE_PATH ${errors}) diff --git a/Tests/RunCMake/cmake_path/COMPARE-EQUAL-wrong-path-result.txt b/Tests/RunCMake/cmake_path/COMPARE-EQUAL-wrong-path-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/COMPARE-EQUAL-wrong-path-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/COMPARE-NOT_EQUAL-wrong-path-result.txt b/Tests/RunCMake/cmake_path/COMPARE-NOT_EQUAL-wrong-path-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/COMPARE-NOT_EQUAL-wrong-path-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/COMPARE.cmake b/Tests/RunCMake/cmake_path/COMPARE.cmake index bc6b9b4..ecf7c82 100644 --- a/Tests/RunCMake/cmake_path/COMPARE.cmake +++ b/Tests/RunCMake/cmake_path/COMPARE.cmake @@ -2,19 +2,19 @@ include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") unset (errors) -set (path "a///b/c") -cmake_path(COMPARE path EQUAL "a/b/c" output) +set(path "a///b/c") +cmake_path(COMPARE "${path}" EQUAL "a/b/c" output) if (NOT output) list (APPEND errors "'${path}' not equal to 'a/b/c'") endif() set (path "a/b/d/../c") -cmake_path(COMPARE path NOT_EQUAL "a/b/c" output) +cmake_path(COMPARE "${path}" NOT_EQUAL "a/b/c" output) if (NOT output) list (APPEND errors "'${path}' equal to 'a/b/c'") endif() cmake_path(NORMAL_PATH path) -cmake_path(COMPARE path EQUAL "a/b/c" output) +cmake_path(COMPARE "${path}" EQUAL "a/b/c" output) if (NOT output) list (APPEND errors "'${path}' not equal to 'a/b/c'") endif() diff --git a/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-invalid-arg-result.txt b/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-invalid-arg-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-invalid-arg-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-no-arg-result.txt b/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-no-arg-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CONCAT-OUTPUT_VARIABLE-no-arg-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CONCAT-wrong-path-result.txt b/Tests/RunCMake/cmake_path/CONCAT-wrong-path-result.txt deleted file mode 100644 index d00491f..0000000 --- a/Tests/RunCMake/cmake_path/CONCAT-wrong-path-result.txt +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/Tests/RunCMake/cmake_path/CONCAT.cmake b/Tests/RunCMake/cmake_path/CONCAT.cmake deleted file mode 100644 index 62b5eb0..0000000 --- a/Tests/RunCMake/cmake_path/CONCAT.cmake +++ /dev/null @@ -1,20 +0,0 @@ - -include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") -unset (errors) - -set (path "/a/b") -cmake_path (CONCAT path "cd") -if (NOT path STREQUAL "/a/bcd") - list (APPEND errors "'${path}' instead of 'a/bcd'") -endif() - -set (path "/a/b") -cmake_path (CONCAT path "cd" "ef" OUTPUT_VARIABLE output) -if (NOT path STREQUAL "/a/b") - list (APPEND errors "input changed unexpectedly") -endif() -if (NOT output STREQUAL "/a/bcdef") - list (APPEND errors "'${output}' instead of 'a/bcdef'") -endif() - -check_errors (CONCAT ${errors}) diff --git a/Tests/RunCMake/cmake_path/PROXIMATE_PATH.cmake b/Tests/RunCMake/cmake_path/PROXIMATE_PATH.cmake deleted file mode 100644 index ad23377..0000000 --- a/Tests/RunCMake/cmake_path/PROXIMATE_PATH.cmake +++ /dev/null @@ -1,41 +0,0 @@ - -include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") -unset (errors) - -if (WIN32) - set (path "c:/a/d") - cmake_path(PROXIMATE_PATH path BASE_DIRECTORY "e/d/c") - if (NOT path STREQUAL "c:/a/d") - list (APPEND errors "'${path}' instead of 'c:/a/d'") - endif() -else() - set (path "/a/d") - cmake_path(PROXIMATE_PATH path BASE_DIRECTORY "e/d/c") - if (NOT path STREQUAL "/a/d") - list (APPEND errors "'${path}' instead of '/a/d'") - endif() -endif() - -set (path "/a/d") -cmake_path(PROXIMATE_PATH path BASE_DIRECTORY "/a/b/c" OUTPUT_VARIABLE output) -if (NOT path STREQUAL "/a/d") - list (APPEND errors "input changed unexpectedly") -endif() -if (NOT output STREQUAL "../../d") - list (APPEND errors "'${output}' instead of '../../d'") -endif() - -set (path "${CMAKE_CURRENT_SOURCE_DIR}/a/d") -cmake_path(PROXIMATE_PATH path) -if (NOT path STREQUAL "a/d") - list (APPEND errors "'${path}' instead of 'a/d'") -endif() - -set (path "a/b/c") -cmake_path(PROXIMATE_PATH path) -if (NOT path STREQUAL "a/b/c") - list (APPEND errors "'${path}' instead of 'a/b/c'") -endif() - - -check_errors (PROXIMATE_PATH ${errors}) diff --git a/Tests/RunCMake/cmake_path/RunCMakeTest.cmake b/Tests/RunCMake/cmake_path/RunCMakeTest.cmake index ca9cba6..4edfb1a 100644 --- a/Tests/RunCMake/cmake_path/RunCMakeTest.cmake +++ b/Tests/RunCMake/cmake_path/RunCMakeTest.cmake @@ -11,14 +11,9 @@ foreach (subcommand IN ITEMS ROOT_NAME ROOT_DIRECTORY ROOT_PATH FILENAME EXTENSI run_cmake_command (GET-${subcommand}-wrong-path "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=GET wrong_path ${subcommand} output" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() -### COMPARE sub-command -foreach (subcommand IN ITEMS EQUAL NOT_EQUAL) - run_cmake_command (COMPARE-${subcommand}-wrong-path "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=COMPARE wrong_path ${subcommand} path2 output" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") -endforeach() - -foreach (command IN ITEMS CONCAT REMOVE_FILENAME REPLACE_FILENAME +foreach (command IN ITEMS APPEND_STRING REMOVE_FILENAME REPLACE_FILENAME REMOVE_EXTENSION REPLACE_EXTENSION NORMAL_PATH - RELATIVE_PATH PROXIMATE_PATH ABSOLUTE_PATH) + RELATIVE_PATH ABSOLUTE_PATH) run_cmake_command (${command}-wrong-path "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=${command} wrong_path" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() @@ -55,7 +50,7 @@ foreach (subcommand IN ITEMS EQUAL NOT_EQUAL) run_cmake_command (COMPARE-${subcommand}-missing-output "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=COMPARE path ${subcommand} path2" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() -foreach (command IN ITEMS CMAKE_PATH NATIVE_PATH +foreach (command IN ITEMS SET NATIVE_PATH HAS_ROOT_NAME HAS_ROOT_DIRECTORY HAS_ROOT_PATH HAS_FILENAME HAS_EXTENSION HAS_STEM HAS_RELATIVE_PATH HAS_PARENT_PATH @@ -72,9 +67,9 @@ endforeach() ## OUTPUT_VARIABLE without argument set (RunCMake-stderr-file "OUTPUT_VARIABLE-no-arg-stderr.txt") -foreach (command IN ITEMS APPEND CONCAT REMOVE_FILENAME REPLACE_FILENAME +foreach (command IN ITEMS APPEND APPEND_STRING REMOVE_FILENAME REPLACE_FILENAME REMOVE_EXTENSION REPLACE_EXTENSION NORMAL_PATH - RELATIVE_PATH PROXIMATE_PATH ABSOLUTE_PATH) + RELATIVE_PATH ABSOLUTE_PATH) run_cmake_command (${command}-OUTPUT_VARIABLE-no-arg "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=${command} path OUTPUT_VARIABLE" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() @@ -98,7 +93,7 @@ foreach (subcommand IN ITEMS EQUAL NOT_EQUAL) run_cmake_command (COMPARE-${subcommand}-invalid-output "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=COMPARE path ${subcommand} path2" -DCHECK_INVALID_OUTPUT=ON -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() -foreach (command IN ITEMS CMAKE_PATH NATIVE_PATH +foreach (command IN ITEMS NATIVE_PATH HAS_ROOT_NAME HAS_ROOT_DIRECTORY HAS_ROOT_PATH HAS_FILENAME HAS_EXTENSION HAS_STEM HAS_RELATIVE_PATH HAS_PARENT_PATH @@ -111,9 +106,9 @@ foreach (command IN ITEMS CMAKE_PATH NATIVE_PATH run_cmake_command (${command}-invalid-output "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=${command} path ${extra_args}" -DCHECK_INVALID_OUTPUT=ON -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() -foreach (command IN ITEMS APPEND CONCAT REMOVE_FILENAME REPLACE_FILENAME +foreach (command IN ITEMS APPEND APPEND_STRING REMOVE_FILENAME REPLACE_FILENAME REMOVE_EXTENSION REPLACE_EXTENSION NORMAL_PATH - RELATIVE_PATH PROXIMATE_PATH ABSOLUTE_PATH) + RELATIVE_PATH ABSOLUTE_PATH) run_cmake_command (${command}-OUTPUT_VARIABLE-invalid-arg "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=${command} path OUTPUT_VARIABLE" -DCHECK_INVALID_OUTPUT=ON -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() @@ -139,7 +134,7 @@ endforeach() foreach (command IN ITEMS REMOVE_FILENAME REPLACE_FILENAME REMOVE_EXTENSION REPLACE_EXTENSION NORMAL_PATH - RELATIVE_PATH PROXIMATE_PATH ABSOLUTE_PATH) + RELATIVE_PATH ABSOLUTE_PATH) if (command STREQUAL "REPLACE_FILENAME" OR command STREQUAL "REPLACE_EXTENSION") set (extra_args input) else() @@ -148,7 +143,7 @@ foreach (command IN ITEMS REMOVE_FILENAME REPLACE_FILENAME run_cmake_command (${command}-unexpected-arg "${CMAKE_COMMAND}" "-DCMAKE_PATH_ARGUMENTS=${command} path ${extra_args} unexpected" -P "${RunCMake_SOURCE_DIR}/call-cmake_path.cmake") endforeach() -foreach (command IN ITEMS CMAKE_PATH NATIVE_PATH +foreach (command IN ITEMS SET NATIVE_PATH HAS_ROOT_NAME HAS_ROOT_DIRECTORY HAS_ROOT_PATH HAS_FILENAME HAS_EXTENSION HAS_STEM HAS_RELATIVE_PATH HAS_PARENT_PATH @@ -170,17 +165,16 @@ run_cmake(COMPARE-wrong-operator) set (RunCMake_TEST_OPTIONS "-DRunCMake_SOURCE_DIR=${RunCMake_SOURCE_DIR}") run_cmake(GET) +run_cmake(SET) run_cmake(APPEND) -run_cmake(CONCAT) +run_cmake(APPEND_STRING) run_cmake(REMOVE_FILENAME) run_cmake(REPLACE_FILENAME) run_cmake(REMOVE_EXTENSION) run_cmake(REPLACE_EXTENSION) run_cmake(NORMAL_PATH) run_cmake(RELATIVE_PATH) -run_cmake(PROXIMATE_PATH) run_cmake(ABSOLUTE_PATH) -run_cmake(CMAKE_PATH) run_cmake(NATIVE_PATH) run_cmake(CONVERT) run_cmake(COMPARE) diff --git a/Tests/RunCMake/cmake_path/SET-missing-output-result.txt b/Tests/RunCMake/cmake_path/SET-missing-output-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/cmake_path/SET-missing-output-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/cmake_path/SET-unexpected-arg-result.txt b/Tests/RunCMake/cmake_path/SET-unexpected-arg-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/cmake_path/SET-unexpected-arg-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/cmake_path/SET.cmake b/Tests/RunCMake/cmake_path/SET.cmake new file mode 100644 index 0000000..445783e --- /dev/null +++ b/Tests/RunCMake/cmake_path/SET.cmake @@ -0,0 +1,43 @@ + +include ("${RunCMake_SOURCE_DIR}/check_errors.cmake") +unset (errors) + +cmake_path(SET path "/x/y/z/../../a/d") +if (NOT path STREQUAL "/x/y/z/../../a/d") + list (APPEND errors "'${path}' instead of '/x/y/z/../../a/d'") +endif() +cmake_path(SET path NORMALIZE "/x/y/z/../../a/d") +if (NOT path STREQUAL "/x/a/d") + list (APPEND errors "'${path}' instead of '/x/a/d'") +endif() + +if (WIN32) + cmake_path(SET path "/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "/x/y/z/../../a/d") + list (APPEND errors "'${path}' instead of '/x/y/z/../../a/d'") + endif() + cmake_path(SET path NORMALIZE "/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "/x/a/d") + list (APPEND errors "'${path}' instead of '/x/a/d'") + endif() + + cmake_path(SET path "//?/c:/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "c:/x/y/z/../../a/d") + list (APPEND errors "'${path}' instead of 'c:/x/y/z/../../a/d'") + endif() + cmake_path(SET path NORMALIZE "//?/c:/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "c:/x/a/d") + list (APPEND errors "'${path}' instead of 'c:/x/a/d'") + endif() + + cmake_path(SET path "\\\\?\\UNC/host/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "//host/x/y/z/../../a/d") + list (APPEND errors "'${path}' instead of '//host/x/y/z/../../a/d'") + endif() + cmake_path(SET path NORMALIZE "\\\\?\\UNC\\host/x\\y/z\\..\\../a/d") + if (NOT path STREQUAL "//host/x/a/d") + list (APPEND errors "'${path}' instead of '//host/x/a/d'") + endif() +endif() + +check_errors (SET ${errors}) -- cgit v0.12