Browse Source

Add generator-agnostic DEBUGGER_WORKING_DIRECTORY target property

Generalize the `VS_DEBUGGER_WORKING_DIRECTORY` property.

Issue: #16478
Garrett Campbell 10 months ago
parent
commit
9ed178f9d8

+ 2 - 0
Auxiliary/vim/syntax/cmake.vim

@@ -155,6 +155,7 @@ syn keyword cmakeProperty contained
             \ C_STANDARD_REQUIRED
             \ C_STANDARD_REQUIRED
             \ DEBUG_CONFIGURATIONS
             \ DEBUG_CONFIGURATIONS
             \ DEBUG_POSTFIX
             \ DEBUG_POSTFIX
+            \ DEBUGGER_WORKING_DIRECTORY
             \ DEFINE_SYMBOL
             \ DEFINE_SYMBOL
             \ DEFINITIONS
             \ DEFINITIONS
             \ DEPENDS
             \ DEPENDS
@@ -1140,6 +1141,7 @@ syn keyword cmakeVariable contained
             \ CMAKE_C_VISIBILITY_PRESET
             \ CMAKE_C_VISIBILITY_PRESET
             \ CMAKE_DEBUG_POSTFIX
             \ CMAKE_DEBUG_POSTFIX
             \ CMAKE_DEBUG_TARGET_PROPERTIES
             \ CMAKE_DEBUG_TARGET_PROPERTIES
+            \ CMAKE_DEBUGGER_WORKING_DIRECTORY
             \ CMAKE_DEFAULT_BUILD_TYPE
             \ CMAKE_DEFAULT_BUILD_TYPE
             \ CMAKE_DEFAULT_CONFIGS
             \ CMAKE_DEFAULT_CONFIGS
             \ CMAKE_DEPENDS_IN_PROJECT_ONLY
             \ CMAKE_DEPENDS_IN_PROJECT_ONLY

+ 1 - 0
Help/manual/cmake-properties.7.rst

@@ -204,6 +204,7 @@ Properties on Targets
    /prop_tgt/CXX_STANDARD
    /prop_tgt/CXX_STANDARD
    /prop_tgt/CXX_STANDARD_REQUIRED
    /prop_tgt/CXX_STANDARD_REQUIRED
    /prop_tgt/DEBUG_POSTFIX
    /prop_tgt/DEBUG_POSTFIX
+   /prop_tgt/DEBUGGER_WORKING_DIRECTORY
    /prop_tgt/DEFINE_SYMBOL
    /prop_tgt/DEFINE_SYMBOL
    /prop_tgt/DEPLOYMENT_ADDITIONAL_FILES
    /prop_tgt/DEPLOYMENT_ADDITIONAL_FILES
    /prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY
    /prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY

+ 1 - 0
Help/manual/cmake-variables.7.rst

@@ -434,6 +434,7 @@ Variables that Control the Build
    /variable/CMAKE_CXX_MODULE_STD
    /variable/CMAKE_CXX_MODULE_STD
    /variable/CMAKE_CXX_SCAN_FOR_MODULES
    /variable/CMAKE_CXX_SCAN_FOR_MODULES
    /variable/CMAKE_DEBUG_POSTFIX
    /variable/CMAKE_DEBUG_POSTFIX
+   /variable/CMAKE_DEBUGGER_WORKING_DIRECTORY
    /variable/CMAKE_DEFAULT_BUILD_TYPE
    /variable/CMAKE_DEFAULT_BUILD_TYPE
    /variable/CMAKE_DEFAULT_CONFIGS
    /variable/CMAKE_DEFAULT_CONFIGS
    /variable/CMAKE_DEPENDS_USE_COMPILER
    /variable/CMAKE_DEPENDS_USE_COMPILER

+ 11 - 0
Help/prop_tgt/DEBUGGER_WORKING_DIRECTORY.rst

@@ -0,0 +1,11 @@
+DEBUGGER_WORKING_DIRECTORY
+--------------------------
+
+.. versionadded:: 3.32
+
+  Sets the local debugger working directory for C++ targets.
+  The property value may use
+  :manual:`generator expressions <cmake-generator-expressions(7)>`.
+  This property is initialized by the value of the variable
+  :variable:`CMAKE_DEBUGGER_WORKING_DIRECTORY` if it is set when a target is
+  created.

+ 9 - 0
Help/release/dev/debugger-working-directory.rst

@@ -0,0 +1,9 @@
+debugger-working-directory
+--------------------------
+
+* The :variable:`CMAKE_DEBUGGER_WORKING_DIRECTORY` was added to
+  initialize the corresponding target property.
+
+* The :prop_tgt:`DEBUGGER_WORKING_DIRECTORY` target property was added
+  to tell generators what debugger working directory should be set for
+  the target.

