Skip to content

Commit c4af46b

Browse files
committed
add_custom_command: Normalize OUTPUT and DEPENDS paths.
While tracing dependencies of a target, cmTargetTraceDependencies follows sources by full path to determine if the source is to be produced by a custom command. Commit 4959f34 (cmSourceFileLocation: Collapse full path for directory comparisons., 2014-03-27) changed the storage of target sources to be in the form of a normalized path instead of an unnormalized path. The path is followed by looking it up in a mapping via cmMakefile::GetSourceFileWithOutput to acquire an appropriate cmSourceFile. The mapping is populated with the OUTPUT components of add_custom_command invocations, however it is populated with unnormalized paths. This means that the tracing logic does not find appropriate cmSourceFiles, and does not generate appropriate build rules for the generated sources. Normalize the paths in the OUTPUT components of add_custom_command to resolve this. The paths in the DEPENDS component of add_custom_command are also not normalized, leading to the same problem again. Normalize the depends paths after generator evaluation and expansion.
1 parent 5e9441c commit c4af46b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Source/cmAddCustomCommandCommand.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
173173
break;
174174
}
175175

176+
if (cmSystemTools::FileIsFullPath(filename.c_str()))
177+
{
178+
filename = cmSystemTools::CollapseFullPath(filename);
179+
}
176180
switch (doing)
177181
{
178182
case doing_working_directory:

Source/cmCustomCommandGenerator.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,18 @@ std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const
103103
{
104104
cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
105105
= this->GE->Parse(*i);
106+
std::vector<std::string> result;
106107
cmSystemTools::ExpandListArgument(
107-
cge->Evaluate(this->Makefile, this->Config), this->Depends);
108+
cge->Evaluate(this->Makefile, this->Config), result);
109+
for (std::vector<std::string>::iterator it = result.begin();
110+
it != result.end(); ++it)
111+
{
112+
if (cmSystemTools::FileIsFullPath(it->c_str()))
113+
{
114+
*it = cmSystemTools::CollapseFullPath(*it);
115+
}
116+
}
117+
this->Depends.insert(this->Depends.end(), result.begin(), result.end());
108118
}
109119
}
110120
return this->Depends;

Tests/CustomCommand/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,30 @@ add_custom_target(source_in_custom_target SOURCES source_in_custom_target.cpp)
456456
set_property(SOURCE source_in_custom_target
457457
PROPERTY COMPILE_DEFINITIONS "TEST"
458458
)
459+
460+
set(gen_path "${CMAKE_CURRENT_BINARY_DIR}//./foo")
461+
set(gen_file "${gen_path}/foo.cxx")
462+
463+
add_custom_command(
464+
OUTPUT "${gen_file}"
465+
# Make sure the output directory exists before trying to write to it.
466+
COMMAND ${CMAKE_COMMAND} -E make_directory "${gen_path}"
467+
COMMAND ${CMAKE_COMMAND} -E touch "${gen_file}"
468+
)
469+
470+
add_library(NormOutput "${gen_file}")
471+
472+
set(gen_path "${gen_path}/bar")
473+
set(gen_file "${gen_path}/bar.cxx")
474+
475+
add_custom_command(
476+
OUTPUT "${gen_path}"
477+
COMMAND ${CMAKE_COMMAND} -E make_directory "${gen_path}"
478+
)
479+
480+
add_custom_command(
481+
OUTPUT "${gen_file}"
482+
DEPENDS "${gen_path}"
483+
COMMAND ${CMAKE_COMMAND} -E touch "${gen_file}")
484+
485+
add_library(NormDepends "${gen_file}")

0 commit comments

Comments
 (0)