Browse Source

Merge topic 'out-of-dir-link-keyword'

09721ca078 target_link_libraries: Fix out-of-dir calls with debug/optimized keywords
c40229968c target_link_libraries: Add FIXME comment for out-of-dir genex list

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4202
Brad King 5 years ago
parent
commit
9a5d399725

+ 2 - 2
Help/prop_tgt/LINK_LIBRARIES_INDIRECTION.txt

@@ -2,8 +2,8 @@
   A call to :command:`target_link_libraries(<target> ...)` may update this
   property on ``<target>``.  If ``<target>`` was not created in the same
   directory as the call then :command:`target_link_libraries` will add a
-  suffix of the form ``::@<directory-id>`` to each entry, where the
-  ``::@`` is a separator and the ``<directory-id>`` is unspecified.
+  suffix of the form ``::@(directory-id)`` to each entry, where the
+  ``::@`` is a separator and the ``(directory-id)`` is unspecified.
   This tells the generators that the named libraries must be looked up in
   the scope of the caller rather than in the scope in which the
   ``<target>`` was created.  Valid directory ids are stripped on export

+ 1 - 1
Source/cmMakefile.cxx

@@ -139,7 +139,7 @@ cmDirectoryId cmMakefile::GetDirectoryId() const
   // If we ever need to expose this to CMake language code we should
   // add a read-only property in cmMakefile::GetProperty.
   char buf[32];
-  sprintf(buf, "<%p>",
+  sprintf(buf, "(%p)",
           static_cast<void const*>(this)); // cast avoids format warning
   return std::string(buf);
 }

+ 4 - 0
Source/cmTargetLinkLibrariesCommand.cxx

@@ -406,6 +406,10 @@ static bool HandleLibrary(cmMakefile& mf, cmTarget* target,
     // the name to tell ResolveLinkItem to look up the name in the
     // caller's directory.
     cmDirectoryId const dirId = mf.GetDirectoryId();
+    // FIXME: The "lib" may be a genex with a list inside it.
+    // After expansion this id will only attach to the last entry,
+    // or may attach to an empty string!  We will need another way
+    // to encode this that can apply to a whole list.  See issue #20204.
     libRef = lib + CMAKE_DIRECTORY_ID_SEP + dirId.String;
   } else {
     // This is an absolute path or a library name added by a caller

+ 4 - 1
Tests/CMakeCommands/target_link_libraries/SubDirB/CMakeLists.txt

@@ -2,7 +2,10 @@ add_executable(SubDirB SubDirB.c)
 
 # Link to a target imported in this directory that would not normally
 # be visible to the directory in which TopDir is defined.
-target_link_libraries(TopDir PUBLIC SameNameImported)
+target_link_libraries(TopDir PUBLIC debug SameNameImported optimized SameNameImported)
+
+#FIXME: Demonstrate known issue #20204.
+#target_link_libraries(TopDir PUBLIC "$<1:SameNameImported;SameNameImported>")
 
 # Link SubDirA to a target imported in this directory that has the same
 # name as a target imported in SubDirA's directory.  We verify when

+ 1 - 1
Tests/RunCMake/target_link_libraries/CMP0079-iface-NEW-stdout.txt

@@ -1 +1 @@
--- INTERFACE_LINK_LIBRARIES='foo::@<[Xx0-9A-Fa-f]+>'
+-- INTERFACE_LINK_LIBRARIES='foo::@\([Xx0-9A-Fa-f]+\)'

+ 1 - 1
Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus-stderr.txt

@@ -1,5 +1,5 @@
 ^CMake Error at CMP0079-link-NEW-bogus.cmake:[0-9]+ \(add_executable\):
-  Target "top" links to target "foo::@<0xdeadbeef>" but the target was not
+  Target "top" links to target "foo::@\(0xdeadbeef\)" but the target was not
   found.  Perhaps a find_package\(\) call is missing for an IMPORTED target, or
   an ALIAS target is missing\?
 Call Stack \(most recent call first\):

+ 1 - 1
Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-bogus.cmake

@@ -3,4 +3,4 @@ cmake_policy(SET CMP0079 NEW)
 enable_language(C)
 
 add_executable(top empty.c)
-set_property(TARGET top APPEND PROPERTY LINK_LIBRARIES "foo::@<0xdeadbeef>")
+set_property(TARGET top APPEND PROPERTY LINK_LIBRARIES "foo::@(0xdeadbeef)")

+ 1 - 1
Tests/RunCMake/target_link_libraries/CMP0079-link-NEW-stdout.txt

@@ -1 +1 @@
--- LINK_LIBRARIES='foo::@<[Xx0-9A-Fa-f]+>'
+-- LINK_LIBRARIES='foo::@\([Xx0-9A-Fa-f]+\)'