GenEx: Add generator expr. for CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT
This commit is contained in:
parent
8a11a39c51
commit
af81b8667e
@ -1037,10 +1037,11 @@ closely related to the expressions in this sub-section.
|
||||
|
||||
``1`` if the version of the ISPC compiler matches ``version``, otherwise ``0``.
|
||||
|
||||
Compiler Language And ID
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Compiler Language, ID, and Frontend-Variant
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable, which is closely
|
||||
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` and
|
||||
:variable:`CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT` variables, which are closely
|
||||
related to most of the expressions in this sub-section.
|
||||
|
||||
.. genex:: $<C_COMPILER_ID>
|
||||
@ -1155,6 +1156,118 @@ related to most of the expressions in this sub-section.
|
||||
``1`` if CMake's compiler id of the ISPC compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<C_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler frontend variant of the C compiler used.
|
||||
|
||||
.. genex:: $<C_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the C compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<CXX_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler frontend variant of the C++ compiler used.
|
||||
|
||||
.. genex:: $<CXX_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the C++ compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<CUDA_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler id of the CUDA compiler used.
|
||||
|
||||
.. genex:: $<CUDA_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the CUDA compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<OBJC_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler frontend variant of the Objective-C compiler used.
|
||||
|
||||
.. genex:: $<OBJC_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the Objective-C compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<OBJCXX_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler frontend variant of the Objective-C++ compiler used.
|
||||
|
||||
.. genex:: $<OBJCXX_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the Objective-C++ compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<Fortran_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler id of the Fortran compiler used.
|
||||
|
||||
.. genex:: $<Fortran_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the Fortran compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<HIP_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler id of the HIP compiler used.
|
||||
|
||||
.. genex:: $<HIP_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the HIP compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<ISPC_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
CMake's compiler id of the ISPC compiler used.
|
||||
|
||||
.. genex:: $<ISPC_COMPILER_FRONTEND_VARIANT:compiler_ids>
|
||||
|
||||
.. versionadded:: 3.30
|
||||
|
||||
where ``compiler_ids`` is a comma-separated list.
|
||||
``1`` if CMake's compiler frontend variant of the ISPC compiler matches any one
|
||||
of the entries in ``compiler_ids``, otherwise ``0``.
|
||||
|
||||
.. genex:: $<COMPILE_LANGUAGE>
|
||||
|
||||
.. versionadded:: 3.3
|
||||
|
6
Help/release/dev/genex-compiler-frontend-variant.rst
Normal file
6
Help/release/dev/genex-compiler-frontend-variant.rst
Normal file
@ -0,0 +1,6 @@
|
||||
genex-compiler-frontent-variant
|
||||
-------------------------------
|
||||
|
||||
* Generator expressions ``$<<LANG>_COMPILER_FRONTEND_VARIANT:...>`` were added that allow
|
||||
access to the value of the associated :variable:`CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT`
|
||||
variables.
|
@ -2013,6 +2013,76 @@ static const CompilerVersionNode cCompilerVersionNode("C"),
|
||||
fortranCompilerVersionNode("Fortran"), ispcCompilerVersionNode("ISPC"),
|
||||
hipCompilerVersionNode("HIP");
|
||||
|
||||
struct CompilerFrontendVariantNode : public cmGeneratorExpressionNode
|
||||
{
|
||||
CompilerFrontendVariantNode(const char* compilerLang)
|
||||
: CompilerLanguage(compilerLang)
|
||||
{
|
||||
}
|
||||
|
||||
int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
|
||||
|
||||
std::string Evaluate(
|
||||
const std::vector<std::string>& parameters,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content,
|
||||
cmGeneratorExpressionDAGChecker* dagChecker) const override
|
||||
{
|
||||
if (!context->HeadTarget) {
|
||||
std::ostringstream e;
|
||||
e << "$<" << this->CompilerLanguage
|
||||
<< "_COMPILER_FRONTEND_VARIANT> may only be used with binary targets. "
|
||||
" It may not be used with add_custom_command or add_custom_target.";
|
||||
reportError(context, content->GetOriginalExpression(), e.str());
|
||||
return {};
|
||||
}
|
||||
return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
|
||||
this->CompilerLanguage);
|
||||
}
|
||||
|
||||
std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content,
|
||||
cmGeneratorExpressionDAGChecker* /*unused*/,
|
||||
const std::string& lang) const
|
||||
{
|
||||
std::string const& compilerFrontendVariant =
|
||||
context->LG->GetMakefile()->GetSafeDefinition(
|
||||
"CMAKE_" + lang + "_COMPILER_FRONTEND_VARIANT");
|
||||
if (parameters.empty()) {
|
||||
return compilerFrontendVariant;
|
||||
}
|
||||
if (compilerFrontendVariant.empty()) {
|
||||
return parameters.front().empty() ? "1" : "0";
|
||||
}
|
||||
static cmsys::RegularExpression compilerFrontendVariantValidator(
|
||||
"^[A-Za-z0-9_]*$");
|
||||
|
||||
for (auto const& param : parameters) {
|
||||
if (!compilerFrontendVariantValidator.find(param)) {
|
||||
reportError(context, content->GetOriginalExpression(),
|
||||
"Expression syntax not recognized.");
|
||||
return {};
|
||||
}
|
||||
if (strcmp(param.c_str(), compilerFrontendVariant.c_str()) == 0) {
|
||||
return "1";
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
const char* const CompilerLanguage;
|
||||
};
|
||||
|
||||
static const CompilerFrontendVariantNode cCompilerFrontendVariantNode("C"),
|
||||
cxxCompilerFrontendVariantNode("CXX"),
|
||||
cudaCompilerFrontendVariantNode("CUDA"),
|
||||
objcCompilerFrontendVariantNode("OBJC"),
|
||||
objcxxCompilerFrontendVariantNode("OBJCXX"),
|
||||
fortranCompilerFrontendVariantNode("Fortran"),
|
||||
hipCompilerFrontendVariantNode("HIP"),
|
||||
ispcCompilerFrontendVariantNode("ISPC");
|
||||
|
||||
struct PlatformIdNode : public cmGeneratorExpressionNode
|
||||
{
|
||||
PlatformIdNode() {} // NOLINT(modernize-use-equals-default)
|
||||
@ -4449,6 +4519,14 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
|
||||
{ "OBJCXX_COMPILER_VERSION", &objcxxCompilerVersionNode },
|
||||
{ "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
|
||||
{ "HIP_COMPILER_VERSION", &hipCompilerVersionNode },
|
||||
{ "C_COMPILER_FRONTEND_VARIANT", &cCompilerFrontendVariantNode },
|
||||
{ "CXX_COMPILER_FRONTEND_VARIANT", &cxxCompilerFrontendVariantNode },
|
||||
{ "CUDA_COMPILER_FRONTEND_VARIANT", &cudaCompilerFrontendVariantNode },
|
||||
{ "OBJC_COMPILER_FRONTEND_VARIANT", &objcCompilerFrontendVariantNode },
|
||||
{ "OBJCXX_COMPILER_FRONTEND_VARIANT", &objcxxCompilerFrontendVariantNode },
|
||||
{ "Fortran_COMPILER_FRONTEND_VARIANT",
|
||||
&fortranCompilerFrontendVariantNode },
|
||||
{ "HIP_COMPILER_FRONTEND_VARIANT", &hipCompilerFrontendVariantNode },
|
||||
{ "PLATFORM_ID", &platformIdNode },
|
||||
{ "COMPILE_FEATURES", &compileFeaturesNode },
|
||||
{ "CONFIGURATION", &configurationNode },
|
||||
|
@ -22,6 +22,8 @@ add_executable(CompileOptions main.cpp)
|
||||
macro(get_compiler_test_genex lst lang)
|
||||
list(APPEND ${lst} -DTEST_${lang}_COMPILER_VERSION="$<${lang}_COMPILER_VERSION>")
|
||||
list(APPEND ${lst} -DTEST_${lang}_COMPILER_VERSION_EQUALITY=$<${lang}_COMPILER_VERSION:${CMAKE_${lang}_COMPILER_VERSION}>)
|
||||
list(APPEND ${lst} -DTEST_${lang}_COMPILER_FRONTEND_VARIANT="$<${lang}_COMPILER_FRONTEND_VARIANT>")
|
||||
list(APPEND ${lst} -DTEST_${lang}_COMPILER_FRONTEND_VARIANT_EQUALITY=$<${lang}_COMPILER_FRONTEND_VARIANT:${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}>)
|
||||
endmacro()
|
||||
|
||||
get_compiler_test_genex(c_tests C)
|
||||
@ -91,6 +93,8 @@ target_compile_definitions(CompileOptions
|
||||
PRIVATE
|
||||
"EXPECTED_C_COMPILER_VERSION=\"${CMAKE_C_COMPILER_VERSION}\""
|
||||
"EXPECTED_CXX_COMPILER_VERSION=\"${CMAKE_CXX_COMPILER_VERSION}\""
|
||||
"EXPECTED_C_COMPILER_FRONTEND_VARIANT=\"${CMAKE_C_COMPILER_FRONTEND_VARIANT}\""
|
||||
"EXPECTED_CXX_COMPILER_FRONTEND_VARIANT=\"${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}\""
|
||||
)
|
||||
|
||||
if(TEST_FORTRAN)
|
||||
@ -99,5 +103,6 @@ if(TEST_FORTRAN)
|
||||
PRIVATE
|
||||
"TEST_FORTRAN"
|
||||
"EXPECTED_Fortran_COMPILER_VERSION=\"${CMAKE_Fortran_COMPILER_VERSION}\""
|
||||
"EXPECTED_Fortran_COMPILER_FRONTEND_VARIANT=\"${CMAKE_Fortran_COMPILER_FRONTEND_VARIANT}\""
|
||||
)
|
||||
endif()
|
||||
|
@ -68,15 +68,25 @@ int main()
|
||||
#endif
|
||||
&&
|
||||
strcmp(EXPECTED_C_COMPILER_VERSION, TEST_C_COMPILER_VERSION) == 0 &&
|
||||
strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION) == 0
|
||||
strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION) ==
|
||||
0 &&
|
||||
strcmp(EXPECTED_C_COMPILER_FRONTEND_VARIANT,
|
||||
TEST_C_COMPILER_FRONTEND_VARIANT) == 0 &&
|
||||
strcmp(EXPECTED_CXX_COMPILER_FRONTEND_VARIANT,
|
||||
TEST_CXX_COMPILER_FRONTEND_VARIANT) == 0
|
||||
#ifdef TEST_FORTRAN
|
||||
&& strcmp(EXPECTED_Fortran_COMPILER_VERSION,
|
||||
TEST_Fortran_COMPILER_VERSION) == 0
|
||||
TEST_Fortran_COMPILER_VERSION) == 0 &&
|
||||
strcmp(EXPECTED_Fortran_COMPILER_FRONTEND_VARIANT,
|
||||
TEST_Fortran_COMPILER_FRONTEND_VARIANT) == 0
|
||||
#endif
|
||||
&& TEST_C_COMPILER_VERSION_EQUALITY == 1 &&
|
||||
TEST_CXX_COMPILER_VERSION_EQUALITY == 1
|
||||
TEST_CXX_COMPILER_VERSION_EQUALITY == 1 &&
|
||||
TEST_C_COMPILER_FRONTEND_VARIANT_EQUALITY == 1 &&
|
||||
TEST_CXX_COMPILER_FRONTEND_VARIANT_EQUALITY == 1
|
||||
#ifdef TEST_FORTRAN
|
||||
&& TEST_Fortran_COMPILER_VERSION_EQUALITY == 1
|
||||
&& TEST_Fortran_COMPILER_VERSION_EQUALITY == 1 &&
|
||||
TEST_Fortran_COMPILER_FRONTEND_VARIANT_EQUALITY == 1
|
||||
#endif
|
||||
)
|
||||
? 0
|
||||
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,9 @@
|
||||
CMake Error at NonValidTarget-CXX_COMPILER_FRONTEND_VARIANT.cmake:1 \(add_custom_command\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<CXX_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
\$<CXX_COMPILER_FRONTEND_VARIANT> may only be used with binary targets. It
|
||||
may not be used with add_custom_command or add_custom_target.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
@ -0,0 +1,4 @@
|
||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<CXX_COMPILER_FRONTEND_VARIANT>.cpp"
|
||||
)
|
||||
add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,9 @@
|
||||
CMake Error at NonValidTarget-C_COMPILER_FRONTEND_VARIANT.cmake:1 \(add_custom_command\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<C_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
\$<C_COMPILER_FRONTEND_VARIANT> may only be used with binary targets. It
|
||||
may not be used with add_custom_command or add_custom_target.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
@ -0,0 +1,4 @@
|
||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<C_COMPILER_FRONTEND_VARIANT>.cpp"
|
||||
)
|
||||
add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,9 @@
|
||||
CMake Error at NonValidTarget-Fortran_COMPILER_FRONTEND_VARIANT.cmake:1 \(add_custom_command\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<Fortran_COMPILER_FRONTEND_VARIANT>
|
||||
|
||||
\$<Fortran_COMPILER_FRONTEND_VARIANT> may only be used with binary targets.
|
||||
It may not be used with add_custom_command or add_custom_target.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:3 \(include\)
|
@ -0,0 +1,4 @@
|
||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<Fortran_COMPILER_FRONTEND_VARIANT>.cpp"
|
||||
)
|
||||
add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
|
@ -20,6 +20,9 @@ run_cmake(NonValidTarget-Fortran_COMPILER_ID)
|
||||
run_cmake(NonValidTarget-C_COMPILER_VERSION)
|
||||
run_cmake(NonValidTarget-CXX_COMPILER_VERSION)
|
||||
run_cmake(NonValidTarget-Fortran_COMPILER_VERSION)
|
||||
run_cmake(NonValidTarget-C_COMPILER_FRONTEND_VARIANT)
|
||||
run_cmake(NonValidTarget-CXX_COMPILER_FRONTEND_VARIANT)
|
||||
run_cmake(NonValidTarget-Fortran_COMPILER_FRONTEND_VARIANT)
|
||||
run_cmake(NonValidTarget-TARGET_PROPERTY)
|
||||
run_cmake(NonValidTarget-TARGET_POLICY)
|
||||
run_cmake(COMPILE_ONLY-not-compiling)
|
||||
|
Loading…
Reference in New Issue
Block a user