Browse Source

Merge topic 'xcode-debugger-workdir'

149ee3b4bc Xcode: Use DEBUGGER_WORKING_DIRECTORY as a fallback for scheme work dir
0f1b9ef32a Help: VS_DEBUGGER_WORKING_DIRECTORY precedence

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10736
Brad King 5 months ago
parent
commit
93cbcd7596

+ 7 - 0
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.

+ 2 - 0
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`.

+ 2 - 0
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`.

+ 4 - 0
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.

+ 9 - 0
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);
+}

+ 2 - 0
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,

+ 7 - 5
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);
   }
 }