+ 8 - 0
Help/variable/CMAKE_DEBUGGER_WORKING_DIRECTORY.rst

@@ -0,0 +1,8 @@
+CMAKE_DEBUGGER_WORKING_DIRECTORY
+--------------------------------
+
+.. versionadded:: 3.32
+
+This variable is used to initialize the :prop_tgt:`DEBUGGER_WORKING_DIRECTORY`
+property on each target as it is created.  See that target property
+for additional information.

+ 6 - 0
Source/cmGlobalGenerator.cxx

@@ -3499,6 +3499,12 @@ void cmGlobalGenerator::AppendDirectoryForConfig(const std::string& /*unused*/,
   // configuration.
   // configuration.
 }
 }
 
 
+cmValue cmGlobalGenerator::GetDebuggerWorkingDirectory(
+  cmGeneratorTarget* gt) const
+{
+  return gt->GetProperty("DEBUGGER_WORKING_DIRECTORY");
+}
+
 cmGlobalGenerator::TargetDependSet const&
 cmGlobalGenerator::TargetDependSet const&
 cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target)
 cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target)
 {
 {

+ 2 - 0
Source/cmGlobalGenerator.h

@@ -513,6 +513,8 @@ public:
   // Default config to use for cmake --build
   // Default config to use for cmake --build
   virtual std::string GetDefaultBuildConfig() const { return "Debug"; }
   virtual std::string GetDefaultBuildConfig() const { return "Debug"; }
 
 
+  virtual cmValue GetDebuggerWorkingDirectory(cmGeneratorTarget* gt) const;
+
   // Class to track a set of dependencies.
   // Class to track a set of dependencies.
   using TargetDependSet = cmTargetDependSet;
   using TargetDependSet = cmTargetDependSet;
 
 

+ 10 - 0
Source/cmGlobalVisualStudioGenerator.cxx

@@ -93,6 +93,16 @@ bool cmGlobalVisualStudioGenerator::InitializePlatform(cmMakefile*)
   return true;
   return true;
 }
 }
 
 
+cmValue cmGlobalVisualStudioGenerator::GetDebuggerWorkingDirectory(
+  cmGeneratorTarget* gt) const
+{
+  if (cmValue ret = gt->GetProperty("VS_DEBUGGER_WORKING_DIRECTORY")) {
+    return ret;
+  } else {
+    return cmGlobalGenerator::GetDebuggerWorkingDirectory(gt);
+  }
+}
+
 std::string const& cmGlobalVisualStudioGenerator::GetPlatformName() const
 std::string const& cmGlobalVisualStudioGenerator::GetPlatformName() const
 {
 {
   if (!this->GeneratorPlatform.empty()) {
   if (!this->GeneratorPlatform.empty()) {

+ 2 - 0
Source/cmGlobalVisualStudioGenerator.h

@@ -78,6 +78,8 @@ public:
    */
    */
   virtual std::string GetUserMacrosRegKeyBase();
   virtual std::string GetUserMacrosRegKeyBase();
 
 
+  cmValue GetDebuggerWorkingDirectory(cmGeneratorTarget* gt) const override;
+
   enum MacroName
   enum MacroName
   {
   {
     MacroReload,
     MacroReload,

+ 2 - 0
Source/cmTarget.cxx

@@ -373,6 +373,8 @@ struct TargetProperty
 
 
 TargetProperty const StaticTargetProperties[] = {
 TargetProperty const StaticTargetProperties[] = {
   /* clang-format off */
   /* clang-format off */
+  // -- Debugger Properties
+  { "DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
   // Compilation properties
   // Compilation properties
   { "COMPILE_WARNING_AS_ERROR"_s, IC::CanCompileSources },
   { "COMPILE_WARNING_AS_ERROR"_s, IC::CanCompileSources },
   { "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },
   { "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },

+ 3 - 2
Source/cmVisualStudio10TargetGenerator.cxx

@@ -3167,8 +3167,9 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
     }
     }
 
 
     if (ttype <= cmStateEnums::UTILITY) {
     if (ttype <= cmStateEnums::UTILITY) {
-      if (cmValue workingDir = this->GeneratorTarget->GetProperty(
-            "VS_DEBUGGER_WORKING_DIRECTORY")) {
+      if (cmValue workingDir =
+            this->GlobalGenerator->GetDebuggerWorkingDirectory(
+              this->GeneratorTarget)) {
         std::string genWorkingDir = cmGeneratorExpression::Evaluate(
         std::string genWorkingDir = cmGeneratorExpression::Evaluate(
           *workingDir, this->LocalGenerator, config);
           *workingDir, this->LocalGenerator, config);
         e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
         e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,