mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
Genex: add $<TARGET_FILE_PREFIX:...> and $<TARGET_FILE_SUFFIX:...>
These capabilities complement MR !3190 and is also needed to solve issue #18771.
This commit is contained in:
@@ -393,7 +393,18 @@ Target-Dependent Queries
|
||||
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.
|
||||
Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a
|
||||
target.
|
||||
``$<TARGET_FILE_PREFIX:tgt>``
|
||||
Prefix 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_SUFFIX:tgt>``
|
||||
Suffix 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_NAME:tgt>``
|
||||
Name of main file (.exe, .so.1.2, .a).
|
||||
``$<TARGET_FILE_DIR:tgt>``
|
||||
@@ -405,6 +416,16 @@ Target-Dependent Queries
|
||||
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_PREFIX:tgt>``
|
||||
Prefix 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_SUFFIX:tgt>``
|
||||
Suffix 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_NAME:tgt>``
|
||||
Name of file used to link (.a, .lib, .so).
|
||||
``$<TARGET_LINKER_FILE_DIR:tgt>``
|
||||
|
||||
7
Help/release/dev/genex-TARGET_FILE_PREFIX.rst
Normal file
7
Help/release/dev/genex-TARGET_FILE_PREFIX.rst
Normal file
@@ -0,0 +1,7 @@
|
||||
genex-TARGET_FILE_PREFIX
|
||||
------------------------
|
||||
|
||||
* New ``$<TARGET_FILE_PREFIX:...>``, ``$<TARGET_LINKER_FILE_PREFIX:...>``,
|
||||
``$<TARGET_FILE_SUFFIX:...>`` and ``$<TARGET_LINKER_FILE_SUFFIX:...>``
|
||||
:manual:`generator expressions <cmake-generator-expressions(7)>` have been
|
||||
added to retrieve the prefix and suffix of various artifacts.
|
||||
@@ -2297,6 +2297,119 @@ static const TargetOutputNameArtifact<ArtifactLinkerTag>
|
||||
|
||||
static const TargetOutputNameArtifact<ArtifactPdbTag> targetPdbOutputNameNode;
|
||||
|
||||
class ArtifactFilePrefixTag;
|
||||
class ArtifactLinkerFilePrefixTag;
|
||||
class ArtifactFileSuffixTag;
|
||||
class ArtifactLinkerFileSuffixTag;
|
||||
|
||||
template <typename ArtifactT>
|
||||
struct TargetFileArtifactResultGetter
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetFileArtifactResultGetter<ArtifactFilePrefixTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent*)
|
||||
{
|
||||
return target->GetFilePrefix(context->Config);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct TargetFileArtifactResultGetter<ArtifactLinkerFilePrefixTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
if (!target->IsLinkable()) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_LINKER_PREFIX 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->GetFilePrefix(context->Config, artifact);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct TargetFileArtifactResultGetter<ArtifactFileSuffixTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent*)
|
||||
{
|
||||
return target->GetFileSuffix(context->Config);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct TargetFileArtifactResultGetter<ArtifactLinkerFileSuffixTag>
|
||||
{
|
||||
static std::string Get(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
if (!target->IsLinkable()) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_LINKER_SUFFIX 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->GetFileSuffix(context->Config, artifact);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ArtifactT>
|
||||
struct TargetFileArtifact : public TargetArtifactBase
|
||||
{
|
||||
TargetFileArtifact() {} // 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 =
|
||||
TargetFileArtifactResultGetter<ArtifactT>::Get(target, context, content);
|
||||
if (context->HadError) {
|
||||
return std::string();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
static const TargetFileArtifact<ArtifactFilePrefixTag> targetFilePrefixNode;
|
||||
static const TargetFileArtifact<ArtifactLinkerFilePrefixTag>
|
||||
targetLinkerFilePrefixNode;
|
||||
static const TargetFileArtifact<ArtifactFileSuffixTag> targetFileSuffixNode;
|
||||
static const TargetFileArtifact<ArtifactLinkerFileSuffixTag>
|
||||
targetLinkerFileSuffixNode;
|
||||
|
||||
static const struct ShellPathNode : public cmGeneratorExpressionNode
|
||||
{
|
||||
ShellPathNode() {} // NOLINT(modernize-use-equals-default)
|
||||
@@ -2361,6 +2474,10 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
|
||||
{ "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File },
|
||||
{ "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File },
|
||||
{ "TARGET_PDB_FILE", &targetPdbNodeGroup.File },
|
||||
{ "TARGET_FILE_PREFIX", &targetFilePrefixNode },
|
||||
{ "TARGET_LINKER_FILE_PREFIX", &targetLinkerFilePrefixNode },
|
||||
{ "TARGET_FILE_SUFFIX", &targetFileSuffixNode },
|
||||
{ "TARGET_LINKER_FILE_SUFFIX", &targetLinkerFileSuffixNode },
|
||||
{ "TARGET_FILE_NAME", &targetNodeGroup.FileName },
|
||||
{ "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName },
|
||||
{ "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName },
|
||||
|
||||
@@ -33,6 +33,14 @@ 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_FILE_PREFIX)
|
||||
run_cmake(TARGET_FILE_PREFIX-imported-target)
|
||||
run_cmake(TARGET_FILE_PREFIX-non-valid-target)
|
||||
run_cmake(TARGET_LINKER_FILE_PREFIX-non-valid-target)
|
||||
run_cmake(TARGET_FILE_SUFFIX)
|
||||
run_cmake(TARGET_FILE_SUFFIX-imported-target)
|
||||
run_cmake(TARGET_FILE_SUFFIX-non-valid-target)
|
||||
run_cmake(TARGET_LINKER_FILE_SUFFIX-non-valid-target)
|
||||
run_cmake(TARGET_OUTPUT_NAME)
|
||||
run_cmake(TARGET_OUTPUT_NAME-imported-target)
|
||||
run_cmake(TARGET_OUTPUT_NAME-non-valid-target)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_FILE_PREFIX-generated.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_FILE_PREFIX-generated.cmake")
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (win_platforms Windows CYGWIN)
|
||||
|
||||
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
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable default\" \"$<TARGET_FILE_PREFIX:exec1>\" \"\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared default\" \"$<TARGET_FILE_PREFIX:shared1>\" \"${CMAKE_SHARED_LIBRARY_PREFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker default\" \"$<TARGET_LINKER_FILE_PREFIX:shared1>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,${CMAKE_IMPORT_LIBRARY_PREFIX},${CMAKE_SHARED_LIBRARY_PREFIX}>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static default\" \"$<TARGET_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX static linker default\" \"$<TARGET_LINKER_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")\n")
|
||||
|
||||
|
||||
add_executable (exec2 IMPORTED)
|
||||
set_property (TARGET exec2 PROPERTY PREFIX exec2_prefix)
|
||||
set_property (TARGET exec2 PROPERTY ENABLE_EXPORTS TRUE)
|
||||
set_property (TARGET exec2 PROPERTY IMPORT_PREFIX exec2_import_prefix)
|
||||
add_library (shared2 SHARED IMPORTED)
|
||||
set_property (TARGET shared2 PROPERTY PREFIX shared2_prefix)
|
||||
set_property (TARGET shared2 PROPERTY IMPORT_PREFIX shared2_import_prefix)
|
||||
add_library (static2 STATIC IMPORTED)
|
||||
set_property (TARGET static2 PROPERTY PREFIX static2_prefix)
|
||||
set_property (TARGET static2 PROPERTY IMPORT_PREFIX static2_import_prefix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable custom\" \"$<TARGET_FILE_PREFIX:exec2>\" \"exec2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared custom\" \"$<TARGET_FILE_PREFIX:shared2>\" \"shared2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_prefix,shared2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static custom\" \"$<TARGET_FILE_PREFIX:static2>\" \"static2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX static linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:static2>\" \"static2_prefix\")\n")
|
||||
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_FILE_PREFIX-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}")
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_FILE_PREFIX-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_FILE_PREFIX:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_FILE_PREFIX:empty>]"
|
||||
)
|
||||
49
Tests/RunCMake/GeneratorExpression/TARGET_FILE_PREFIX.cmake
Normal file
49
Tests/RunCMake/GeneratorExpression/TARGET_FILE_PREFIX.cmake
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (win_platforms Windows CYGWIN)
|
||||
|
||||
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
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable default\" \"$<TARGET_FILE_PREFIX:exec1>\" \"\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared default\" \"$<TARGET_FILE_PREFIX:shared1>\" \"${CMAKE_SHARED_LIBRARY_PREFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker default\" \"$<TARGET_LINKER_FILE_PREFIX:shared1>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,${CMAKE_IMPORT_LIBRARY_PREFIX},${CMAKE_SHARED_LIBRARY_PREFIX}>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static default\" \"$<TARGET_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX static linker default\" \"$<TARGET_LINKER_FILE_PREFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_PREFIX}\")\n")
|
||||
|
||||
|
||||
add_executable (exec2 empty.c)
|
||||
set_property (TARGET exec2 PROPERTY PREFIX exec2_prefix)
|
||||
set_property (TARGET exec2 PROPERTY ENABLE_EXPORTS TRUE)
|
||||
set_property (TARGET exec2 PROPERTY IMPORT_PREFIX exec2_import_prefix)
|
||||
add_library (shared2 SHARED empty.c)
|
||||
set_property (TARGET shared2 PROPERTY PREFIX shared2_prefix)
|
||||
set_property (TARGET shared2 PROPERTY IMPORT_PREFIX shared2_import_prefix)
|
||||
add_library (static2 STATIC empty.c)
|
||||
set_property (TARGET static2 PROPERTY PREFIX static2_prefix)
|
||||
set_property (TARGET static2 PROPERTY IMPORT_PREFIX static2_import_prefix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_PREFIX executable custom\" \"$<TARGET_FILE_PREFIX:exec2>\" \"exec2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX executable linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_prefix,exec2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX shared custom\" \"$<TARGET_FILE_PREFIX:shared2>\" \"shared2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX shared linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_prefix,shared2_prefix>\")
|
||||
check_value (\"TARGET_FILE_PREFIX static custom\" \"$<TARGET_FILE_PREFIX:static2>\" \"static2_prefix\")
|
||||
check_value (\"TARGET_LINKER_FILE_PREFIX static linker custom\" \"$<TARGET_LINKER_FILE_PREFIX:static2>\" \"static2_prefix\")\n")
|
||||
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_FILE_PREFIX-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_FILE_SUFFIX-generated.cmake")
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
include ("${RunCMake_TEST_BINARY_DIR}/TARGET_FILE_SUFFIX-generated.cmake")
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (win_platforms Windows CYGWIN)
|
||||
|
||||
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
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable default\" \"$<TARGET_FILE_SUFFIX:exec1>\" \"${CMAKE_EXECUTABLE_SUFFIX}\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared default\" \"$<TARGET_FILE_SUFFIX:shared1>\" \"${CMAKE_SHARED_LIBRARY_SUFFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker default\" \"$<TARGET_LINKER_FILE_SUFFIX:shared1>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,${CMAKE_IMPORT_LIBRARY_SUFFIX},${CMAKE_SHARED_LIBRARY_SUFFIX}>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static default\" \"$<TARGET_FILE_SUFFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_SUFFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX static linker default\" \"$<TARGET_LINKER_FILE_SUFFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_SUFFIX}\")\n")
|
||||
|
||||
|
||||
add_executable (exec2 IMPORTED)
|
||||
set_property (TARGET exec2 PROPERTY SUFFIX exec2_suffix)
|
||||
set_property (TARGET exec2 PROPERTY ENABLE_EXPORTS TRUE)
|
||||
set_property (TARGET exec2 PROPERTY IMPORT_SUFFIX exec2_import_suffix)
|
||||
add_library (shared2 SHARED IMPORTED)
|
||||
set_property (TARGET shared2 PROPERTY SUFFIX shared2_suffix)
|
||||
set_property (TARGET shared2 PROPERTY IMPORT_SUFFIX shared2_import_suffix)
|
||||
add_library (static2 STATIC IMPORTED)
|
||||
set_property (TARGET static2 PROPERTY SUFFIX static2_suffix)
|
||||
set_property (TARGET static2 PROPERTY IMPORT_SUFFIX static2_import_suffix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable custom\" \"$<TARGET_FILE_SUFFIX:exec2>\" \"exec2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared custom\" \"$<TARGET_FILE_SUFFIX:shared2>\" \"shared2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_suffix,shared2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static custom\" \"$<TARGET_FILE_SUFFIX:static2>\" \"static2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX static linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:static2>\" \"static2_suffix\")\n")
|
||||
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_FILE_SUFFIX-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}")
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_FILE_SUFFIX-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_FILE_SUFFIX:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_FILE_SUFFIX:empty>]"
|
||||
)
|
||||
49
Tests/RunCMake/GeneratorExpression/TARGET_FILE_SUFFIX.cmake
Normal file
49
Tests/RunCMake/GeneratorExpression/TARGET_FILE_SUFFIX.cmake
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
enable_language (C)
|
||||
|
||||
set (win_platforms Windows CYGWIN)
|
||||
|
||||
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
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable default\" \"$<TARGET_FILE_SUFFIX:exec1>\" \"${CMAKE_EXECUTABLE_SUFFIX}\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared default\" \"$<TARGET_FILE_SUFFIX:shared1>\" \"${CMAKE_SHARED_LIBRARY_SUFFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker default\" \"$<TARGET_LINKER_FILE_SUFFIX:shared1>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,${CMAKE_IMPORT_LIBRARY_SUFFIX},${CMAKE_SHARED_LIBRARY_SUFFIX}>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static default\" \"$<TARGET_FILE_SUFFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_SUFFIX}\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX static linker default\" \"$<TARGET_LINKER_FILE_SUFFIX:static1>\" \"${CMAKE_STATIC_LIBRARY_SUFFIX}\")\n")
|
||||
|
||||
|
||||
add_executable (exec2 empty.c)
|
||||
set_property (TARGET exec2 PROPERTY SUFFIX exec2_suffix)
|
||||
set_property (TARGET exec2 PROPERTY ENABLE_EXPORTS TRUE)
|
||||
set_property (TARGET exec2 PROPERTY IMPORT_SUFFIX exec2_import_suffix)
|
||||
add_library (shared2 SHARED empty.c)
|
||||
set_property (TARGET shared2 PROPERTY SUFFIX shared2_suffix)
|
||||
set_property (TARGET shared2 PROPERTY IMPORT_SUFFIX shared2_import_suffix)
|
||||
add_library (static2 STATIC empty.c)
|
||||
set_property (TARGET static2 PROPERTY SUFFIX static2_suffix)
|
||||
set_property (TARGET static2 PROPERTY IMPORT_SUFFIX static2_import_suffix)
|
||||
|
||||
string (APPEND GENERATE_CONTENT
|
||||
"\ncheck_value (\"TARGET_FILE_SUFFIX executable custom\" \"$<TARGET_FILE_SUFFIX:exec2>\" \"exec2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX executable linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:exec2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,exec2_import_suffix,exec2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX shared custom\" \"$<TARGET_FILE_SUFFIX:shared2>\" \"shared2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX shared linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:shared2>\" \"$<IF:$<IN_LIST:$<PLATFORM_ID>,${win_platforms}>,shared2_import_suffix,shared2_suffix>\")
|
||||
check_value (\"TARGET_FILE_SUFFIX static custom\" \"$<TARGET_FILE_SUFFIX:static2>\" \"static2_suffix\")
|
||||
check_value (\"TARGET_LINKER_FILE_SUFFIX static linker custom\" \"$<TARGET_LINKER_FILE_SUFFIX:static2>\" \"static2_suffix\")\n")
|
||||
|
||||
|
||||
file (GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_FILE_SUFFIX-generated.cmake"
|
||||
CONTENT "${GENERATE_CONTENT}")
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_LINKER_FILE_PREFIX-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_LINKER_FILE_PREFIX:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_LINKER_FILE_PREFIX:empty>]"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
CMake Error at TARGET_LINKER_FILE_SUFFIX-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_LINKER_FILE_SUFFIX:empty>
|
||||
|
||||
Target "empty" is not an executable or library\.
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
|
||||
CONTENT "[$<TARGET_LINKER_FILE_SUFFIX:empty>]"
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error at TARGET_LINKER_OUTPUT_NAME-non-valid-target.cmake:6 \(file\):
|
||||
CMake Error at TARGET_LINKER_OUTPUT_NAME-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_LINKER_OUTPUT_NAME:empty>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMake Error at TARGET_OUTPUT_NAME-non-valid-target.cmake:6 \(file\):
|
||||
CMake Error at TARGET_OUTPUT_NAME-non-valid-target.cmake:[0-9]+ \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_OUTPUT_NAME:empty>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
|
||||
enable_language(C)
|
||||
|
||||
add_custom_target(empty)
|
||||
|
||||
file(GENERATE
|
||||
|
||||
Reference in New Issue
Block a user