diff options
24 files changed, 107 insertions, 28 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index f53af3731d..25e581ad21 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -1421,9 +1421,10 @@ Output-Related Expressions * The ``$<LINK_LIBRARY:...>`` generator expression can only be used to specify link libraries. In practice, this means it can appear in the - :prop_tgt:`LINK_LIBRARIES` and :prop_tgt:`INTERFACE_LINK_LIBRARIES` - target properties, and be specified in :command:`target_link_libraries` - and :command:`link_libraries` commands. + :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`, and + :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be + specified in :command:`target_link_libraries` and :command:`link_libraries` + commands. * If a ``$<LINK_LIBRARY:...>`` generator expression appears in the :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be @@ -1596,9 +1597,10 @@ Output-Related Expressions * The ``$<LINK_GROUP:...>`` generator expression can only be used to specify link libraries. In practice, this means it can appear in the - :prop_tgt:`LINK_LIBRARIES` and :prop_tgt:`INTERFACE_LINK_LIBRARIES` - target properties, and be specified in :command:`target_link_libraries` - and :command:`link_libraries` commands. + :prop_tgt:`LINK_LIBRARIES`, :prop_tgt:`INTERFACE_LINK_LIBRARIES`,and + :prop_tgt:`INTERFACE_LINK_LIBRARIES_DIRECT` target properties, and be + specified in :command:`target_link_libraries` and :command:`link_libraries` + commands. * If a ``$<LINK_GROUP:...>`` generator expression appears in the :prop_tgt:`INTERFACE_LINK_LIBRARIES` property of a target, it will be diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx index d35d4289c5..6be5153c22 100644 --- a/Source/cmGeneratorExpressionDAGChecker.cxx +++ b/Source/cmGeneratorExpressionDAGChecker.cxx @@ -178,7 +178,7 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkOptionsExpression() const } bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries( - cmGeneratorTarget const* tgt) const + cmGeneratorTarget const* tgt, ForGenex genex) const { const auto* top = this->Top(); @@ -188,13 +188,17 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries( return top->Target == tgt && prop == "LINK_LIBRARIES"_s; } - return prop == "LINK_LIBRARIES"_s || prop == "INTERFACE_LINK_LIBRARIES"_s || + auto result = prop == "LINK_LIBRARIES"_s || + prop == "INTERFACE_LINK_LIBRARIES"_s || prop == "INTERFACE_LINK_LIBRARIES_DIRECT"_s || - prop == "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s || prop == "LINK_INTERFACE_LIBRARIES"_s || prop == "IMPORTED_LINK_INTERFACE_LIBRARIES"_s || cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES_") || cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES_"); + + return genex == ForGenex::LINK_LIBRARY || genex == ForGenex::LINK_GROUP + ? result + : (result || prop == "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s); } cmGeneratorExpressionDAGChecker const* cmGeneratorExpressionDAGChecker::Top() diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h index 93b44db828..55d131f845 100644 --- a/Source/cmGeneratorExpressionDAGChecker.h +++ b/Source/cmGeneratorExpressionDAGChecker.h @@ -71,7 +71,14 @@ struct cmGeneratorExpressionDAGChecker bool EvaluatingLinkExpression() const; bool EvaluatingLinkOptionsExpression() const; - bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr) const; + enum class ForGenex + { + ANY, + LINK_LIBRARY, + LINK_GROUP + }; + bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr, + ForGenex genex = ForGenex::ANY) const; #define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index d773fdf7f3..45d5a83cf6 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1662,11 +1662,16 @@ static const struct LinkLibraryNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* dagChecker) const override { + using ForGenex = cmGeneratorExpressionDAGChecker::ForGenex; + if (!context->HeadTarget || !dagChecker || - !dagChecker->EvaluatingLinkLibraries()) { + !dagChecker->EvaluatingLinkLibraries(nullptr, + ForGenex::LINK_LIBRARY)) { reportError(context, content->GetOriginalExpression(), "$<LINK_LIBRARY:...> may only be used with binary targets " - "to specify link libraries."); + "to specify link libraries through 'LINK_LIBRARIES', " + "'INTERFACE_LINK_LIBRARIES', and " + "'INTERFACE_LINK_LIBRARIES_DIRECT' properties."); return std::string(); } @@ -1743,11 +1748,16 @@ static const struct LinkGroupNode : public cmGeneratorExpressionNode const GeneratorExpressionContent* content, cmGeneratorExpressionDAGChecker* dagChecker) const override { + using ForGenex = cmGeneratorExpressionDAGChecker::ForGenex; + if (!context->HeadTarget || !dagChecker || - !dagChecker->EvaluatingLinkLibraries()) { - reportError(context, content->GetOriginalExpression(), - "$<LINK_GROUP:...> may only be used with binary targets " - "to specify group of link libraries."); + !dagChecker->EvaluatingLinkLibraries(nullptr, ForGenex::LINK_GROUP)) { + reportError( + context, content->GetOriginalExpression(), + "$<LINK_GROUP:...> may only be used with binary targets " + "to specify group of link libraries through 'LINK_LIBRARIES', " + "'INTERFACE_LINK_LIBRARIES', and " + "'INTERFACE_LINK_LIBRARIES_DIRECT' properties."); return std::string(); } diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake index f20d22596f..f1023d141f 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-LINK_GROUP/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(add_link_options) run_cmake(link_directories) run_cmake(target_link_options) run_cmake(target_link_directories) +run_cmake(invalid-property) run_cmake(no-arguments) run_cmake(empty-arguments) run_cmake(forbidden-arguments) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_command-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_command-stderr.txt index a80a11b1cf..c3eb1036a9 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_command-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_command-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_custom_command.cmake:[0-9]+ \(add_custom_command\): \$<LINK_GROUP:feat> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_target-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_target-stderr.txt index deb246a7b6..8bd07feb1d 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_target-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/add_custom_target-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_custom_target.cmake:[0-9]+ \(add_custom_target\): \$<LINK_GROUP:feat> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/add_link_options-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/add_link_options-stderr.txt index 17c348c9b8..8314461631 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/add_link_options-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/add_link_options-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_link_options.cmake:[0-9]+ \(add_link_options\): \$<LINK_GROUP:feat> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-result.txt b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-stderr.txt new file mode 100644 index 0000000000..f39d275ade --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property-stderr.txt @@ -0,0 +1,10 @@ +CMake Error at invalid-property.cmake:[0-9]+ \(set_property\): + Error evaluating generator expression: + + \$<LINK_GROUP:feat,dep> + + \$<LINK_GROUP:...> may only be used with binary targets to specify group of + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property.cmake b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property.cmake new file mode 100644 index 0000000000..549f4c148a --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_GROUP/invalid-property.cmake @@ -0,0 +1,10 @@ +enable_language(C) + +set (CMAKE_LINK_GROUP_USING_feat "--prefix" "--suffix") +set (CMAKE_LINK_GROUP_USING_feat_SUPPORTED TRUE) + +add_library(dep SHARED empty.c) +set_property(TARGET dep PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE "$<LINK_GROUP:feat,dep>") + +add_library(lib SHARED empty.c) +target_link_libraries(lib PRIVATE dep) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/link_directories-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/link_directories-stderr.txt index 51194a4220..1ee01f3c24 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/link_directories-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/link_directories-stderr.txt @@ -4,6 +4,7 @@ CMake Error at link_directories.cmake:[0-9]+ \(link_directories\): \$<LINK_GROUP:feat> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/target_link_directories-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/target_link_directories-stderr.txt index 042dd0b1de..58a8fc4cd4 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/target_link_directories-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/target_link_directories-stderr.txt @@ -4,6 +4,7 @@ CMake Error at target_link_directories.cmake:[0-9]+ \(target_link_directories\): \$<LINK_GROUP:feat> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_GROUP/target_link_options-stderr.txt b/Tests/RunCMake/GenEx-LINK_GROUP/target_link_options-stderr.txt index 7030b9c10c..910106c738 100644 --- a/Tests/RunCMake/GenEx-LINK_GROUP/target_link_options-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_GROUP/target_link_options-stderr.txt @@ -4,6 +4,7 @@ CMake Error at target_link_options.cmake:[0-9]+ \(target_link_options\): \$<LINK_GROUP:FEAT> \$<LINK_GROUP:...> may only be used with binary targets to specify group of - link libraries. + link libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake index 3fb68d6edb..7df0e80e24 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/RunCMakeTest.cmake @@ -6,6 +6,7 @@ run_cmake(add_link_options) run_cmake(link_directories) run_cmake(target_link_options) run_cmake(target_link_directories) +run_cmake(invalid-property) run_cmake(no-arguments) run_cmake(empty-arguments) run_cmake(forbidden-arguments) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_command-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_command-stderr.txt index d8ff0eb3bb..a9c3842b13 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_command-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_command-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_custom_command.cmake:[0-9]+ \(add_custom_command\): \$<LINK_LIBRARY:feat> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_target-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_target-stderr.txt index 8ca384d946..95104a54fa 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_target-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_custom_target-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_custom_target.cmake:[0-9]+ \(add_custom_target\): \$<LINK_LIBRARY:feat> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_link_options-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_link_options-stderr.txt index 399a413929..f8669adb5d 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/add_link_options-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/add_link_options-stderr.txt @@ -4,6 +4,7 @@ CMake Error at add_link_options.cmake:[0-9]+ \(add_link_options\): \$<LINK_LIBRARY:feat> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-result.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-stderr.txt new file mode 100644 index 0000000000..7410e489ac --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property-stderr.txt @@ -0,0 +1,10 @@ +CMake Error at invalid-property.cmake:[0-9]+ \(set_property\): + Error evaluating generator expression: + + \$<LINK_LIBRARY:feat,dep> + + \$<LINK_LIBRARY:...> may only be used with binary targets to specify link + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property.cmake b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property.cmake new file mode 100644 index 0000000000..a8e3a5751c --- /dev/null +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/invalid-property.cmake @@ -0,0 +1,10 @@ +enable_language(C) + +set (CMAKE_LINK_LIBRARY_USING_feat "<LIBRARY>") +set (CMAKE_LINK_LIBRARY_USING_feat_SUPPORTED TRUE) + +add_library(dep SHARED empty.c) +set_property(TARGET dep PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE "$<LINK_LIBRARY:feat,dep>") + +add_library(lib SHARED empty.c) +target_link_libraries(lib PRIVATE dep) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/link_directories-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/link_directories-stderr.txt index aeb32f2910..e47bf04b3a 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/link_directories-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/link_directories-stderr.txt @@ -4,6 +4,7 @@ CMake Error at link_directories.cmake:[0-9]+ \(link_directories\): \$<LINK_LIBRARY:feat> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_directories-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_directories-stderr.txt index e0c60c4e87..7c467fdb51 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_directories-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_directories-stderr.txt @@ -4,6 +4,7 @@ CMake Error at target_link_directories.cmake:[0-9]+ \(target_link_directories\): \$<LINK_LIBRARY:feat> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_options-stderr.txt b/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_options-stderr.txt index 6c9aab111c..02805b7ecc 100644 --- a/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_options-stderr.txt +++ b/Tests/RunCMake/GenEx-LINK_LIBRARY/target_link_options-stderr.txt @@ -4,6 +4,7 @@ CMake Error at target_link_options.cmake:[0-9]+ \(target_link_options\): \$<LINK_LIBRARY:FEAT> \$<LINK_LIBRARY:...> may only be used with binary targets to specify link - libraries. + libraries through 'LINK_LIBRARIES', 'INTERFACE_LINK_LIBRARIES', and + 'INTERFACE_LINK_LIBRARIES_DIRECT' properties. Call Stack \(most recent call first\): CMakeLists.txt:[0-9]+ \(include\) |