فهرست منبع

add_custom_command: check if a relative path should be an in-source path

This still is broken for dependencies on generated paths where they get
generated to the source directory rather than the build directory
however, but there's no way to determine that is the case.

Fixes: #20194
Ben Boeckel 6 سال پیش
والد
کامیت
fd0ba705ce
3فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 0 4
      Source/cmCustomCommandGenerator.cxx
  2. 7 0
      Source/cmLocalGenerator.cxx
  3. 8 0
      Tests/CustomCommand/CMakeLists.txt

+ 0 - 4
Source/cmCustomCommandGenerator.cxx

@@ -8,7 +8,6 @@
 
 
 #include <cmext/algorithm>
 #include <cmext/algorithm>
 
 
-#include "cmAlgorithms.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmCustomCommandLines.h"
 #include "cmGeneratorExpression.h"
 #include "cmGeneratorExpression.h"
@@ -30,9 +29,6 @@ void AppendPaths(const std::vector<std::string>& inputs,
       cmExpandedList(cge->Evaluate(lg, config));
       cmExpandedList(cge->Evaluate(lg, config));
     for (std::string& it : result) {
     for (std::string& it : result) {
       cmSystemTools::ConvertToUnixSlashes(it);
       cmSystemTools::ConvertToUnixSlashes(it);
-      if (cmContains(it, '/') && !cmSystemTools::FileIsFullPath(it)) {
-        it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it);
-      }
       if (cmSystemTools::FileIsFullPath(it)) {
       if (cmSystemTools::FileIsFullPath(it)) {
         it = cmSystemTools::CollapseFullPath(
         it = cmSystemTools::CollapseFullPath(
           it, lg->GetMakefile()->GetHomeOutputDirectory());
           it, lg->GetMakefile()->GetHomeOutputDirectory());

+ 7 - 0
Source/cmLocalGenerator.cxx

@@ -2004,6 +2004,13 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
   // Treat the name as relative to the source directory in which it
   // Treat the name as relative to the source directory in which it
   // was given.
   // was given.
   dep = cmStrCat(this->GetCurrentSourceDirectory(), '/', inName);
   dep = cmStrCat(this->GetCurrentSourceDirectory(), '/', inName);
+
+  // If the in-source path does not exist, assume it instead lives in the
+  // binary directory.
+  if (!cmSystemTools::FileExists(dep)) {
+    dep = cmStrCat(this->GetCurrentBinaryDirectory(), '/', inName);
+  }
+
   return true;
   return true;
 }
 }
 
 

+ 8 - 0
Tests/CustomCommand/CMakeLists.txt

@@ -549,3 +549,11 @@ add_custom_command(
 )
 )
 
 
 add_custom_target(depends_on_path ALL DEPENDS "depends_on_path.txt")
 add_custom_target(depends_on_path ALL DEPENDS "depends_on_path.txt")
+
+add_custom_command(
+  OUTPUT "depends_on_in_source_path.txt"
+  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/main.cxx" in_source_path.txt
+  DEPENDS main.cxx
+)
+
+add_custom_target(depends_on_in_source_path ALL DEPENDS "depends_on_in_source_path.txt")