From 92c4c852db821bc75ef0a20db4855e3af57ef80d Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Mon, 18 Nov 2019 22:01:04 +0100 Subject: Xcode: Add custom working directory property Closes: #19967 --- Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst | 13 ++++++++++ Help/release/dev/xcode-scheme-workdir.rst | 7 ++++++ .../CMAKE_XCODE_SCHEME_WORKING_DIRECTORY.rst | 12 ++++++++++ Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmTarget.cxx | 1 + Source/cmXCodeScheme.cxx | 28 ++++++++++++++++++---- Source/cmXCodeScheme.h | 6 ++++- .../XcodeProject/XcodeSchemaProperty-check.cmake | 1 + .../XcodeProject/XcodeSchemaProperty.cmake | 1 + 11 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst create mode 100644 Help/release/dev/xcode-scheme-workdir.rst create mode 100644 Help/variable/CMAKE_XCODE_SCHEME_WORKING_DIRECTORY.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 94d08c6..c5ef09a 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -381,6 +381,7 @@ Properties on Targets /prop_tgt/XCODE_SCHEME_ADDRESS_SANITIZER /prop_tgt/XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN /prop_tgt/XCODE_SCHEME_ARGUMENTS + /prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY /prop_tgt/XCODE_SCHEME_DEBUG_AS_ROOT /prop_tgt/XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING /prop_tgt/XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 01dd5fd..0c1d510 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -239,6 +239,7 @@ Variables that Change Behavior /variable/CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY /variable/CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER /variable/CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN + /variable/CMAKE_XCODE_SCHEME_WORKING_DIRECTORY /variable/CMAKE_XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING /variable/CMAKE_XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER /variable/CMAKE_XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS diff --git a/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst b/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst new file mode 100644 index 0000000..7ffa74b --- /dev/null +++ b/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst @@ -0,0 +1,13 @@ +XCODE_SCHEME_WORKING_DIRECTORY +------------------------------ + +Specify the ``Working Directory`` a of the `Run` and `Profile` +action in the generated Xcode scheme. In case the value contains +generator expressions those are evaluated. + +This property is initialized by the value of the variable +:variable:`CMAKE_XCODE_SCHEME_WORKING_DIRECTORY` if it is set +when a target is created. + +Please refer to the :prop_tgt:`XCODE_GENERATE_SCHEME` target property +documentation to see all Xcode schema related properties. diff --git a/Help/release/dev/xcode-scheme-workdir.rst b/Help/release/dev/xcode-scheme-workdir.rst new file mode 100644 index 0000000..8eb5ed8 --- /dev/null +++ b/Help/release/dev/xcode-scheme-workdir.rst @@ -0,0 +1,7 @@ +xcode-scheme-workdir +-------------------- + +* The Xcode generator learnt to set the value of the + ``Custom Working Directory`` schema + option with the :prop_tgt:`XCODE_SCHEME_WORKING_DIRECTORY` + target property. diff --git a/Help/variable/CMAKE_XCODE_SCHEME_WORKING_DIRECTORY.rst b/Help/variable/CMAKE_XCODE_SCHEME_WORKING_DIRECTORY.rst new file mode 100644 index 0000000..cc690f7 --- /dev/null +++ b/Help/variable/CMAKE_XCODE_SCHEME_WORKING_DIRECTORY.rst @@ -0,0 +1,12 @@ +CMAKE_XCODE_SCHEME_WORKING_DIRECTORY +------------------------------------ + +Specify the ``Working Directory`` a of the `Run` and `Profile` +action in the generated Xcode scheme. + +This variable initializes the +:prop_tgt:`XCODE_SCHEME_WORKING_DIRECTORY` +property on all targets. + +Please refer to the :prop_tgt:`XCODE_GENERATE_SCHEME` target property +documentation to see all Xcode schema related properties. diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 154bd8e..40e8d48 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3414,7 +3414,7 @@ bool cmGlobalXCodeGenerator::OutputXCodeSharedSchemes( (root->GetMakefile()->GetCMakeInstance()->GetIsInTryCompile() || obj->GetTarget()->GetPropertyAsBool("XCODE_GENERATE_SCHEME"))) { const std::string& targetName = obj->GetTarget()->GetName(); - cmXCodeScheme schm(obj, testables[targetName], + cmXCodeScheme schm(root, obj, testables[targetName], this->CurrentConfigurationTypes, this->XcodeVersion); schm.WriteXCodeSharedScheme(xcProjDir, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 14635f7..b9bf7a5 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -371,6 +371,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, initProp("XCODE_SCHEME_THREAD_SANITIZER_STOP"); initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER"); initProp("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP"); + initProp("XCODE_SCHEME_WORKING_DIRECTORY"); initProp("XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER"); initProp("XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP"); initProp("XCODE_SCHEME_MALLOC_SCRIBBLE"); diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx index afc95f5..b34c2f6 100644 --- a/Source/cmXCodeScheme.cxx +++ b/Source/cmXCodeScheme.cxx @@ -8,13 +8,16 @@ #include #include "cmGeneratedFileStream.h" +#include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmXMLSafe.h" -cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, TestObjects tests, +cmXCodeScheme::cmXCodeScheme(cmLocalGenerator* lg, cmXCodeObject* xcObj, + TestObjects tests, const std::vector& configList, unsigned int xcVersion) - : Target(xcObj) + : LocalGenerator(lg) + , Target(xcObj) , Tests(std::move(tests)) , TargetName(xcObj->GetTarget()->GetName()) , ConfigList(configList) @@ -135,7 +138,8 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout, xout.Attribute("selectedLauncherIdentifier", "Xcode.DebuggerFoundation.Launcher.LLDB"); xout.Attribute("launchStyle", "0"); - xout.Attribute("useCustomWorkingDirectory", "NO"); + WriteCustomWorkingDirectory(xout, configuration); + xout.Attribute("ignoresPersistentStateOnLaunch", "NO"); WriteLaunchActionBooleanAttribute(xout, "debugDocumentVersioning", "XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING", @@ -355,7 +359,7 @@ void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout, xout.Attribute("buildConfiguration", configuration); xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES"); xout.Attribute("savedToolIdentifier", ""); - xout.Attribute("useCustomWorkingDirectory", "NO"); + WriteCustomWorkingDirectory(xout, configuration); WriteLaunchActionBooleanAttribute(xout, "debugDocumentVersioning", "XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING", true); @@ -395,6 +399,22 @@ void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout, xout.EndElement(); } +void cmXCodeScheme::WriteCustomWorkingDirectory( + cmXMLWriter& xout, const std::string& configuration) +{ + std::string propertyValue = this->Target->GetTarget()->GetSafeProperty( + "XCODE_SCHEME_WORKING_DIRECTORY"); + if (propertyValue.empty()) { + xout.Attribute("useCustomWorkingDirectory", "NO"); + } else { + xout.Attribute("useCustomWorkingDirectory", "YES"); + + auto customWorkingDirectory = cmGeneratorExpression::Evaluate( + propertyValue, this->LocalGenerator, configuration); + xout.Attribute("customWorkingDirectory", customWorkingDirectory); + } +} + std::string cmXCodeScheme::WriteVersionString() { std::ostringstream v; diff --git a/Source/cmXCodeScheme.h b/Source/cmXCodeScheme.h index dff5e35..da40856 100644 --- a/Source/cmXCodeScheme.h +++ b/Source/cmXCodeScheme.h @@ -20,7 +20,7 @@ class cmXCodeScheme public: using TestObjects = std::vector; - cmXCodeScheme(cmXCodeObject* xcObj, TestObjects tests, + cmXCodeScheme(cmLocalGenerator* lg, cmXCodeObject* xcObj, TestObjects tests, const std::vector& configList, unsigned int xcVersion); @@ -28,6 +28,7 @@ public: const std::string& container); private: + cmLocalGenerator* const LocalGenerator; const cmXCodeObject* const Target; const TestObjects Tests; const std::string& TargetName; @@ -63,6 +64,9 @@ private: void WriteBuildableReference(cmXMLWriter& xout, const cmXCodeObject* xcObj, const std::string& container); + void WriteCustomWorkingDirectory(cmXMLWriter& xout, + const std::string& configuration); + std::string WriteVersionString(); std::string FindConfiguration(const std::string& name); diff --git a/Tests/RunCMake/XcodeProject/XcodeSchemaProperty-check.cmake b/Tests/RunCMake/XcodeProject/XcodeSchemaProperty-check.cmake index 7d83a70..c742f50 100644 --- a/Tests/RunCMake/XcodeProject/XcodeSchemaProperty-check.cmake +++ b/Tests/RunCMake/XcodeProject/XcodeSchemaProperty-check.cmake @@ -45,6 +45,7 @@ check_property("ENVIRONMENT" [=[key="FOO"]=]) check_property("ENVIRONMENT" [=[value="foo"]=]) check_property("ENVIRONMENT" [=[key="BAR"]=]) check_property("ENVIRONMENT" [=[value="bar"]=]) +check_property("WORKING_DIRECTORY" [=["/working/dir"]=]) expect_no_schema("NoSchema") diff --git a/Tests/RunCMake/XcodeProject/XcodeSchemaProperty.cmake b/Tests/RunCMake/XcodeProject/XcodeSchemaProperty.cmake index be219f4..ce5c0c9 100644 --- a/Tests/RunCMake/XcodeProject/XcodeSchemaProperty.cmake +++ b/Tests/RunCMake/XcodeProject/XcodeSchemaProperty.cmake @@ -35,6 +35,7 @@ endfunction() create_scheme_for_property(EXECUTABLE myExecutable) create_scheme_for_property(ARGUMENTS "--foo;--bar=baz") create_scheme_for_property(ENVIRONMENT "FOO=foo;BAR=bar") +create_scheme_for_property(WORKING_DIRECTORY "/working/dir") add_executable(NoSchema main.cpp) set_target_properties(NoSchema PROPERTIES XCODE_GENERATE_SCHEME OFF) -- cgit v0.12