From 98d59417b0c6ac3ea85e315133337030dad93496 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Nov 2018 12:46:00 -0400 Subject: add_custom_{command,target}: Fix WORKING_DIRECTORY leading genex Since commit v3.13.0-rc1~39^2 (add_custom_{command,target}: WORKING_DIRECTORY generator expressions, 2018-09-22) the `WORKING_DIRECTORY` option accepts generator expressions. Fix support for the case of a leading generator expression by deferring conversion to an absolute path until after evaluation of the generator expression. Fixes: #18543 --- Source/cmAddCustomCommandCommand.cxx | 6 ------ Source/cmAddCustomTargetCommand.cxx | 7 ------- Source/cmCustomCommandGenerator.cxx | 6 ++++++ Tests/CustomCommandWorkingDirectory/CMakeLists.txt | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 91ccdf7..53f5593 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -318,12 +318,6 @@ bool cmAddCustomCommandCommand::InitialPass( return false; } - // Convert working directory to a full path. - if (!working.empty()) { - const std::string& build_dir = this->Makefile->GetCurrentBinaryDirectory(); - working = cmSystemTools::CollapseFullPath(working, build_dir); - } - // Choose which mode of the command to use. bool escapeOldStyle = !verbatim; if (source.empty() && output.empty()) { diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 82ee6b4..ddd9b70 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -181,13 +181,6 @@ bool cmAddCustomTargetCommand::InitialPass( } } - // Convert working directory to a full path. - if (!working_directory.empty()) { - const std::string& build_dir = this->Makefile->GetCurrentBinaryDirectory(); - working_directory = - cmSystemTools::CollapseFullPath(working_directory, build_dir); - } - if (commandLines.empty() && !byproducts.empty()) { this->Makefile->IssueMessage( cmake::FATAL_ERROR, diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 5bbae17..d1c1736 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -70,6 +70,12 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, std::unique_ptr cge = this->GE->Parse(workingdirectory); this->WorkingDirectory = cge->Evaluate(this->LG, this->Config); + // Convert working directory to a full path. + if (!this->WorkingDirectory.empty()) { + std::string const& build_dir = this->LG->GetCurrentBinaryDirectory(); + this->WorkingDirectory = + cmSystemTools::CollapseFullPath(this->WorkingDirectory, build_dir); + } } } diff --git a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt index 2e12a78..3bab1fe 100644 --- a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt +++ b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt @@ -47,7 +47,7 @@ file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/genex) add_custom_command( OUTPUT "${TestWorkingDir_BINARY_DIR}/genex/working.c" COMMAND "${CMAKE_COMMAND}" -E copy "${TestWorkingDir_SOURCE_DIR}/working.c.in" "${TestWorkingDir_BINARY_DIR}/genex/working.c" - WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/" + WORKING_DIRECTORY "$<0:not_used/>${TestWorkingDir_BINARY_DIR}/$<1:genex>/" COMMENT "custom command" ) @@ -58,7 +58,7 @@ add_custom_target( CustomGenex ALL COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TestWorkingDir_SOURCE_DIR}/customTarget.c" "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c" BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c" - WORKING_DIRECTORY "${TestWorkingDir_BINARY_DIR}/$<1:genex>/" + WORKING_DIRECTORY "$<0:not_used/>${TestWorkingDir_BINARY_DIR}/$<1:genex>/" ) add_dependencies(workinggenex CustomGenex) -- cgit v0.12