genex-LINK_(LIBRARY|GROUP) features: update variables behavior

Variable CMAKE_LINK_(LIBRARY|GROUP)_USING_<FEATURE>_SUPPORTED is evaluated
only if CMAKE_<LANG>_LINK_(LIBRARY|GROUP)_USING_<FEATURE>_SUPPORTED is not defined.

This new behavior enable to activate a feature globally on a platform and to disable
it for some compilers and languages.
This commit is contained in:
Marc Chevrier
2022-03-22 17:07:16 +01:00
parent 2328843450
commit 1777883f8b
18 changed files with 66 additions and 11 deletions
@@ -19,8 +19,9 @@ of features dependent from the link language.
This variable will be used by :genex:`LINK_GROUP` generator expression if,
for the linker language, the variable
:variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` is false or not
set.
:variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` is not defined
and the variable :variable:`CMAKE_LINK_GROUP_USING_<FEATURE>_SUPPORTED` is
``TRUE``..
.. include:: CMAKE_LINK_GROUP_USING_FEATURE.txt
@@ -10,5 +10,4 @@ linker language.
.. note::
This variable is evaluated if, and only if, the variable
:variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` evaluates to
``FALSE``.
:variable:`CMAKE_<LANG>_LINK_GROUP_USING_<FEATURE>_SUPPORTED` is not defined.
@@ -19,8 +19,9 @@ definition of features dependent from the link language.
This variable will be used by :genex:`LINK_LIBRARY` generator expression if,
for the linker language, the variable
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` is false or not
set.
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` is not defined
and the variable :variable:`CMAKE_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` is
``TRUE``.
.. include:: CMAKE_LINK_LIBRARY_USING_FEATURE.txt
@@ -10,5 +10,5 @@ linker language.
.. note::
This variable is evaluated if, and only if, the variable
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` evaluates to
``FALSE``.
:variable:`CMAKE_<LANG>_LINK_LIBRARY_USING_<FEATURE>_SUPPORTED` is not
defined.
+6 -2
View File
@@ -803,7 +803,9 @@ bool cmComputeLinkInformation::AddLibraryFeature(std::string const& feature)
cmStrCat("CMAKE_", this->LinkLanguage, "_LINK_LIBRARY_USING_", feature);
cmValue featureSupported =
this->Makefile->GetDefinition(cmStrCat(featureName, "_SUPPORTED"));
if (!featureSupported.IsOn()) {
if (!featureSupported) {
// language specific variable is not defined, fallback to the more generic
// one
featureName = cmStrCat("CMAKE_LINK_LIBRARY_USING_", feature);
featureSupported =
this->Makefile->GetDefinition(cmStrCat(featureName, "_SUPPORTED"));
@@ -965,7 +967,9 @@ cmComputeLinkInformation::GetGroupFeature(std::string const& feature)
cmStrCat("CMAKE_", this->LinkLanguage, "_LINK_GROUP_USING_", feature);
cmValue featureSupported =
this->Makefile->GetDefinition(cmStrCat(featureName, "_SUPPORTED"));
if (!featureSupported.IsOn()) {
if (!featureSupported) {
// language specific variable is not defined, fallback to the more generic
// one
featureName = cmStrCat("CMAKE_LINK_GROUP_USING_", feature);
featureSupported =
this->Makefile->GetDefinition(cmStrCat(featureName, "_SUPPORTED"));
@@ -11,6 +11,7 @@ run_cmake(empty-arguments)
run_cmake(forbidden-arguments)
run_cmake(nested-incompatible-genex)
run_cmake(invalid-feature)
run_cmake(multiple-definitions)
run_cmake(bad-feature1)
run_cmake(bad-feature2)
run_cmake(bad-feature3)
@@ -0,0 +1 @@
1
@@ -0,0 +1,5 @@
CMake Error at multiple-definitions.cmake:[0-9]+ \(add_library\):
Feature 'feat', specified through generator-expression '\$<LINK_GROUP>' to
link target 'lib', is not supported for the 'C' link language.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
@@ -0,0 +1,12 @@
enable_language(C)
# Language specific definition takes precedence over more generic one
set(CMAKE_C_LINK_GROUP_USING_feat "-BEFORE" "-AFTER")
set(CMAKE_C_LINK_GROUP_USING_feat_SUPPORTED FALSE)
set(CMAKE_LINK_GROUP_USING_feat "-BEFORE" "-AFTER")
set(CMAKE_LINK_GROUP_USING_feat_SUPPORTED TRUE)
add_library(dep SHARED empty.c)
add_library(lib SHARED empty.c)
target_link_libraries(lib PRIVATE "$<LINK_GROUP:feat,dep>")
@@ -10,6 +10,7 @@ run_cmake(no-arguments)
run_cmake(empty-arguments)
run_cmake(forbidden-arguments)
run_cmake(invalid-feature)
run_cmake(multiple-definitions)
run_cmake(bad-feature1)
run_cmake(bad-feature2)
run_cmake(bad-feature3)
@@ -0,0 +1,5 @@
CMake Error at multiple-definitions.cmake:[0-9]+ \(add_library\):
Feature 'feat', specified through generator-expression '\$<LINK_LIBRARY>' to
link target 'lib', is not supported for the 'C' link language.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
@@ -0,0 +1,12 @@
enable_language(C)
# Language specific definition takes precedence over more generic one
set(CMAKE_C_LINK_LIBRARY_USING_feat "<LIBRARY>")
set(CMAKE_C_LINK_LIBRARY_USING_feat_SUPPORTED FALSE)
set(CMAKE_LINK_LIBRARY_USING_feat "<LIBRARY>")
set(CMAKE_LINK_LIBRARY_USING_feat_SUPPORTED TRUE)
add_library(dep SHARED empty.c)
add_library(lib SHARED empty.c)
target_link_libraries(lib PRIVATE "$<LINK_LIBRARY:feat,dep>")
@@ -0,0 +1,4 @@
if (NOT actual_stdout MATCHES "(/|-)-START_GROUP\"? +.*${LINK_SHARED_LIBRARY_PREFIX}base1${LINK_SHARED_LIBRARY_SUFFIX} +.*${LINK_SHARED_LIBRARY_PREFIX}base2${LINK_SHARED_LIBRARY_SUFFIX} +\"?(/|-)-END_GROUP")
set (RunCMake_TEST_FAILED "Not found expected '--START_GROUP <base1> <base2> --END_GROUP'.")
endif()
@@ -20,6 +20,9 @@ set(CMAKE_C_LINK_GROUP_USING_feat1_SUPPORTED TRUE)
set(CMAKE_C_LINK_LIBRARY_USING_feat1 "--LIBFLAG<LIBRARY>")
set(CMAKE_C_LINK_LIBRARY_USING_feat1_SUPPORTED TRUE)
set(CMAKE_C_LINK_GROUP_USING_feat2 "--START_GROUP" "--END_GROUP")
set(CMAKE_LINK_GROUP_USING_feat2 "--START_GROUP" "--END_GROUP")
set(CMAKE_LINK_GROUP_USING_feat2_SUPPORTED TRUE)
add_library(LinkGroup_simple1 SHARED lib.c)
target_link_libraries(LinkGroup_simple1 PRIVATE "$<LINK_GROUP:feat1,base1,base2>")
@@ -31,6 +34,10 @@ add_library(LinkGroup_simple2 SHARED lib.c)
target_link_libraries(LinkGroup_simple2 PRIVATE "$<LINK_GROUP:feat1,base2,base3>")
add_library(LinkGroup_multiple-definitions SHARED lib.c)
target_link_libraries(LinkGroup_multiple-definitions PRIVATE "$<LINK_GROUP:feat2,base1,base2>")
add_library(base4 SHARED base.c)
target_link_libraries(base4 INTERFACE "$<LINK_GROUP:feat1,base1,base2>")
add_library(LinkGroup_multiple-groups SHARED lib.c)
@@ -42,6 +42,7 @@ if ((RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Xcode"
run_cmake_target(LINK_GROUP simple1 LinkGroup_simple1)
run_cmake_target(LINK_GROUP simple2 LinkGroup_simple2)
run_cmake_target(LINK_GROUP multiple-definitions LinkGroup_multiple-definitions)
run_cmake_target(LINK_GROUP multiple-groups LinkGroup_multiple-groups)
run_cmake_target(LINK_GROUP group-and-single LinkGroup_group-and-single)
run_cmake_target(LINK_GROUP with-LINK_LIBRARY LinkGroup_with-LINK_LIBRARY)
@@ -16,7 +16,6 @@ set(CMAKE_C_LINK_LIBRARY_USING_feat1 "--LIBFLAG<LIBRARY>")
set(CMAKE_C_LINK_LIBRARY_USING_feat1_SUPPORTED TRUE)
set(CMAKE_C_LINK_LIBRARY_USING_feat1_1 "--LIBFLAG_C<LIBRARY>")
set(CMAKE_C_LINK_LIBRARY_USING_feat1_1_SUPPORTED FALSE)
set(CMAKE_LINK_LIBRARY_USING_feat1_1 "--LIBFLAG<LIBRARY>")
set(CMAKE_LINK_LIBRARY_USING_feat1_1_SUPPORTED TRUE)