summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-11-23 15:09:20 (GMT)
committerBrad King <brad.king@kitware.com>2020-11-23 15:24:13 (GMT)
commit36921d2d231632768bba8dfb33f86fb92e695b43 (patch)
treeca605ac9f4f1a379803288a9dddbd87972b6bf4b
parent4549027a09756d7421651bc8312e4619707f076d (diff)
downloadCMake-36921d2d231632768bba8dfb33f86fb92e695b43.zip
CMake-36921d2d231632768bba8dfb33f86fb92e695b43.tar.gz
CMake-36921d2d231632768bba8dfb33f86fb92e695b43.tar.bz2
Xcode: Fix custom command work-dir placeholders in "new build system"
The placeholders for `CONFIGURATION` and `EFFECTIVE_PLATFORM_NAME` need to be handled in the `WORKING_DIRECTORY` of custom commands just as we already do for the `COMMAND`. Fixes: #21483
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx14
-rw-r--r--Tests/RunCMake/add_custom_command/PrintDir.cmake1
-rw-r--r--Tests/RunCMake/add_custom_command/RunCMakeTest.cmake15
-rw-r--r--Tests/RunCMake/add_custom_command/WorkingDirectory-build-multi-config-stdout.txt1
-rw-r--r--Tests/RunCMake/add_custom_command/WorkingDirectory-build-single-config-stdout.txt1
-rw-r--r--Tests/RunCMake/add_custom_command/WorkingDirectory.cmake9
6 files changed, 38 insertions, 3 deletions
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index b40d8ea..7ee94b2 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -1965,6 +1965,15 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateRunScriptBuildPhase(
return buildPhase;
}
+namespace {
+void ReplaceScriptVars(std::string& cmd)
+{
+ cmSystemTools::ReplaceString(cmd, "$(CONFIGURATION)", "$CONFIGURATION");
+ cmSystemTools::ReplaceString(cmd, "$(EFFECTIVE_PLATFORM_NAME)",
+ "$EFFECTIVE_PLATFORM_NAME");
+}
+}
+
std::string cmGlobalXCodeGenerator::ConstructScript(
cmCustomCommandGenerator const& ccg)
{
@@ -1975,6 +1984,7 @@ std::string cmGlobalXCodeGenerator::ConstructScript(
wd = lg->GetCurrentBinaryDirectory();
}
wd = lg->ConvertToOutputFormat(wd, cmOutputConverter::SHELL);
+ ReplaceScriptVars(wd);
script = cmStrCat(script, " cd ", wd, "\n");
for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
std::string cmd = ccg.GetCommand(c);
@@ -1984,9 +1994,7 @@ std::string cmGlobalXCodeGenerator::ConstructScript(
cmSystemTools::ReplaceString(cmd, "/./", "/");
cmd = lg->ConvertToOutputFormat(cmd, cmOutputConverter::SHELL);
ccg.AppendArguments(c, cmd);
- cmSystemTools::ReplaceString(cmd, "$(CONFIGURATION)", "$CONFIGURATION");
- cmSystemTools::ReplaceString(cmd, "$(EFFECTIVE_PLATFORM_NAME)",
- "$EFFECTIVE_PLATFORM_NAME");
+ ReplaceScriptVars(cmd);
script = cmStrCat(script, " ", cmd, '\n');
}
return script;
diff --git a/Tests/RunCMake/add_custom_command/PrintDir.cmake b/Tests/RunCMake/add_custom_command/PrintDir.cmake
new file mode 100644
index 0000000..0a7b646
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/PrintDir.cmake
@@ -0,0 +1 @@
+message(STATUS "WorkingDir='${CMAKE_CURRENT_BINARY_DIR}'")
diff --git a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
index 96642fa..aac085d 100644
--- a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
@@ -27,3 +27,18 @@ set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(AssigningMultipleTargets-build ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
+
+if(NOT RunCMake_GENERATOR STREQUAL "Ninja Multi-Config")
+ run_cmake(WorkingDirectory)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/WorkingDirectory-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake-stdout-file WorkingDirectory-build-multi-config-stdout.txt)
+ else()
+ set(RunCMake-stdout-file WorkingDirectory-build-single-config-stdout.txt)
+ endif()
+ run_cmake_command(WorkingDirectory-build ${CMAKE_COMMAND} --build . --config Debug)
+ unset(RunCMake-stdout-file)
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+endif()
diff --git a/Tests/RunCMake/add_custom_command/WorkingDirectory-build-multi-config-stdout.txt b/Tests/RunCMake/add_custom_command/WorkingDirectory-build-multi-config-stdout.txt
new file mode 100644
index 0000000..95ecf42
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/WorkingDirectory-build-multi-config-stdout.txt
@@ -0,0 +1 @@
+-- WorkingDir='[^']*/Tests/RunCMake/add_custom_command/WorkingDirectory-build/Debug'
diff --git a/Tests/RunCMake/add_custom_command/WorkingDirectory-build-single-config-stdout.txt b/Tests/RunCMake/add_custom_command/WorkingDirectory-build-single-config-stdout.txt
new file mode 100644
index 0000000..1db56ae
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/WorkingDirectory-build-single-config-stdout.txt
@@ -0,0 +1 @@
+-- WorkingDir='[^']*/Tests/RunCMake/add_custom_command/WorkingDirectory-build'
diff --git a/Tests/RunCMake/add_custom_command/WorkingDirectory.cmake b/Tests/RunCMake/add_custom_command/WorkingDirectory.cmake
new file mode 100644
index 0000000..65b7250
--- /dev/null
+++ b/Tests/RunCMake/add_custom_command/WorkingDirectory.cmake
@@ -0,0 +1,9 @@
+add_custom_target(mkdir COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
+add_custom_command(
+ OUTPUT out.txt
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/PrintDir.cmake
+ WORKING_DIRECTORY ${CMAKE_CFG_INTDIR}
+ )
+set_property(SOURCE out.txt PROPERTY SYMBOLIC 1)
+add_custom_target(drive ALL DEPENDS out.txt)
+add_dependencies(drive mkdir)