From 0400cd5dd1be33ebcc2c2d5dba8233a78b1cee68 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Jul 2014 11:14:49 -0400 Subject: Make $ available to projects (#14751) Previously this generator expression was used internally by the target_link_libraries command to honor private linking requirements of static libraries in their INTERFACE_LINK_LIBRARIES. Remove the check that limits $ to this use case to make it available for project code to use too. --- Help/manual/cmake-generator-expressions.7.rst | 7 +++++++ Source/cmTarget.cxx | 14 +++----------- Tests/InterfaceLinkLibraries/CMakeLists.txt | 12 ++++++++++++ Tests/InterfaceLinkLibraries/main.cpp | 8 ++++++-- Tests/InterfaceLinkLibraries/zot.cpp | 6 ++++++ Tests/InterfaceLinkLibraries/zot.h | 7 +++++++ Tests/InterfaceLinkLibraries/zot_vs6_1.cpp | 1 + Tests/InterfaceLinkLibraries/zot_vs6_2.cpp | 1 + Tests/InterfaceLinkLibraries/zot_vs6_3.cpp | 1 + Tests/InterfaceLinkLibraries/zot_vs6_4.cpp | 1 + 10 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 Tests/InterfaceLinkLibraries/zot.cpp create mode 100644 Tests/InterfaceLinkLibraries/zot.h create mode 100644 Tests/InterfaceLinkLibraries/zot_vs6_1.cpp create mode 100644 Tests/InterfaceLinkLibraries/zot_vs6_2.cpp create mode 100644 Tests/InterfaceLinkLibraries/zot_vs6_3.cpp create mode 100644 Tests/InterfaceLinkLibraries/zot_vs6_4.cpp diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index 9e82674..bc24798 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -188,6 +188,13 @@ property is non-empty:: Marks ``...`` as being the name of a target. This is required if exporting targets to multiple dependent export sets. The ``...`` must be a literal name of a target- it may not contain generator expressions. +``$`` + Content of ``...`` except when evaluated in a link interface while + propagating :ref:`Target Usage Requirements`, in which case it is the + empty string. + Intended for use only in an :prop_tgt:`INTERFACE_LINK_LIBRARIES` target + property, perhaps via the :command:`target_link_libraries` command, + to specify private link dependencies without other usage requirements. ``$`` Content of ``...`` when the property is exported using :command:`install(EXPORT)`, and empty otherwise. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index b4688c4..ffdeb6a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3555,6 +3555,8 @@ void cmTarget::ExpandLinkItems(std::string const& prop, { cmGeneratorExpression ge; cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0); + // The $ expression may be in a link interface to specify private + // link dependencies that are otherwise excluded from usage requirements. if(usage_requirements_only) { dagChecker.SetTransitivePropertiesOnly(); @@ -6057,18 +6059,8 @@ void cmTarget::GetTransitivePropertyTargets(const std::string& config, cmTarget const* headTarget, std::vector &tgts) const { - // The $ expression may be in a link interface to specify private - // link dependencies that are otherwise excluded from usage requirements. - // Currently $ is internal to CMake and only ever added by - // target_link_libraries for PRIVATE dependencies of STATIC libraries in - // INTERFACE_LINK_LIBRARIES which is used under CMP0022 NEW behavior. - bool usage_requirements_only = - this->GetType() == STATIC_LIBRARY && - this->GetPolicyStatusCMP0022() != cmPolicies::WARN && - this->GetPolicyStatusCMP0022() != cmPolicies::OLD; if(cmTarget::LinkInterface const* iface = - this->GetLinkInterfaceLibraries(config, headTarget, - usage_requirements_only)) + this->GetLinkInterfaceLibraries(config, headTarget, true)) { for(std::vector::const_iterator it = iface->Libraries.begin(); it != iface->Libraries.end(); ++it) diff --git a/Tests/InterfaceLinkLibraries/CMakeLists.txt b/Tests/InterfaceLinkLibraries/CMakeLists.txt index bd0cf74..9e14c44 100644 --- a/Tests/InterfaceLinkLibraries/CMakeLists.txt +++ b/Tests/InterfaceLinkLibraries/CMakeLists.txt @@ -9,6 +9,9 @@ target_compile_definitions(foo_shared INTERFACE FOO_LIBRARY) add_library(bar_shared SHARED bar_vs6_1.cpp) target_compile_definitions(bar_shared INTERFACE BAR_LIBRARY) set_property(TARGET bar_shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_shared) +add_library(zot_shared SHARED zot_vs6_1.cpp) +target_compile_definitions(zot_shared INTERFACE ZOT_LIBRARY) +set_property(TARGET bar_shared APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) add_executable(shared_test main_vs6_1.cpp) set_property(TARGET shared_test APPEND PROPERTY LINK_LIBRARIES bar_shared) @@ -18,6 +21,9 @@ target_compile_definitions(foo_static INTERFACE FOO_LIBRARY) add_library(bar_static STATIC bar_vs6_2.cpp) target_compile_definitions(bar_static INTERFACE BAR_LIBRARY) set_property(TARGET bar_static APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_static) +add_library(zot_static STATIC zot_vs6_2.cpp) +target_compile_definitions(zot_static INTERFACE ZOT_LIBRARY) +set_property(TARGET bar_static APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) add_executable(static_test main_vs6_2.cpp) set_property(TARGET static_test APPEND PROPERTY LINK_LIBRARIES bar_static) @@ -31,6 +37,9 @@ target_compile_definitions(bar_shared_private INTERFACE BAR_LIBRARY) target_compile_definitions(bar_shared_private PRIVATE BAR_USE_BANG) set_property(TARGET bar_shared_private APPEND PROPERTY LINK_LIBRARIES bang_shared_private) set_property(TARGET bar_shared_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES foo_shared_private) +add_library(zot_shared_private SHARED zot_vs6_3.cpp) +target_compile_definitions(zot_shared_private INTERFACE ZOT_LIBRARY) +set_property(TARGET bar_shared_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) add_executable(shared_private_test main_vs6_3.cpp) set_property(TARGET shared_private_test APPEND PROPERTY LINK_LIBRARIES bar_shared_private) @@ -44,6 +53,9 @@ target_compile_definitions(bar_static_private INTERFACE BAR_LIBRARY) target_compile_definitions(bar_static_private PRIVATE BAR_USE_BANG) set_property(TARGET bar_static_private APPEND PROPERTY LINK_LIBRARIES bang_static_private) set_property(TARGET bar_static_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $ foo_static_private) +add_library(zot_static_private STATIC zot_vs6_4.cpp) +target_compile_definitions(zot_static_private INTERFACE ZOT_LIBRARY) +set_property(TARGET bar_static_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) add_executable(InterfaceLinkLibraries main_vs6_4.cpp) set_property(TARGET InterfaceLinkLibraries APPEND PROPERTY LINK_LIBRARIES bar_static_private) diff --git a/Tests/InterfaceLinkLibraries/main.cpp b/Tests/InterfaceLinkLibraries/main.cpp index a54076a..6e1295a 100644 --- a/Tests/InterfaceLinkLibraries/main.cpp +++ b/Tests/InterfaceLinkLibraries/main.cpp @@ -11,9 +11,13 @@ #error Unexpected BANG_LIBRARY #endif -#include "bar.h" +#ifdef ZOT_LIBRARY +#error Unexpected ZOT_LIBRARY +#endif + +#include "zot.h" int main(void) { - return foo() + bar(); + return foo() + bar() + zot(); } diff --git a/Tests/InterfaceLinkLibraries/zot.cpp b/Tests/InterfaceLinkLibraries/zot.cpp new file mode 100644 index 0000000..69462b0 --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot.cpp @@ -0,0 +1,6 @@ +#include "zot.h" + +int zot() +{ + return 0; +} diff --git a/Tests/InterfaceLinkLibraries/zot.h b/Tests/InterfaceLinkLibraries/zot.h new file mode 100644 index 0000000..5e4fb1e --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot.h @@ -0,0 +1,7 @@ + +#include "bar.h" + +#ifdef _WIN32 +__declspec(dllexport) +#endif +int zot(); diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp new file mode 100644 index 0000000..c588c5f --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot_vs6_1.cpp @@ -0,0 +1 @@ +#include "zot.cpp" diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp new file mode 100644 index 0000000..c588c5f --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot_vs6_2.cpp @@ -0,0 +1 @@ +#include "zot.cpp" diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp new file mode 100644 index 0000000..c588c5f --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot_vs6_3.cpp @@ -0,0 +1 @@ +#include "zot.cpp" diff --git a/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp b/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp new file mode 100644 index 0000000..c588c5f --- /dev/null +++ b/Tests/InterfaceLinkLibraries/zot_vs6_4.cpp @@ -0,0 +1 @@ +#include "zot.cpp" -- cgit v0.12 From 6e7e881c57e8ff7295a1007d329708143b54baad Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Jul 2014 11:34:02 -0400 Subject: Honor $ when checking interface properties Callers of cmTarget::GetLinkImplementationClosure are interested in the set of targets whose interface properties propagate to the current target. This excludes targets guarded by $. Teach the CompatibleInterface test to cover suppression of interface compatibility tests with $. Although this is not recommended in practice, it is a way of covering the above behavior. --- Source/cmTarget.cxx | 2 +- Tests/CompatibleInterface/CMakeLists.txt | 11 ++++++++++- Tests/CompatibleInterface/bar.cpp | 7 +++++++ Tests/CompatibleInterface/foo.cpp | 4 ++++ Tests/CompatibleInterface/main.cpp | 8 +++++++- 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Tests/CompatibleInterface/bar.cpp create mode 100644 Tests/CompatibleInterface/foo.cpp diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ffdeb6a..cdece87 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -6018,7 +6018,7 @@ void processILibs(const std::string& config, { tgts.push_back(item.Target); if(cmTarget::LinkInterface const* iface = - item.Target->GetLinkInterfaceLibraries(config, headTarget, false)) + item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) { for(std::vector::const_iterator it = iface->Libraries.begin(); diff --git a/Tests/CompatibleInterface/CMakeLists.txt b/Tests/CompatibleInterface/CMakeLists.txt index 350b518..668a97b 100644 --- a/Tests/CompatibleInterface/CMakeLists.txt +++ b/Tests/CompatibleInterface/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) project(CompatibleInterface) @@ -54,6 +54,15 @@ set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP2 200) add_executable(CompatibleInterface main.cpp) target_link_libraries(CompatibleInterface iface1) +add_library(foo STATIC foo.cpp) +add_library(bar SHARED bar.cpp) +set_property(TARGET foo APPEND PROPERTY COMPATIBLE_INTERFACE_BOOL SOMEPROP) +set_property(TARGET foo PROPERTY INTERFACE_SOMEPROP ON) +# Use LINK_ONLY to suppress usage requirements and allow the check to pass. +set_property(TARGET bar PROPERTY INTERFACE_LINK_LIBRARIES $) +set_property(TARGET CompatibleInterface PROPERTY SOMEPROP OFF) +target_link_libraries(CompatibleInterface bar) + set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP2 ON) set_property(TARGET CompatibleInterface PROPERTY BOOL_PROP3 ON) set_property(TARGET CompatibleInterface PROPERTY STRING_PROP2 prop2) diff --git a/Tests/CompatibleInterface/bar.cpp b/Tests/CompatibleInterface/bar.cpp new file mode 100644 index 0000000..2e09900 --- /dev/null +++ b/Tests/CompatibleInterface/bar.cpp @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int bar() +{ + return 0; +} diff --git a/Tests/CompatibleInterface/foo.cpp b/Tests/CompatibleInterface/foo.cpp new file mode 100644 index 0000000..e05eb7e --- /dev/null +++ b/Tests/CompatibleInterface/foo.cpp @@ -0,0 +1,4 @@ +int foo() +{ + return 0; +} diff --git a/Tests/CompatibleInterface/main.cpp b/Tests/CompatibleInterface/main.cpp index e23625a..d20b64b 100644 --- a/Tests/CompatibleInterface/main.cpp +++ b/Tests/CompatibleInterface/main.cpp @@ -40,8 +40,14 @@ enum { #include "iface2.h" +int foo(); +#ifdef _WIN32 +__declspec(dllimport) +#endif +int bar(); + int main(int argc, char **argv) { Iface2 if2; - return if2.foo(); + return if2.foo() + foo() + bar(); } -- cgit v0.12 From 10c5c82c1e255523757d4c4fe81b6ad742e81c8f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 16 Jul 2014 14:26:18 -0400 Subject: Help: Add notes for topic 'generalize-LINK_ONLY' --- Help/release/dev/generalize-LINK_ONLY.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Help/release/dev/generalize-LINK_ONLY.rst diff --git a/Help/release/dev/generalize-LINK_ONLY.rst b/Help/release/dev/generalize-LINK_ONLY.rst new file mode 100644 index 0000000..6dccbd5 --- /dev/null +++ b/Help/release/dev/generalize-LINK_ONLY.rst @@ -0,0 +1,6 @@ +generalize-LINK_ONLY +-------------------- + +* The :prop_tgt:`INTERFACE_LINK_LIBRARIES` target property now supports + a ``$`` + :manual:`generator expression `. -- cgit v0.12