diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 5c8ed74fe2..4514dbcd05 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -2687,24 +2687,37 @@ In the following, the phrase "the ``tgt`` filename" means the name of the target properties and their configuration specific variants :prop_tgt:`PDB_NAME_` and :prop_tgt:`PDB_OUTPUT_DIRECTORY_`. -.. genex:: $ +.. genex:: $ .. versionadded:: 3.15 Base name of the linker generated program database file (.pdb) where ``tgt`` is the name of a target. + .. versionadded:: 4.2 + The option ``POSTFIX``, which can be used to control the inclusion or not + of the :prop_tgt:`_POSTFIX` target property value as part of the + base name. The default is ``POSTFIX:INCLUDE``. + .. versionchanged:: 4.2 The postfix, as specified by :prop_tgt:`DEBUG_POSTFIX` or :prop_tgt:`_POSTFIX` target properties, is always included in the - ``PDB`` base name. See the policy :policy:`CMP0202`. + ``PDB`` base name, except if option ``POSTFIX`` has value ``EXCLUDE``. + See the policy :policy:`CMP0202`. The base name corresponds to the target PDB file name (see - ``$``) without prefix and suffix. For example, - if target file name is ``base.pdb``, the base name is ``base``. + ``$``) without prefix and suffix, and, optionally, + postfix. For example, if target file name is ``base_postfix.pdb``, the base + name is - See also the :prop_tgt:`PDB_NAME` target property, and its - configuration-specific variant :prop_tgt:`PDB_NAME_`. + * ``base_postfix`` for ``$`` or + ``$``. + * ``base`` for ``$``. + + See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`PDB_NAME` target properties, + and their configuration-specific variants :prop_tgt:`OUTPUT_NAME_` + and :prop_tgt:`PDB_NAME_`, and the :prop_tgt:`_POSTFIX` and + :prop_tgt:`DEBUG_POSTFIX` target properties. Note that ``tgt`` is not added as a dependency of the target this expression is evaluated on. diff --git a/Help/release/dev/GenEx-TARGET_FILE_BASE_NAME-POSTFIX.rst b/Help/release/dev/GenEx-TARGET_FILE_BASE_NAME-POSTFIX.rst index 23ee3c8cd0..491ed0a288 100644 --- a/Help/release/dev/GenEx-TARGET_FILE_BASE_NAME-POSTFIX.rst +++ b/Help/release/dev/GenEx-TARGET_FILE_BASE_NAME-POSTFIX.rst @@ -4,7 +4,8 @@ GenEx-TARGET_FILE_BASE_NAME-POSTFIX * The :genex:`TARGET_FILE_BASE_NAME`, :genex:`TARGET_IMPORT_FILE_BASE_NAME`, :genex:`TARGET_LINKER_FILE_BASE_NAME`, :genex:`TARGET_LINKER_LIBRARY_FILE_BASE_NAME`, - and :genex:`TARGET_LINKER_IMPORT_FILE_BASE_NAME` + :genex:`TARGET_LINKER_IMPORT_FILE_BASE_NAME`, and + :genex:`TARGET_PDB_FILE_BASE_NAME` generator expressions gained the option ``POSTFIX`` to control the inclusion or not of the :prop_tgt:`_POSTFIX` target property as part of the base name of the target. diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 97a85a8e54..9ced2a1220 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -4166,6 +4166,7 @@ static TargetFilesystemArtifact { auto output = target->GetOutputName(eval->Context.Config, cmStateEnums::RuntimeBinaryArtifact); - return postfix == Postfix::Include + return postfix != Postfix::Exclude ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) : output; } @@ -4206,7 +4207,7 @@ struct TargetOutputNameArtifactResultGetter if (target->HasImportLibrary(eval->Context.Config)) { auto output = target->GetOutputName(eval->Context.Config, cmStateEnums::ImportLibraryArtifact); - return postfix == Postfix::Include + return postfix != Postfix::Exclude ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) : output; } @@ -4235,7 +4236,7 @@ struct TargetOutputNameArtifactResultGetter ? cmStateEnums::ImportLibraryArtifact : cmStateEnums::RuntimeBinaryArtifact; auto output = target->GetOutputName(eval->Context.Config, artifact); - return postfix == Postfix::Include + return postfix != Postfix::Exclude ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) : output; } @@ -4262,7 +4263,7 @@ struct TargetOutputNameArtifactResultGetter target->GetType() == cmStateEnums::STATIC_LIBRARY) { auto output = target->GetOutputName(eval->Context.Config, cmStateEnums::ImportLibraryArtifact); - return postfix == Postfix::Include + return postfix != Postfix::Exclude ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) : output; } @@ -4289,7 +4290,7 @@ struct TargetOutputNameArtifactResultGetter if (target->HasImportLibrary(eval->Context.Config)) { auto output = target->GetOutputName(eval->Context.Config, cmStateEnums::ImportLibraryArtifact); - return postfix == Postfix::Include + return postfix != Postfix::Exclude ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) : output; } @@ -4303,7 +4304,7 @@ struct TargetOutputNameArtifactResultGetter static std::string Get(cmGeneratorTarget* target, cm::GenEx::Evaluation* eval, GeneratorExpressionContent const* content, - Postfix /* unused */) + Postfix postfix) { if (target->IsImported()) { ::reportError( @@ -4336,9 +4337,24 @@ struct TargetOutputNameArtifactResultGetter auto output = target->GetPDBOutputName(eval->Context.Config); - return target->GetPolicyStatusCMP0202() == cmPolicies::NEW - ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) - : output; + if (target->GetPolicyStatusCMP0202() == cmPolicies::NEW) { + return postfix != Postfix::Exclude + ? cmStrCat(output, target->GetFilePostfix(eval->Context.Config)) + : output; + } + + if (target->GetPolicyStatusCMP0202() == cmPolicies::WARN && + postfix != Postfix::Unspecified) { + eval->Context.LG->GetCMakeInstance()->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0202), '\n', + "\"POSTFIX\" option is recognized only when the policy is " + "set to NEW. Since the policy is not set, the OLD behavior " + "will be used."), + eval->Backtrace); + } + + return output; } }; @@ -4366,7 +4382,7 @@ struct TargetFileBaseNameArtifact : public TargetArtifactBase return std::string(); } - Postfix postfix = Postfix::Include; + Postfix postfix = Postfix::Unspecified; if (parameters.size() == 2) { if (parameters[1] == "POSTFIX:INCLUDE") { postfix = Postfix::Include; @@ -4388,14 +4404,6 @@ struct TargetFileBaseNameArtifact : public TargetArtifactBase } }; -struct TargetPdbFileBaseNameArtifact - : public TargetFileBaseNameArtifact -{ - TargetPdbFileBaseNameArtifact() {} // NOLINT(modernize-use-equals-default) - - int NumExpectedParameters() const override { return 1; } -}; - static TargetFileBaseNameArtifact const targetFileBaseNameNode; static TargetFileBaseNameArtifact const @@ -4406,7 +4414,8 @@ static TargetFileBaseNameArtifact const targetLinkerLibraryFileBaseNameNode; static TargetFileBaseNameArtifact const targetLinkerImportFileBaseNameNode; -static TargetPdbFileBaseNameArtifact const targetPdbFileBaseNameNode; +static TargetFileBaseNameArtifact const + targetPdbFileBaseNameNode; class ArtifactFilePrefixTag; class ArtifactImportFilePrefixTag; diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME-stderr.txt b/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME-stderr.txt new file mode 100644 index 0000000000..d4ad4bbed9 --- /dev/null +++ b/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME-stderr.txt @@ -0,0 +1,10 @@ +^CMake Warning \(dev\) at CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME\.cmake:[0-9]+ \(file\): + Policy CMP0202 is not set: PDB file names always include their target's + per-config POSTFIX\. Run "cmake --help-policy CMP0202" for policy details\. + Use the cmake_policy command to set the policy and suppress this warning\. + + "POSTFIX" option is recognized only when the policy is set to NEW. Since + the policy is not set, the OLD behavior will be used\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME.cmake new file mode 100644 index 0000000000..2e1e891b8f --- /dev/null +++ b/Tests/RunCMake/GenEx-TARGET_FILE/CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME.cmake @@ -0,0 +1,11 @@ + +cmake_minimum_required(VERSION 4.0) + +enable_language(C) + +add_library(empty SHARED empty.c) + +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt" + CONTENT "[$]" +) diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake index dc71a18753..2cef2d13b7 100644 --- a/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake @@ -41,6 +41,7 @@ if(LINKER_SUPPORTS_PDB) run_cmake(ValidTarget-TARGET_PDB_FILE) run_cmake(NonValidTarget-TARGET_PDB_FILE_BASE_NAME) run_cmake(ValidTarget-TARGET_PDB_FILE_BASE_NAME) + run_cmake(CMP0202-WARN-TARGET_PDB_FILE_BASE_NAME) else() run_cmake(NonValidCompiler-TARGET_PDB_FILE) run_cmake(NonValidCompiler-TARGET_PDB_FILE_BASE_NAME) diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_FILE_BASE_NAME.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_FILE_BASE_NAME.cmake index 81bbcf5f17..414859b57d 100644 --- a/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_FILE_BASE_NAME.cmake +++ b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_FILE_BASE_NAME.cmake @@ -117,23 +117,23 @@ string (APPEND GENERATE_CONTENT [[ check_value ("TARGET_FILE_BASE_NAME executable all properties + postfix" "$" "exec4_runtime_postfix") check_value ("TARGET_FILE_BASE_NAME executable all properties + postfix" "$" "exec4_runtime_postfix") -check_value ("TARGET_FILE_BASE_NAME executable all properties without postfix" "$" "exec4_runtime") +check_value ("TARGET_FILE_BASE_NAME executable all properties + postfix (excluded)" "$" "exec4_runtime") check_value ("TARGET_FILE_BASE_NAME shared all properties + postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_runtime,shared4_library>_postfix") check_value ("TARGET_FILE_BASE_NAME shared all properties + postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_runtime,shared4_library>_postfix") -check_value ("TARGET_FILE_BASE_NAME shared all properties without postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_runtime,shared4_library>") +check_value ("TARGET_FILE_BASE_NAME shared all properties + postfix (excluded)" "$" "$,Windows$CYGWIN$MSYS>,shared4_runtime,shared4_library>") check_value ("TARGET_LINKER_FILE_BASE_NAME shared linker all properties + postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_archive,shared4_library>_postfix") check_value ("TARGET_LINKER_FILE_BASE_NAME shared linker all properties + postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_archive,shared4_library>_postfix") -check_value ("TARGET_LINKER_FILE_BASE_NAME shared linker all properties without postfix" "$" "$,Windows$CYGWIN$MSYS>,shared4_archive,shared4_library>") +check_value ("TARGET_LINKER_FILE_BASE_NAME shared linker all properties + postfix (excluded)" "$" "$,Windows$CYGWIN$MSYS>,shared4_archive,shared4_library>") check_value ("TARGET_FILE_BASE_NAME static all properties + postfix" "$" "static4_archive_postfix") check_value ("TARGET_FILE_BASE_NAME static all properties + postfix" "$" "static4_archive_postfix") -check_value ("TARGET_FILE_BASE_NAME static all properties without postfix" "$" "static4_archive") +check_value ("TARGET_FILE_BASE_NAME static all properties + postfix (excluded)" "$" "static4_archive") check_value ("TARGET_LINKER_FILE_BASE_NAME static linker all properties + postfix" "$" "static4_archive_postfix") check_value ("TARGET_LINKER_FILE_BASE_NAME static linker all properties + postfix" "$" "static4_archive_postfix") -check_value ("TARGET_LINKER_FILE_BASE_NAME static linker all properties without postfix" "$" "static4_archive") +check_value ("TARGET_LINKER_FILE_BASE_NAME static linker all properties + postfix (excluded)" "$" "static4_archive") ]]) if (CMAKE_C_LINKER_SUPPORTS_PDB) string (APPEND GENERATE_CONTENT [[ @@ -158,6 +158,12 @@ if (CMAKE_C_LINKER_SUPPORTS_PDB) string (APPEND GENERATE_CONTENT [[ check_value ("TARGET_PDB_FILE_BASE_NAME executable PDB all properties + postfix" "$" "exec5_pdb_postfix") check_value ("TARGET_PDB_FILE_BASE_NAME shared PDB all properties + postfix" "$" "shared5_pdb_postfix") + +check_value ("TARGET_PDB_FILE_BASE_NAME executable PDB all properties + postfix" "$" "exec5_pdb_postfix") +check_value ("TARGET_PDB_FILE_BASE_NAME shared PDB all properties + postfix" "$" "shared5_pdb_postfix") + +check_value ("TARGET_PDB_FILE_BASE_NAME executable PDB all properties + postfix (excluded)" "$" "exec5_pdb") +check_value ("TARGET_PDB_FILE_BASE_NAME shared PDB all properties + postfix (excluded)" "$" "shared5_pdb") ]]) endif()