diff --git a/Help/prop_tgt/DEBUGGER_WORKING_DIRECTORY.rst b/Help/prop_tgt/DEBUGGER_WORKING_DIRECTORY.rst index 757112f991..3653e9e3ff 100644 --- a/Help/prop_tgt/DEBUGGER_WORKING_DIRECTORY.rst +++ b/Help/prop_tgt/DEBUGGER_WORKING_DIRECTORY.rst @@ -9,3 +9,10 @@ The property value may use This property is initialized by the value of the variable :variable:`CMAKE_DEBUGGER_WORKING_DIRECTORY` if it is set when a target is created. + +If the :prop_tgt:`VS_DEBUGGER_WORKING_DIRECTORY` property is also set, it will +take precedence over ``DEBUGGER_WORKING_DIRECTORY`` when using one of the +Visual Studio generators. + +Similarly, if :prop_tgt:`XCODE_SCHEME_WORKING_DIRECTORY` is set, it will +override ``DEBUGGER_WORKING_DIRECTORY`` when using the Xcode generator. diff --git a/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst b/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst index dbf5442676..9dfa79f2ef 100644 --- a/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst +++ b/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst @@ -13,3 +13,5 @@ created. This property only works for :ref:`Visual Studio Generators`; it is ignored on other generators. + +See also :prop_tgt:`DEBUGGER_WORKING_DIRECTORY`. diff --git a/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst b/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst index d8d56fc387..3f28037841 100644 --- a/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst +++ b/Help/prop_tgt/XCODE_SCHEME_WORKING_DIRECTORY.rst @@ -13,3 +13,5 @@ when a target is created. Please refer to the :prop_tgt:`XCODE_GENERATE_SCHEME` target property documentation to see all Xcode schema related properties. + +See also :prop_tgt:`DEBUGGER_WORKING_DIRECTORY`. diff --git a/Help/release/4.0.rst b/Help/release/4.0.rst index b2b169aba8..ebcbf7de17 100644 --- a/Help/release/4.0.rst +++ b/Help/release/4.0.rst @@ -289,3 +289,7 @@ Changes made since CMake 4.0.0 include the following. This restores support for using LLVM/Clang on macOS without manually setting ``CMAKE_OSX_SYSROOT``, which was broken by CMake 4.0.0's removal of a default value. + + * The :prop_tgt:`DEBUGGER_WORKING_DIRECTORY` target property is now + used by the :generator:`Xcode` generator as a fallback for the + :prop_tgt:`XCODE_SCHEME_WORKING_DIRECTORY` target property. diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index ab8f395c83..7175ac14d8 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -5423,3 +5423,12 @@ std::string cmGlobalXCodeGenerator::GetDeploymentPlatform(cmMakefile const* mf) return "MACOSX_DEPLOYMENT_TARGET"; } } + +cmValue cmGlobalXCodeGenerator::GetDebuggerWorkingDirectory( + cmGeneratorTarget* gt) const +{ + if (cmValue ret = gt->GetProperty("XCODE_SCHEME_WORKING_DIRECTORY")) { + return ret; + } + return cmGlobalGenerator::GetDebuggerWorkingDirectory(gt); +} diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index be42d94155..6c860cbb44 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -132,6 +132,8 @@ public: cmMakefile* mf) override; void AppendFlag(std::string& flags, std::string const& flag) const; + cmValue GetDebuggerWorkingDirectory(cmGeneratorTarget* gt) const override; + enum class BuildSystem { One = 1, diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx index 603bf0c4de..23d007a163 100644 --- a/Source/cmXCodeScheme.cxx +++ b/Source/cmXCodeScheme.cxx @@ -14,6 +14,7 @@ #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" +#include "cmGlobalGenerator.h" #include "cmList.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" @@ -474,16 +475,17 @@ void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout, void cmXCodeScheme::WriteCustomWorkingDirectory( cmXMLWriter& xout, std::string const& configuration) { - std::string const& propertyValue = - this->Target->GetTarget()->GetSafeProperty( - "XCODE_SCHEME_WORKING_DIRECTORY"); - if (propertyValue.empty()) { + cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator(); + + cmValue propertyValue = + gg->GetDebuggerWorkingDirectory(this->Target->GetTarget()); + if (!propertyValue) { xout.Attribute("useCustomWorkingDirectory", "NO"); } else { xout.Attribute("useCustomWorkingDirectory", "YES"); auto customWorkingDirectory = cmGeneratorExpression::Evaluate( - propertyValue, this->LocalGenerator, configuration); + *propertyValue, this->LocalGenerator, configuration); xout.Attribute("customWorkingDirectory", customWorkingDirectory); } }