Explorar o código

Add generator expression support to PDB_OUTPUT_DIRECTORY target property

Fixes: #16365
Marian Klymov %!s(int64=7) %!d(string=hai) anos
pai
achega
79ca546ed2

+ 8 - 2
Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst

@@ -5,8 +5,14 @@ Output directory for the MS debug symbols ``.pdb`` file
 generated by the linker for an executable or shared library target.
 generated by the linker for an executable or shared library target.
 
 
 This property specifies the directory into which the MS debug symbols
 This property specifies the directory into which the MS debug symbols
-will be placed by the linker.  This property is initialized by the
-value of the :variable:`CMAKE_PDB_OUTPUT_DIRECTORY` variable if it is
+will be placed by the linker. The property value may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
+Multi-configuration generators append a per-configuration
+subdirectory to the specified directory unless a generator expression
+is used.
+
+This property is initialized by the value of the
+:variable:`CMAKE_PDB_OUTPUT_DIRECTORY` variable if it is
 set when a target is created.
 set when a target is created.
 
 
 .. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY`
 .. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY`

+ 3 - 0
Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst

@@ -11,5 +11,8 @@ property is initialized by the value of the
 :variable:`CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>` variable if it is
 :variable:`CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>` variable if it is
 set when a target is created.
 set when a target is created.
 
 
+Contents of ``PDB_OUTPUT_DIRECTORY_<CONFIG>`` may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
+
 .. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>`
 .. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>`
 .. include:: PDB_NOTE.txt
 .. include:: PDB_NOTE.txt

+ 5 - 0
Help/release/dev/PDBDirectoryGenExpression.rst

@@ -0,0 +1,5 @@
+PDBDirectoryGenExpression
+-------------------------
+
+* The :prop_tgt:`PDB_OUTPUT_DIRECTORY` property learned to support
+  :manual:`generator expressions <cmake-generator-expressions(7)>`.

+ 13 - 2
Source/cmGeneratorTarget.cxx

@@ -4612,13 +4612,24 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
   // Select an output directory.
   // Select an output directory.
   if (const char* config_outdir = this->GetProperty(configProp)) {
   if (const char* config_outdir = this->GetProperty(configProp)) {
     // Use the user-specified per-configuration output directory.
     // Use the user-specified per-configuration output directory.
-    out = config_outdir;
+    cmGeneratorExpression ge;
+    std::unique_ptr<cmCompiledGeneratorExpression> cge =
+      ge.Parse(config_outdir);
+    out = cge->Evaluate(this->LocalGenerator, config);
 
 
     // Skip per-configuration subdirectory.
     // Skip per-configuration subdirectory.
     conf.clear();
     conf.clear();
   } else if (const char* outdir = this->GetProperty(propertyName)) {
   } else if (const char* outdir = this->GetProperty(propertyName)) {
     // Use the user-specified output directory.
     // Use the user-specified output directory.
-    out = outdir;
+    cmGeneratorExpression ge;
+    std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
+    out = cge->Evaluate(this->LocalGenerator, config);
+
+    // Skip per-configuration subdirectory if the value contained a
+    // generator expression.
+    if (out != outdir) {
+      conf.clear();
+    }
   }
   }
   if (out.empty()) {
   if (out.empty()) {
     return false;
     return false;

+ 8 - 2
Tests/PDBDirectoryAndName/CMakeLists.txt

@@ -19,7 +19,7 @@ set(my_targets "")
 add_library(mylibA SHARED mylibA.c)
 add_library(mylibA SHARED mylibA.c)
 set_target_properties(mylibA PROPERTIES
 set_target_properties(mylibA PROPERTIES
     PDB_NAME "mylibA_Special"
     PDB_NAME "mylibA_Special"
-    PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB"
+    PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB/$<CONFIG>"
 )
 )
 list(APPEND my_targets mylibA)
 list(APPEND my_targets mylibA)
 
 
@@ -87,7 +87,13 @@ foreach(t ${my_targets})
   if(NOT pdb_dir)
   if(NOT pdb_dir)
     set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
     set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
   endif()
   endif()
-  list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
+  if (pdb_dir MATCHES "\\$<.*>")
+    # Skip per-configuration subdirectory if the value contained
+    # a generator expression.
+    list(APPEND pdbs ${pdb_dir}/${pdb_name}.pdb)
+  else()
+    list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
+  endif()
 endforeach()
 endforeach()
 add_custom_target(check_pdbs ALL VERBATIM
 add_custom_target(check_pdbs ALL VERBATIM
   COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"
   COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"