Add generator expression support to PDB_OUTPUT_DIRECTORY target property

Fixes: #16365
This commit is contained in:
Marian Klymov 2018-05-17 00:19:56 +03:00 committed by Brad King
parent acb9710162
commit 79ca546ed2
5 changed files with 37 additions and 6 deletions

View File

@ -5,8 +5,14 @@ Output directory for the MS debug symbols ``.pdb`` file
generated by the linker for an executable or shared library target.
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.
.. |COMPILE_PDB_XXX| replace:: :prop_tgt:`COMPILE_PDB_OUTPUT_DIRECTORY`

View File

@ -11,5 +11,8 @@ property is initialized by the value of the
:variable:`CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG>` variable if it is
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>`
.. include:: PDB_NOTE.txt

View File

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

View File

@ -4612,13 +4612,24 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
// Select an output directory.
if (const char* config_outdir = this->GetProperty(configProp)) {
// 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.
conf.clear();
} else if (const char* outdir = this->GetProperty(propertyName)) {
// 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()) {
return false;

View File

@ -19,7 +19,7 @@ set(my_targets "")
add_library(mylibA SHARED mylibA.c)
set_target_properties(mylibA PROPERTIES
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)
@ -87,7 +87,13 @@ foreach(t ${my_targets})
if(NOT pdb_dir)
set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
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()
add_custom_target(check_pdbs ALL VERBATIM
COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"