From a5f44ec92558e229cf6927b321f5f7903af8b412 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 18 Dec 2019 09:49:54 -0500 Subject: cmAddCustomCommandCommand: remove unnecessary braces --- Source/cmAddCustomCommandCommand.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 52fc5d5..995088c 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -261,9 +261,9 @@ bool cmAddCustomCommandCommand(std::vector const& args, case doing_target: target = copy; break; - case doing_depends: { + case doing_depends: depends.push_back(copy); - } break; + break; case doing_outputs: outputs.push_back(filename); break; -- cgit v0.12 From f5126badd8aadd307a2d38b215cb1dc2ff43647d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 18 Dec 2019 09:48:40 -0500 Subject: add_custom_command: convert DEPENDS path arguments to absolute paths This is only done if they are "obviously" paths in that they contain a directory separator. Fixes: #17111 --- Help/command/add_custom_command.rst | 8 +++++--- Help/release/dev/add_custom_command-depends-path.rst | 8 ++++++++ Source/cmCustomCommandGenerator.cxx | 4 ++++ Tests/CustomCommand/CMakeLists.txt | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Help/release/dev/add_custom_command-depends-path.rst diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst index aba3742..576ed5b 100644 --- a/Help/command/add_custom_command.rst +++ b/Help/command/add_custom_command.rst @@ -112,9 +112,11 @@ The options are: build time. ``DEPENDS`` - Specify files on which the command depends. If any dependency is - an ``OUTPUT`` of another custom command in the same directory - (``CMakeLists.txt`` file) CMake automatically brings the other + Specify files on which the command depends. Entries in the ``DEPENDS`` + argument list which may also be target names are assumed to be target names, + so only entries which contain a path separator are detected as file paths. + If any dependency is an ``OUTPUT`` of another custom command in the same + directory (``CMakeLists.txt`` file) CMake automatically brings the other custom command into the target in which this command is built. A target-level dependency is added if any dependency is listed as ``BYPRODUCTS`` of a target or any of its build events in the same diff --git a/Help/release/dev/add_custom_command-depends-path.rst b/Help/release/dev/add_custom_command-depends-path.rst new file mode 100644 index 0000000..69a805b --- /dev/null +++ b/Help/release/dev/add_custom_command-depends-path.rst @@ -0,0 +1,8 @@ +add_custom_command-depends-path +------------------------------- + +* The :command:`add_custom_command` command learned to detect paths in + ``DEPENDS`` arguments and convert them to paths relative to the current + binary directory. This only applies to paths which contain a ``/`` or ``\\`` + in them because names like ``filename.txt`` could also be target names and + cannot be coverted into absolute paths blindly. diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index bce27c2..c568253 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -8,6 +8,7 @@ #include +#include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmGeneratorExpression.h" @@ -29,6 +30,9 @@ void AppendPaths(const std::vector& inputs, cmExpandedList(cge->Evaluate(lg, config)); for (std::string& it : result) { cmSystemTools::ConvertToUnixSlashes(it); + if (cmContains(it, '/') && !cmSystemTools::FileIsFullPath(it)) { + it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it); + } if (cmSystemTools::FileIsFullPath(it)) { it = cmSystemTools::CollapseFullPath(it); } diff --git a/Tests/CustomCommand/CMakeLists.txt b/Tests/CustomCommand/CMakeLists.txt index e4b50d0..70e8476 100644 --- a/Tests/CustomCommand/CMakeLists.txt +++ b/Tests/CustomCommand/CMakeLists.txt @@ -534,3 +534,18 @@ add_custom_command( set_property(SOURCE "${gen_file}" PROPERTY SYMBOLIC ON) add_custom_target(command_expand_lists ALL DEPENDS "${gen_file}") set_property(TARGET command_expand_lists PROPERTY CMPARGS "${cmp_args}") + +set(depends_path "./depended_upon_path.txt") + +add_custom_command( + OUTPUT ${depends_path} + COMMAND ${CMAKE_COMMAND} -E touch ${depends_path} +) + +add_custom_command( + OUTPUT "depends_on_path.txt" + COMMAND ${CMAKE_COMMAND} -E touch "depends_on_path.txt" + DEPENDS ${depends_path} +) + +add_custom_target(depends_on_path ALL DEPENDS "depends_on_path.txt") -- cgit v0.12