Просмотр исходного кода

Merge topic 'fastbuild-imported-objlib'

67dc1dff7c FASTBuild: fix imported object libs

Acked-by: Kitware Robot <[email protected]>
Merge-request: !11670
Brad King 1 неделя назад
Родитель
Сommit
8d251cc54a

+ 18 - 3
Source/cmFastbuildNormalTargetGenerator.cxx

@@ -2082,6 +2082,8 @@ void cmFastbuildNormalTargetGenerator::AppendLinkDeps(
   for (cmComputeLinkInformation::Item const& item : items) {
     std::string const feature = item.GetFeatureName();
     LogMessage("GetFeatureName: " + feature);
+    std::string const formatted =
+      item.GetFormattedItem(item.Value.Value).Value;
     if (!feature.empty()) {
       LogMessage("GetFormattedItem: " +
                  item.GetFormattedItem(item.Value.Value).Value);
@@ -2092,13 +2094,26 @@ void cmFastbuildNormalTargetGenerator::AppendLinkDeps(
     if (item.ObjectSource &&
         linkerNode.Type != FastbuildLinkerNode::STATIC_LIBRARY) {
       // Tested in "ObjectLibrary" test.
-      auto libName = item.ObjectSource->GetObjectLibrary();
+      std::string const libName = item.ObjectSource->GetObjectLibrary();
       std::string dep = libName + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
       if (linkedObjects.emplace(dep).second) {
-        FastbuildTargetDep targetDep{ std::move(libName) };
+        FastbuildTargetDep targetDep{ libName };
         targetDep.Type = FastbuildTargetDepType::ORDER_ONLY;
         preBuildDeps.emplace(std::move(targetDep));
-        linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
+
+        cmTarget const* importedTarget =
+          this->LocalGenerator->GetMakefile()->FindImportedTarget(libName);
+        // Add direct path to the object for imported target
+        // since such targets are not defined in fbuild.bff file.
+        if (importedTarget) {
+          LogMessage(
+            cmStrCat("Adding ", formatted, " to LibrarianAdditionalInputs"));
+          linkerNode.LibrarianAdditionalInputs.emplace_back(formatted);
+        } else {
+          LogMessage(
+            cmStrCat("Adding ", dep, " to LibrarianAdditionalInputs"));
+          linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
+        }
       }
     } else if (linkerNode.Type == FastbuildLinkerNode::STATIC_LIBRARY) {
       LogMessage(cmStrCat("Skipping linking to STATIC_LIBRARY (",

+ 10 - 0
Tests/RunCMake/FASTBuild/ImportedObjectLib-check.cmake

@@ -0,0 +1,10 @@
+# Check that we're linking to an object file on disk
+# and not to "-objects" alias (which only exists for non-imported targets).
+set(REGEX_TO_MATCH "
+.*.Libraries =
+.*{
+.*'MyApp_CXX_Objs_1',
+.*dummy.o'
+.*}
+")
+include(${RunCMake_SOURCE_DIR}/check.cmake)

+ 8 - 0
Tests/RunCMake/FASTBuild/ImportedObjectLib.cmake

@@ -0,0 +1,8 @@
+add_library(ExternalObjLib OBJECT IMPORTED)
+set_target_properties(ExternalObjLib PROPERTIES
+    IMPORTED_OBJECTS "${CMAKE_CURRENT_SOURCE_DIR}/dummy.o"
+)
+
+add_executable(MyApp main.cpp)
+
+target_link_libraries(MyApp PRIVATE $<TARGET_OBJECTS:ExternalObjLib>)

+ 1 - 0
Tests/RunCMake/FASTBuild/RunCMakeTest.cmake

@@ -9,3 +9,4 @@ run_cmake(UnityIsolate)
 run_cmake(DisableCaching)
 run_cmake(DisableDistribution)
 run_cmake(SetCompilerProps)
+run_cmake(ImportedObjectLib)