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

Merge topic 'autogen-makefile-depfile'

d2d1763f88 cmQtAutoGenInitializer: De-duplicate autogen/timestamp target depend logic
6193d15556 Autogen: Restore target-ordering dependencies in Makefiles with DEPFILE

Acked-by: Kitware Robot <[email protected]>
Merge-request: !9340
Brad King 1 год назад
Родитель
Сommit
2bfaaf6f6e

+ 10 - 32
Source/cmQtAutoGenInitializer.cxx

@@ -1480,6 +1480,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
       }
     }
 
+    cmTarget* timestampTarget = nullptr;
     std::vector<std::string> dependencies(
       this->AutogenTarget.DependFiles.begin(),
       this->AutogenTarget.DependFiles.end());
@@ -1500,36 +1501,12 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
       const auto timestampTargetName =
         cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
 
-      // Add additional autogen target dependencies to
-      // '_autogen_timestamp_deps'.
-      for (const cmTarget* t : this->AutogenTarget.DependTargets) {
-        std::string depname = t->GetName();
-        if (t->IsImported()) {
-          auto const ttype = t->GetType();
-          if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY ||
-              ttype == cmStateEnums::TargetType::SHARED_LIBRARY ||
-              ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) {
-            depname = cmStrCat("$<TARGET_LINKER_FILE:", t->GetName(), ">");
-          }
-        }
-        dependencies.emplace_back(std::move(depname));
-      }
-
       auto cc = cm::make_unique<cmCustomCommand>();
       cc->SetWorkingDirectory(this->Dir.Work.c_str());
       cc->SetDepends(dependencies);
       cc->SetEscapeOldStyle(false);
-      cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
-        timestampTargetName, true, std::move(cc));
-      auto const isMake =
-        this->GlobalGen->GetName().find("Make") != std::string::npos;
-      if (this->AutogenTarget.DependOrigin && isMake) {
-        for (BT<std::pair<std::string, bool>> const& depName :
-             this->GenTarget->GetUtilities()) {
-          timestampTarget->AddUtility(depName.Value.first, false,
-                                      this->Makefile);
-        }
-      }
+      timestampTarget = this->LocalGen->AddUtilityCommand(timestampTargetName,
+                                                          true, std::move(cc));
 
       this->LocalGen->AddGeneratorTarget(
         cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen));
@@ -1619,18 +1596,19 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
     this->LocalGen->AddGeneratorTarget(
       cm::make_unique<cmGeneratorTarget>(autogenTarget, this->LocalGen));
 
+    // Order the autogen target(s) just before the original target.
+    cmTarget* orderTarget = timestampTarget ? timestampTarget : autogenTarget;
     // Forward origin utilities to autogen target
     if (this->AutogenTarget.DependOrigin) {
       for (BT<std::pair<std::string, bool>> const& depName :
            this->GenTarget->GetUtilities()) {
-        autogenTarget->AddUtility(depName.Value.first, false, this->Makefile);
+        orderTarget->AddUtility(depName.Value.first, false, this->Makefile);
       }
     }
-    if (!useDepfile) {
-      // Add additional autogen target dependencies to autogen target
-      for (cmTarget const* depTarget : this->AutogenTarget.DependTargets) {
-        autogenTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
-      }
+
+    // Add additional autogen target dependencies to autogen target
+    for (cmTarget const* depTarget : this->AutogenTarget.DependTargets) {
+      orderTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
     }
 
     // Set FOLDER property in autogen target

+ 13 - 0
Tests/QtAutogen/AutogenTimestampDeps/CMakeLists.txt

@@ -8,4 +8,17 @@ add_custom_target(ProjectInfo
   COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UpdateProjectInfo.cmake
   BYPRODUCTS ${CMAKE_BINARY_DIR}/ProjectInfo.hpp)
 
+set(ext_lib ${CMAKE_CURRENT_BINARY_DIR}/ext-build/${CMAKE_STATIC_LIBRARY_PREFIX}ext${CMAKE_STATIC_LIBRARY_SUFFIX})
+include(ExternalProject)
+ExternalProject_Add(ext_target
+  SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ext"
+  BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ext-build"
+  DOWNLOAD_COMMAND ""
+  INSTALL_COMMAND ""
+  BUILD_BYPRODUCTS "${ext_lib}"
+  )
+add_library(ext STATIC IMPORTED)
+set_property(TARGET ext PROPERTY IMPORTED_LOCATION "${ext_lib}")
+add_dependencies(ext ext_target)
+
 add_subdirectory(src)

+ 4 - 0
Tests/QtAutogen/AutogenTimestampDeps/ext/CMakeLists.txt

@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.28)
+project(Ext C)
+add_library(ext STATIC ext.c)
+set_property(TARGET ext PROPERTY ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_BINARY_DIR}>")

+ 4 - 0
Tests/QtAutogen/AutogenTimestampDeps/ext/ext.c

@@ -0,0 +1,4 @@
+int ext(void)
+{
+  return 0;
+}

+ 1 - 0
Tests/QtAutogen/AutogenTimestampDeps/src/CMakeLists.txt

@@ -2,3 +2,4 @@ add_executable(Exe main.cpp ${CMAKE_BINARY_DIR}/ProjectInfo.hpp)
 add_dependencies(Exe ProjectInfo)
 target_include_directories(Exe PRIVATE ${CMAKE_BINARY_DIR})
 target_link_libraries(Exe PRIVATE ${QT_QTCORE_TARGET})
+target_link_libraries(Exe PRIVATE ext)

+ 2 - 1
Tests/QtAutogen/AutogenTimestampDeps/src/main.cpp

@@ -1,5 +1,6 @@
 #include "ProjectInfo.hpp"
+extern "C" int ext();
 int main(int argc, char* argv[])
 {
-  return 0;
+  return ext();
 }

+ 4 - 0
Tests/QtAutogen/Tests.cmake

@@ -2,7 +2,11 @@
 ADD_AUTOGEN_TEST(AutogenOriginDependsOff autogenOriginDependsOff)
 ADD_AUTOGEN_TEST(AutogenOriginDependsOn)
 ADD_AUTOGEN_TEST(AutogenTargetDepends)
+
+set(Autogen_CTEST_OPTIONS --build-target Exe)
 ADD_AUTOGEN_TEST(AutogenTimestampDeps)
+unset(Autogen_CTEST_OPTIONS)
+
 ADD_AUTOGEN_TEST(AutoMocGeneratedFile)
 ADD_AUTOGEN_TEST(Complex QtAutogen)
 ADD_AUTOGEN_TEST(GlobalAutogenSystemUseInclude)