diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2022-03-22 16:07:16 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2022-03-25 11:29:28 (GMT) |
commit | 1777883f8bcd0fe8cbdf88429d46530a05584a6c (patch) | |
tree | 04adb9a611b1fb38edff3522aef89e1a1041e3d1 | |
parent | 232884345078a89d7f29fea2900be34c178bc10c (diff) | |
download | CMake-1777883f8bcd0fe8cbdf88429d46530a05584a6c.zip CMake-1777883f8bcd0fe8cbdf88429d46530a05584a6c.tar.gz CMake-1777883f8bcd0fe8cbdf88429d46530a05584a6c.tar.bz2 |
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.
18 files changed, 66 insertions, 11 deletions
diff --git a/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE.rst b/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE.rst index fad1837..692c099 100644 --- a/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE.rst +++ b/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE.rst @@ -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 diff --git a/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED.rst b/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED.rst index 249ccbc..318892f 100644 --- a/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED.rst +++ b/Help/variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED.rst @@ -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. diff --git a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst index 05de570..9f1cede 100644 --- a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst +++ b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst @@ -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 diff --git a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED.rst b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED.rst index 42b75fc..417724b 100644 --- a/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED.rst +++ b/Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED.rst @@ -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. diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 67214f1..a1ffc82 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -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")); diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake index 98eef35..f20d225 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-result.txt b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-stderr.txt new file mode 100644 index 0000000..995f363 --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions.cmake b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions.cmake new file mode 100644 index 0000000..a021d44 --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions.cmake @@ -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>") diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake index 9c266fe..3fb68d6 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-result.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-stderr.txt new file mode 100644 index 0000000..26b0bac --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-stderr.txt @@ -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\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions.cmake b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions.cmake new file mode 100644 index 0000000..1bd1888 --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions.cmake @@ -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>") diff --git a/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-multiple-definitions-result.txt b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-multiple-definitions-result.txt new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-multiple-definitions-result.txt @@ -0,0 +1 @@ +.* diff --git a/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-mutiple-definitions-check.cmake b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-mutiple-definitions-check.cmake new file mode 100644 index 0000000..3e53d26 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-mutiple-definitions-check.cmake @@ -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() diff --git a/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP.cmake b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP.cmake index d08db16..31eb7e2 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP.cmake +++ b/Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP.cmake @@ -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) diff --git a/Tests/RunCMake/target_link_libraries-LINK_GROUP/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-LINK_GROUP/RunCMakeTest.cmake index 400905c..c1d74d0 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_GROUP/RunCMakeTest.cmake +++ b/Tests/RunCMake/target_link_libraries-LINK_GROUP/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/LINK_LIBRARY.cmake b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/LINK_LIBRARY.cmake index 1581611..f19112a 100644 --- a/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/LINK_LIBRARY.cmake +++ b/Tests/RunCMake/target_link_libraries-LINK_LIBRARY/LINK_LIBRARY.cmake @@ -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) |