From 1777883f8bcd0fe8cbdf88429d46530a05584a6c Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Tue, 22 Mar 2022 17:07:16 +0100 Subject: genex-LINK_(LIBRARY|GROUP) features: update variables behavior Variable CMAKE_LINK_(LIBRARY|GROUP)_USING__SUPPORTED is evaluated only if CMAKE__LINK_(LIBRARY|GROUP)_USING__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. --- Help/variable/CMAKE_LINK_GROUP_USING_FEATURE.rst | 5 +++-- Help/variable/CMAKE_LINK_GROUP_USING_FEATURE_SUPPORTED.rst | 3 +-- Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE.rst | 5 +++-- Help/variable/CMAKE_LINK_LIBRARY_USING_FEATURE_SUPPORTED.rst | 4 ++-- Source/cmComputeLinkInformation.cxx | 8 ++++++-- Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake | 1 + .../GenEx-LINK_GROUP/multiple-definitions-result.txt | 1 + .../GenEx-LINK_GROUP/multiple-definitions-stderr.txt | 5 +++++ Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions.cmake | 12 ++++++++++++ Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake | 1 + .../GenEx-LINK_LIBRARY/multiple-definitions-result.txt | 1 + .../GenEx-LINK_LIBRARY/multiple-definitions-stderr.txt | 5 +++++ Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions.cmake | 12 ++++++++++++ .../LINK_GROUP-multiple-definitions-result.txt | 1 + .../LINK_GROUP-mutiple-definitions-check.cmake | 4 ++++ .../target_link_libraries-LINK_GROUP/LINK_GROUP.cmake | 7 +++++++ .../target_link_libraries-LINK_GROUP/RunCMakeTest.cmake | 1 + .../target_link_libraries-LINK_LIBRARY/LINK_LIBRARY.cmake | 1 - 18 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-result.txt create mode 100644 Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions-stderr.txt create mode 100644 Tests/RunCMake/GenEx-LINK_GROUP/multiple-definitions.cmake create mode 100644 Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-result.txt create mode 100644 Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions-stderr.txt create mode 100644 Tests/RunCMake/GenEx-LINK_LIBRARY/multiple-definitions.cmake create mode 100644 Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-multiple-definitions-result.txt create mode 100644 Tests/RunCMake/target_link_libraries-LINK_GROUP/LINK_GROUP-mutiple-definitions-check.cmake 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__LINK_GROUP_USING__SUPPORTED` is false or not -set. +:variable:`CMAKE__LINK_GROUP_USING__SUPPORTED` is not defined +and the variable :variable:`CMAKE_LINK_GROUP_USING__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__LINK_GROUP_USING__SUPPORTED` evaluates to - ``FALSE``. + :variable:`CMAKE__LINK_GROUP_USING__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__LINK_LIBRARY_USING__SUPPORTED` is false or not -set. +:variable:`CMAKE__LINK_LIBRARY_USING__SUPPORTED` is not defined +and the variable :variable:`CMAKE_LINK_LIBRARY_USING__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__LINK_LIBRARY_USING__SUPPORTED` evaluates to - ``FALSE``. + :variable:`CMAKE__LINK_LIBRARY_USING__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 '\$' 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 "$") 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 '\$' 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 "") +set(CMAKE_C_LINK_LIBRARY_USING_feat_SUPPORTED FALSE) +set(CMAKE_LINK_LIBRARY_USING_feat "") +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 "$") 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 --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") 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 "$") @@ -31,6 +34,10 @@ add_library(LinkGroup_simple2 SHARED lib.c) target_link_libraries(LinkGroup_simple2 PRIVATE "$") +add_library(LinkGroup_multiple-definitions SHARED lib.c) +target_link_libraries(LinkGroup_multiple-definitions PRIVATE "$") + + add_library(base4 SHARED base.c) target_link_libraries(base4 INTERFACE "$") 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") set(CMAKE_C_LINK_LIBRARY_USING_feat1_SUPPORTED TRUE) set(CMAKE_C_LINK_LIBRARY_USING_feat1_1 "--LIBFLAG_C") -set(CMAKE_C_LINK_LIBRARY_USING_feat1_1_SUPPORTED FALSE) set(CMAKE_LINK_LIBRARY_USING_feat1_1 "--LIBFLAG") set(CMAKE_LINK_LIBRARY_USING_feat1_1_SUPPORTED TRUE) -- cgit v0.12