Merge topic 'custom-command-slashes'

88548a4 Handle relative WORKING_DIRECTORY in add_custom_(command|target)
7befc00 Handle trailing slashes on add_custom_command DEPENDS
This commit is contained in:
Brad King 2011-02-22 14:31:12 -05:00 committed by CMake Topic Stage
commit 542f45f452
6 changed files with 39 additions and 2 deletions

View File

@ -286,6 +286,13 @@ bool cmAddCustomCommandCommand
return false; return false;
} }
// Convert working directory to a full path.
if(!working.empty())
{
const char* build_dir = this->Makefile->GetCurrentOutputDirectory();
working = cmSystemTools::CollapseFullPath(working.c_str(), build_dir);
}
// Choose which mode of the command to use. // Choose which mode of the command to use.
bool escapeOldStyle = !verbatim; bool escapeOldStyle = !verbatim;
if(source.empty() && output.empty()) if(source.empty() && output.empty())

View File

@ -110,6 +110,8 @@ public:
"will be treated as PRE_LINK.\n" "will be treated as PRE_LINK.\n"
"If WORKING_DIRECTORY is specified the command will be executed " "If WORKING_DIRECTORY is specified the command will be executed "
"in the directory given. " "in the directory given. "
"If it is a relative path it will be interpreted relative to the "
"build tree directory corresponding to the current source directory. "
"If COMMENT is set, the value will be displayed as a " "If COMMENT is set, the value will be displayed as a "
"message before the commands are executed at build time. " "message before the commands are executed at build time. "
"If APPEND is specified the COMMAND and DEPENDS option values " "If APPEND is specified the COMMAND and DEPENDS option values "

View File

@ -166,6 +166,14 @@ bool cmAddCustomTargetCommand
} }
} }
// Convert working directory to a full path.
if(!working_directory.empty())
{
const char* build_dir = this->Makefile->GetCurrentOutputDirectory();
working_directory =
cmSystemTools::CollapseFullPath(working_directory.c_str(), build_dir);
}
// Add the utility target to the makefile. // Add the utility target to the makefile.
bool escapeOldStyle = !verbatim; bool escapeOldStyle = !verbatim;
cmTarget* target = cmTarget* target =

View File

@ -79,6 +79,8 @@ public:
"empty target will be created. " "empty target will be created. "
"If WORKING_DIRECTORY is set, then the command will be run in that " "If WORKING_DIRECTORY is set, then the command will be run in that "
"directory. " "directory. "
"If it is a relative path it will be interpreted relative to the "
"build tree directory corresponding to the current source directory. "
"If COMMENT is set, the value will be displayed as a " "If COMMENT is set, the value will be displayed as a "
"message before the commands are executed at build time. " "message before the commands are executed at build time. "
"Dependencies listed with the DEPENDS argument may reference files " "Dependencies listed with the DEPENDS argument may reference files "

View File

@ -1893,6 +1893,7 @@ bool cmLocalGenerator::GetRealDependency(const char* inName,
{ {
// This is a full path. Return it as given. // This is a full path. Return it as given.
dep = inName; dep = inName;
cmSystemTools::ConvertToUnixSlashes(dep);
return true; return true;
} }

View File

@ -9,8 +9,8 @@ ADD_CUSTOM_COMMAND(
) )
SET_SOURCE_FILES_PROPERTIES( SET_SOURCE_FILES_PROPERTIES(
"${TestWorkingDir_BINARY_DIR}/working.c"
"${TestWorkingDir_BINARY_DIR}/customTarget.c" "${TestWorkingDir_BINARY_DIR}/customTarget.c"
"${TestWorkingDir_BINARY_DIR}/customTarget2.c"
PROPERTIES GENERATED 1) PROPERTIES GENERATED 1)
ADD_EXECUTABLE(working "${TestWorkingDir_BINARY_DIR}/working.c" ADD_EXECUTABLE(working "${TestWorkingDir_BINARY_DIR}/working.c"
@ -23,3 +23,20 @@ ADD_CUSTOM_TARGET(
) )
ADD_DEPENDENCIES(working Custom) ADD_DEPENDENCIES(working Custom)
file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/work)
add_custom_command(
OUTPUT working2.c # Relative to build tree
COMMAND "${CMAKE_COMMAND}" -E copy ${TestWorkingDir_SOURCE_DIR}/working.c.in ../working2.c
DEPENDS ${TestWorkingDir_SOURCE_DIR}/working.c.in/ # trailing slash should be removed
WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
)
add_executable(working2 working2.c ${TestWorkingDir_BINARY_DIR}/customTarget2.c)
add_custom_target(
Custom2 ALL
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${TestWorkingDir_SOURCE_DIR}/customTarget.c ../customTarget2.c
WORKING_DIRECTORY work/ # Relative to build tree, trailing slash
)
add_dependencies(working2 Custom2)