mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
Genex: Add capability to retrieve base name for various target artifacts
This new capability is required to solve efficiently issue #18771
This commit is contained in:
@@ -385,12 +385,22 @@ Target-Dependent Queries
|
||||
``$<TARGET_NAME_IF_EXISTS:tgt>``
|
||||
Expands to the ``tgt`` if the given target exists, an empty string
|
||||
otherwise.
|
||||
``$<TARGET_OUTPUT_NAME:tgt>``
|
||||
Base name of main file where ``tgt`` is the name of a target.
|
||||
|
||||
Note that ``tgt`` is not added as a dependency of the target this
|
||||
expression is evaluated on.
|
||||
``$<TARGET_FILE:tgt>``
|
||||
Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a target.
|
||||
``$<TARGET_FILE_NAME:tgt>``
|
||||
Name of main file (.exe, .so.1.2, .a).
|
||||
``$<TARGET_FILE_DIR:tgt>``
|
||||
Directory of main file (.exe, .so.1.2, .a).
|
||||
``$<TARGET_LINKER_OUTPUT_NAME:tgt>``
|
||||
Base name of file used to link where ``tgt`` is the name of a target.
|
||||
|
||||
Note that ``tgt`` is not added as a dependency of the target this
|
||||
expression is evaluated on.
|
||||
``$<TARGET_LINKER_FILE:tgt>``
|
||||
File used to link (.a, .lib, .so) where ``tgt`` is the name of a target.
|
||||
``$<TARGET_LINKER_FILE_NAME:tgt>``
|
||||
@@ -403,6 +413,15 @@ Target-Dependent Queries
|
||||
Name of file with soname (.so.3).
|
||||
``$<TARGET_SONAME_FILE_DIR:tgt>``
|
||||
Directory of with soname (.so.3).
|
||||
``$<TARGET_PDB_OUTPUT_NAME:tgt>``
|
||||
Base name of the linker generated program database file (.pdb)
|
||||
where ``tgt`` is the name of a target.
|
||||
|
||||
See also the :prop_tgt:`PDB_NAME` target property and its configuration
|
||||
specific variant :prop_tgt:`PDB_NAME_<CONFIG>`.
|
||||
|
||||
Note that ``tgt`` is not added as a dependency of the target this
|
||||
expression is evaluated on.
|
||||
``$<TARGET_PDB_FILE:tgt>``
|
||||
Full path to the linker generated program database file (.pdb)
|
||||
where ``tgt`` is the name of a target.
|
||||
|
||||
7
Help/release/dev/genex-TARGET_OUTPUT_NAME.rst
Normal file
7
Help/release/dev/genex-TARGET_OUTPUT_NAME.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
genex-TARGET_OUTPUT_NAME
|
||||
------------------------
|
||||
|
||||
* New ``$<TARGET_OUTPUT_NAME:...>``, ``$<TARGET_LINKER_OUTPUT_NAME:...>`` and
|
||||
``$<TARGET_PDB_OUTPUT_NAME:...>``
|
||||
:manual:`generator expressions <cmake-generator-expressions(7)>` have been
|
||||
added to retrieve the base name of various artifacts.
|
||||
@@ -2131,6 +2131,126 @@ static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
|
||||
ArtifactPathTag>
|
||||
targetBundleContentDirNode;
|
||||
|
||||
//
|
||||
// To retrieve base name for various artifacts
|
||||
//
|
||||
template <typename ArtifactT>
|
||||
struct TargetOutputNameArtifactResultGetter
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetOutputNameArtifactResultGetter<ArtifactNameTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* /*unused*/)
|
||||
{
|
||||
return target->GetOutputName(context->Config,
|
||||
cmStateEnums::RuntimeBinaryArtifact);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetOutputNameArtifactResultGetter<ArtifactLinkerTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
// The file used to link to the target (.so, .lib, .a).
|
||||
if (!target->IsLinkable()) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_LINKER_OUTPUT_NAME is allowed only for libraries "
|
||||
"and executables with ENABLE_EXPORTS.");
|
||||
return std::string();
|
||||
}
|
||||
cmStateEnums::ArtifactType artifact =
|
||||
target->HasImportLibrary(context->Config)
|
||||
? cmStateEnums::ImportLibraryArtifact
|
||||
: cmStateEnums::RuntimeBinaryArtifact;
|
||||
return target->GetOutputName(context->Config, artifact);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetOutputNameArtifactResultGetter<ArtifactPdbTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
if (target->IsImported()) {
|
||||
::reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"TARGET_PDB_OUTPUT_NAME not allowed for IMPORTED targets.");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string language = target->GetLinkerLanguage(context->Config);
|
||||
|
||||
std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
|
||||
|
||||
if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
|
||||
::reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"TARGET_PDB_OUTPUT_NAME is not supported by the target linker.");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
cmStateEnums::TargetType targetType = target->GetType();
|
||||
|
||||
if (targetType != cmStateEnums::SHARED_LIBRARY &&
|
||||
targetType != cmStateEnums::MODULE_LIBRARY &&
|
||||
targetType != cmStateEnums::EXECUTABLE) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_PDB_OUTPUT_NAME is allowed only for "
|
||||
"targets with linker created artifacts.");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return target->GetPDBOutputName(context->Config);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ArtifactT>
|
||||
struct TargetOutputNameArtifact : public TargetArtifactBase
|
||||
{
|
||||
TargetOutputNameArtifact() {} // NOLINT(modernize-use-equals-default)
|
||||
|
||||
int NumExpectedParameters() const override { return 1; }
|
||||
|
||||
std::string Evaluate(
|
||||
const std::vector<std::string>& parameters,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content,
|
||||
cmGeneratorExpressionDAGChecker* dagChecker) const override
|
||||
{
|
||||
cmGeneratorTarget* target =
|
||||
this->GetTarget(parameters, context, content, dagChecker);
|
||||
if (!target) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string result = TargetOutputNameArtifactResultGetter<ArtifactT>::Get(
|
||||
target, context, content);
|
||||
if (context->HadError) {
|
||||
return std::string();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
static const TargetOutputNameArtifact<ArtifactNameTag> targetOutputNameNode;
|
||||
|
||||
static const TargetOutputNameArtifact<ArtifactLinkerTag>
|
||||
targetLinkerOutputNameNode;
|
||||
|
||||
static const TargetOutputNameArtifact<ArtifactPdbTag> targetPdbOutputNameNode;
|
||||
|
||||
static const struct ShellPathNode : public cmGeneratorExpressionNode
|
||||
{
|
||||
ShellPathNode() {} // NOLINT(modernize-use-equals-default)
|
||||
@@ -2205,6 +2325,9 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
|
||||
{ "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
|
||||
{ "TARGET_BUNDLE_DIR", &targetBundleDirNode },
|
||||
{ "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
|
||||
{ "TARGET_OUTPUT_NAME", &targetOutputNameNode },
|
||||
{ "TARGET_LINKER_OUTPUT_NAME", &targetLinkerOutputNameNode },
|
||||
{ "TARGET_PDB_OUTPUT_NAME", &targetPdbOutputNameNode },
|
||||
{ "STREQUAL", &strEqualNode },
|
||||
{ "EQUAL", &equalNode },
|
||||
{ "IN_LIST", &inListNode },
|
||||
|
||||
@@ -3884,6 +3884,31 @@ std::string cmGeneratorTarget::GetLinkerLanguage(
|
||||
return this->GetLinkClosure(config)->LinkerLanguage;
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::GetPDBOutputName(
|
||||
const std::string& config) const
|
||||
{
|
||||
std::string base =
|
||||
this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
|
||||
|
||||
std::vector<std::string> props;
|
||||
std::string configUpper = cmSystemTools::UpperCase(config);
|
||||
if (!configUpper.empty()) {
|
||||
// PDB_NAME_<CONFIG>
|
||||
props.push_back("PDB_NAME_" + configUpper);
|
||||
}
|
||||
|
||||
// PDB_NAME
|
||||
props.emplace_back("PDB_NAME");
|
||||
|
||||
for (std::string const& p : props) {
|
||||
if (const char* outName = this->GetProperty(p)) {
|
||||
base = outName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
|
||||
{
|
||||
std::string prefix;
|
||||
|
||||
@@ -503,6 +503,9 @@ public:
|
||||
|
||||
OutputInfo const* GetOutputInfo(const std::string& config) const;
|
||||
|
||||
// Get the target PDB base name.
|
||||
std::string GetPDBOutputName(const std::string& config) const;
|
||||
|
||||
/** Get the name of the pdb file for the target. */
|
||||
std::string GetPDBName(const std::string& config = "") const;
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at ImportedTarget-TARGET_PDB_OUTPUT_NAME.cmake:2 \(add_custom_target\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PDB_OUTPUT_NAME:empty>
|
||||
|
||||
TARGET_PDB_OUTPUT_NAME not allowed for IMPORTED targets.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
@@ -0,0 +1,2 @@
|
||||
add_library(empty UNKNOWN IMPORTED)
|
||||
add_custom_target(custom COMMAND echo $<TARGET_PDB_OUTPUT_NAME:empty>)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at NonValidCompiler-TARGET_PDB_OUTPUT_NAME.cmake:6 \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PDB_OUTPUT_NAME:empty>
|
||||
|
||||
TARGET_PDB_OUTPUT_NAME is not supported by the target linker.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_library(empty STATIC empty.c)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_PDB_OUTPUT_NAME:empty>]"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,9 @@
|
||||
CMake Error at NonValidTarget-TARGET_PDB_OUTPUT_NAME.cmake:6 \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_PDB_OUTPUT_NAME:empty>
|
||||
|
||||
TARGET_PDB_OUTPUT_NAME is allowed only for targets with linker created
|
||||
artifacts.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_library(empty STATIC empty.c)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_PDB_OUTPUT_NAME:empty>]"
|
||||
)
|
||||
@@ -1,4 +1,10 @@
|
||||
CMake Error at OUTPUT_NAME-recursion.cmake:[0-9]+ \(add_executable\):
|
||||
Target 'empty1' OUTPUT_NAME depends on itself.
|
||||
Target 'empty2' OUTPUT_NAME depends on itself.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
|
||||
CMake Error at OUTPUT_NAME-recursion.cmake:[0-9]+ \(add_executable\):
|
||||
Target 'empty2' OUTPUT_NAME depends on itself.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
enable_language(C)
|
||||
add_executable(empty1 empty.c)
|
||||
set_property(TARGET empty1 PROPERTY OUTPUT_NAME $<TARGET_FILE_NAME:empty1>)
|
||||
|
||||
add_executable(empty2 empty.c)
|
||||
set_property(TARGET empty2 PROPERTY OUTPUT_NAME $<TARGET_OUTPUT_NAME:empty2>)
|
||||
|
||||
6
Tests/RunCMake/GeneratorExpression/ResultValidator.cmake
Normal file
6
Tests/RunCMake/GeneratorExpression/ResultValidator.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
function (CHECK_VALUE test_msg value expected)
|
||||
if (NOT value STREQUAL expected)
|
||||
string (APPEND RunCMake_TEST_FAILED "${test_msg}: actual result:\n [[${value}]]\nbut expected:\n [[${expected}]]\n")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -33,6 +33,10 @@ run_cmake(COMPILE_LANGUAGE-add_test)
|
||||
run_cmake(COMPILE_LANGUAGE-unknown-lang)
|
||||
run_cmake(TARGET_FILE-recursion)
|
||||
run_cmake(OUTPUT_NAME-recursion)
|
||||
run_cmake(TARGET_OUTPUT_NAME)
|
||||
run_cmake(TARGET_OUTPUT_NAME-imported-target)
|
||||
run_cmake(TARGET_OUTPUT_NAME-non-valid-target)
|
||||
run_cmake(TARGET_LINKER_OUTPUT_NAME-non-valid-target)
|
||||
run_cmake(TARGET_PROPERTY-LOCATION)
|
||||
run_cmake(TARGET_PROPERTY-SOURCES)
|
||||
run_cmake(LINK_ONLY-not-linking)
|
||||
@@ -62,11 +66,15 @@ run_cmake(REMOVE_DUPLICATES-4)
|
||||
run_cmake(ImportedTarget-TARGET_BUNDLE_DIR)
|
||||
run_cmake(ImportedTarget-TARGET_BUNDLE_CONTENT_DIR)
|
||||
run_cmake(ImportedTarget-TARGET_PDB_FILE)
|
||||
run_cmake(ImportedTarget-TARGET_PDB_OUTPUT_NAME)
|
||||
if(LINKER_SUPPORTS_PDB)
|
||||
run_cmake(NonValidTarget-TARGET_PDB_FILE)
|
||||
run_cmake(ValidTarget-TARGET_PDB_FILE)
|
||||
run_cmake(NonValidTarget-TARGET_PDB_OUTPUT_NAME)
|
||||
run_cmake(ValidTarget-TARGET_PDB_OUTPUT_NAME)
|
||||
else()
|
||||
run_cmake(NonValidCompiler-TARGET_PDB_FILE)
|
||||
run_cmake(NonValidCompiler-TARGET_PDB_OUTPUT_NAME)
|
||||
endif()
|
||||
|
||||
set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0085:STRING=OLD)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_LINKER_OUTPUT_NAME-non-valid-target.cmake:6 \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_LINKER_OUTPUT_NAME:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_LINKER_OUTPUT_NAME:empty>]"
|
||||
)
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_OUTPUT_NAME-generated.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_OUTPUT_NAME-generated.cmake")
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (GENERATE_CONTENT [[
|
||||
macro (CHECK_VALUE test_msg value expected)
|
||||
if (NOT "${value}" STREQUAL "${expected}")
|
||||
string (APPEND RunCMake_TEST_FAILED "${test_msg}: actual result:\n [${value}]\nbut expected:\n [${expected}]\n")
|
||||
endif()
|
||||
endmacro()
|
||||
]])
|
||||
|
||||
add_executable(exec1 IMPORTED)
|
||||
add_library (shared1 SHARED IMPORTED)
|
||||
add_library (static1 STATIC IMPORTED)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable default" "$<TARGET_OUTPUT_NAME:exec1>" "exec1")
|
||||
check_value ("TARGET_OUTPUT_NAME shared default" "$<TARGET_OUTPUT_NAME:shared1>" "shared1")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker default" "$<TARGET_LINKER_OUTPUT_NAME:shared1>" "shared1")
|
||||
check_value ("TARGET_OUTPUT_NAME static default" "$<TARGET_OUTPUT_NAME:static1>" "static1")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker default" "$<TARGET_LINKER_OUTPUT_NAME:static1>" "static1")
|
||||
]])
|
||||
|
||||
|
||||
add_executable (exec2 IMPORTED)
|
||||
set_property (TARGET exec2 PROPERTY OUTPUT_NAME exec2_custom)
|
||||
add_library (shared2 SHARED IMPORTED)
|
||||
set_property (TARGET shared2 PROPERTY OUTPUT_NAME shared2_custom)
|
||||
add_library (static2 STATIC IMPORTED)
|
||||
set_property (TARGET static2 PROPERTY OUTPUT_NAME static2_custom)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable custom" "$<TARGET_OUTPUT_NAME:exec2>" "exec2_custom")
|
||||
check_value ("TARGET_OUTPUT_NAME shared custom" "$<TARGET_OUTPUT_NAME:shared2>" "shared2_custom")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker custom" "$<TARGET_LINKER_OUTPUT_NAME:shared2>" "shared2_custom")
|
||||
check_value ("TARGET_OUTPUT_NAME static custom" "$<TARGET_OUTPUT_NAME:static2>" "static2_custom")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker custom" "$<TARGET_LINKER_OUTPUT_NAME:static2>" "static2_custom")
|
||||
]])
|
||||
|
||||
|
||||
add_executable (exec3 IMPORTED)
|
||||
set_property (TARGET exec3 PROPERTY RUNTIME_OUTPUT_NAME exec3_runtime)
|
||||
set_property (TARGET exec3 PROPERTY LIBRARY_OUTPUT_NAME exec3_library)
|
||||
set_property (TARGET exec3 PROPERTY ARCHIVE_OUTPUT_NAME exec3_archive)
|
||||
set_property (TARGET exec3 PROPERTY PDB_NAME exec3_pdb)
|
||||
add_library (shared3 SHARED IMPORTED)
|
||||
set_property (TARGET shared3 PROPERTY RUNTIME_OUTPUT_NAME shared3_runtime)
|
||||
set_property (TARGET shared3 PROPERTY LIBRARY_OUTPUT_NAME shared3_library)
|
||||
set_property (TARGET shared3 PROPERTY ARCHIVE_OUTPUT_NAME shared3_archive)
|
||||
set_property (TARGET shared3 PROPERTY PDB_NAME shared3_pdb)
|
||||
add_library (static3 STATIC IMPORTED)
|
||||
set_property (TARGET static3 PROPERTY RUNTIME_OUTPUT_NAME static3_runtime)
|
||||
set_property (TARGET static3 PROPERTY LIBRARY_OUTPUT_NAME static3_library)
|
||||
set_property (TARGET static3 PROPERTY ARCHIVE_OUTPUT_NAME static3_archive)
|
||||
set_property (TARGET static3 PROPERTY PDB_NAME static3_pdb)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable all properties" "$<TARGET_OUTPUT_NAME:exec3>" "exec3_runtime")
|
||||
check_value ("TARGET_OUTPUT_NAME shared all properties" "$<TARGET_OUTPUT_NAME:shared3>" "$<IF:$<IN_LIST:$<PLATFORM_ID>,Windows$<SEMICOLON>CYGWIN>,shared3_runtime,shared3_library>")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker all properties" "$<TARGET_LINKER_OUTPUT_NAME:shared3>" "$<IF:$<IN_LIST:$<PLATFORM_ID>,Windows$<SEMICOLON>CYGWIN>,shared3_archive,shared3_library>")
|
||||
check_value ("TARGET_OUTPUT_NAME static all properties" "$<TARGET_OUTPUT_NAME:static3>" "static3_archive")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker all properties" "$<TARGET_LINKER_OUTPUT_NAME:static3>" "static3_archive")
|
||||
]])
|
||||
|
||||
|
||||
unset(GENERATE_CONDITION)
|
||||
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(_isMultiConfig)
|
||||
list(GET CMAKE_CONFIGURATION_TYPES 0 FIRST_CONFIG)
|
||||
set(GENERATE_CONDITION CONDITION $<CONFIG:${FIRST_CONFIG}>)
|
||||
endif()
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_OUTPUT_NAME-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}" ${GENERATE_CONDITION})
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_OUTPUT_NAME-non-valid-target.cmake:6 \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_OUTPUT_NAME:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_OUTPUT_NAME:empty>]"
|
||||
)
|
||||
96
Tests/RunCMake/GeneratorExpression/TARGET_OUTPUT_NAME.cmake
Normal file
96
Tests/RunCMake/GeneratorExpression/TARGET_OUTPUT_NAME.cmake
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (GENERATE_CONTENT [[
|
||||
macro (CHECK_VALUE test_msg value expected)
|
||||
if (NOT "${value}" STREQUAL "${expected}")
|
||||
string (APPEND RunCMake_TEST_FAILED "${test_msg}: actual result:\n [${value}]\nbut expected:\n [${expected}]\n")
|
||||
endif()
|
||||
endmacro()
|
||||
]])
|
||||
|
||||
add_executable (exec1 empty.c)
|
||||
add_library (shared1 SHARED empty.c)
|
||||
add_library (static1 STATIC empty.c)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable default" "$<TARGET_OUTPUT_NAME:exec1>" "exec1")
|
||||
check_value ("TARGET_OUTPUT_NAME shared default" "$<TARGET_OUTPUT_NAME:shared1>" "shared1")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker default" "$<TARGET_LINKER_OUTPUT_NAME:shared1>" "shared1")
|
||||
check_value ("TARGET_OUTPUT_NAME static default" "$<TARGET_OUTPUT_NAME:static1>" "static1")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker default" "$<TARGET_LINKER_OUTPUT_NAME:static1>" "static1")
|
||||
]])
|
||||
if (CMAKE_C_LINKER_SUPPORTS_PDB)
|
||||
string(APPEND GENERATE_CONTENT [[
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME executable PDB default" "$<TARGET_PDB_OUTPUT_NAME:exec1>" "exec1")
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME shared PDB default" "$<TARGET_PDB_OUTPUT_NAME:shared1>" "shared1")
|
||||
]])
|
||||
endif()
|
||||
|
||||
|
||||
add_executable (exec2 empty.c)
|
||||
set_property (TARGET exec2 PROPERTY OUTPUT_NAME exec2_custom)
|
||||
add_library (shared2 SHARED empty.c)
|
||||
set_property (TARGET shared2 PROPERTY OUTPUT_NAME shared2_custom)
|
||||
add_library (static2 STATIC empty.c)
|
||||
set_property (TARGET static2 PROPERTY OUTPUT_NAME static2_custom)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable custom" "$<TARGET_OUTPUT_NAME:exec2>" "exec2_custom")
|
||||
check_value ("TARGET_OUTPUT_NAME shared custom" "$<TARGET_OUTPUT_NAME:shared2>" "shared2_custom")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker custom" "$<TARGET_LINKER_OUTPUT_NAME:shared2>" "shared2_custom")
|
||||
check_value ("TARGET_OUTPUT_NAME static custom" "$<TARGET_OUTPUT_NAME:static2>" "static2_custom")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker custom" "$<TARGET_LINKER_OUTPUT_NAME:static2>" "static2_custom")
|
||||
]])
|
||||
if (CMAKE_C_LINKER_SUPPORTS_PDB)
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME executable PDB custom" "$<TARGET_PDB_OUTPUT_NAME:exec2>" "exec2_custom")
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME shared PDB custom" "$<TARGET_PDB_OUTPUT_NAME:shared2>" "shared2_custom")
|
||||
]])
|
||||
endif()
|
||||
|
||||
add_executable (exec3 empty.c)
|
||||
set_property (TARGET exec3 PROPERTY RUNTIME_OUTPUT_NAME exec3_runtime)
|
||||
set_property (TARGET exec3 PROPERTY LIBRARY_OUTPUT_NAME exec3_library)
|
||||
set_property (TARGET exec3 PROPERTY ARCHIVE_OUTPUT_NAME exec3_archive)
|
||||
set_property (TARGET exec3 PROPERTY PDB_NAME exec3_pdb)
|
||||
add_library (shared3 SHARED empty.c)
|
||||
set_property (TARGET shared3 PROPERTY RUNTIME_OUTPUT_NAME shared3_runtime)
|
||||
set_property (TARGET shared3 PROPERTY LIBRARY_OUTPUT_NAME shared3_library)
|
||||
set_property (TARGET shared3 PROPERTY ARCHIVE_OUTPUT_NAME shared3_archive)
|
||||
set_property (TARGET shared3 PROPERTY PDB_NAME shared3_pdb)
|
||||
add_library (static3 STATIC empty.c)
|
||||
set_property (TARGET static3 PROPERTY RUNTIME_OUTPUT_NAME static3_runtime)
|
||||
set_property (TARGET static3 PROPERTY LIBRARY_OUTPUT_NAME static3_library)
|
||||
set_property (TARGET static3 PROPERTY ARCHIVE_OUTPUT_NAME static3_archive)
|
||||
set_property (TARGET static3 PROPERTY PDB_NAME static3_pdb)
|
||||
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
|
||||
check_value ("TARGET_OUTPUT_NAME executable all properties" "$<TARGET_OUTPUT_NAME:exec3>" "exec3_runtime")
|
||||
check_value ("TARGET_OUTPUT_NAME shared all properties" "$<TARGET_OUTPUT_NAME:shared3>" "$<IF:$<IN_LIST:$<PLATFORM_ID>,Windows$<SEMICOLON>CYGWIN>,shared3_runtime,shared3_library>")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME shared linker all properties" "$<TARGET_LINKER_OUTPUT_NAME:shared3>" "$<IF:$<IN_LIST:$<PLATFORM_ID>,Windows$<SEMICOLON>CYGWIN>,shared3_archive,shared3_library>")
|
||||
check_value ("TARGET_OUTPUT_NAME static all properties" "$<TARGET_OUTPUT_NAME:static3>" "static3_archive")
|
||||
check_value ("TARGET_LINKER_OUTPUT_NAME static linker all properties" "$<TARGET_LINKER_OUTPUT_NAME:static3>" "static3_archive")
|
||||
]])
|
||||
if (CMAKE_C_LINKER_SUPPORTS_PDB)
|
||||
string (APPEND GENERATE_CONTENT [[
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME executable PDB all properties" "$<TARGET_PDB_OUTPUT_NAME:exec3>" "exec3_pdb")
|
||||
check_value ("TARGET_PDB_OUTPUT_NAME shared PDB all properties" "$<TARGET_PDB_OUTPUT_NAME:shared3>" "shared3_pdb")
|
||||
]])
|
||||
endif()
|
||||
|
||||
|
||||
unset(GENERATE_CONDITION)
|
||||
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(_isMultiConfig)
|
||||
list(GET CMAKE_CONFIGURATION_TYPES 0 FIRST_CONFIG)
|
||||
set(GENERATE_CONDITION CONDITION $<CONFIG:${FIRST_CONFIG}>)
|
||||
endif()
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_OUTPUT_NAME-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}" ${GENERATE_CONDITION})
|
||||
@@ -0,0 +1,7 @@
|
||||
file(STRINGS ${RunCMake_TEST_BINARY_DIR}/test.txt TEST_TXT ENCODING UTF-8)
|
||||
|
||||
list(GET TEST_TXT 0 PDB_OUTPUT_NAME)
|
||||
|
||||
if(NOT PDB_OUTPUT_NAME MATCHES "empty")
|
||||
set(RunCMake_TEST_FAILED "unexpected PDB_OUTPUT_NAME [${PDB_OUTPUT_NAME}]")
|
||||
endif()
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_library(empty SHARED empty.c)
|
||||
|
||||
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(_isMultiConfig)
|
||||
list(GET CMAKE_CONFIGURATION_TYPES 0 FIRST_CONFIG)
|
||||
set(GENERATE_CONDITION CONDITION $<CONFIG:${FIRST_CONFIG}>)
|
||||
endif()
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "$<TARGET_PDB_OUTPUT_NAME:empty>"
|
||||
${GENERATE_CONDITION}
|
||||
)
|
||||
Reference in New Issue
Block a user