Add generator-agnostic DEBUGGER_WORKING_DIRECTORY target property

Generalize the `VS_DEBUGGER_WORKING_DIRECTORY` property.

Issue: #16478
This commit is contained in:
Garrett Campbell 2024-12-05 14:32:07 -05:00 committed by Brad King
parent 200efab4d4
commit 9ed178f9d8
12 changed files with 57 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

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

View File

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

View File

@ -93,6 +93,16 @@ bool cmGlobalVisualStudioGenerator::InitializePlatform(cmMakefile*)
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
{
if (!this->GeneratorPlatform.empty()) {

View File

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

View File

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

View File

@ -3167,8 +3167,9 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
}
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(
*workingDir, this->LocalGenerator, config);
e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,