Преглед на файлове

Merge branch 'backport-3.15-install-default-fix' into release-3.15

Merge-request: !4340
Brad King преди 5 години
родител
ревизия
8871cb57e2

+ 38 - 6
Source/cmInstallCommand.cxx

@@ -466,6 +466,10 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
     cmInstallFilesGenerator* publicHeaderGenerator = nullptr;
     cmInstallFilesGenerator* resourceGenerator = nullptr;
 
+    // Avoid selecting default destinations for PUBLIC_HEADER and
+    // PRIVATE_HEADER if any artifacts are specified.
+    bool artifactsSpecified = false;
+
     // Track whether this is a namelink-only rule.
     bool namelinkOnly = false;
 
@@ -485,11 +489,13 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
             // The import library uses the ARCHIVE properties.
             archiveGenerator = CreateInstallTargetGenerator(
               target, archiveArgs, true, this->Makefile->GetBacktrace());
+            artifactsSpecified = true;
           }
           if (!runtimeArgs.GetDestination().empty()) {
             // The DLL uses the RUNTIME properties.
             runtimeGenerator = CreateInstallTargetGenerator(
               target, runtimeArgs, false, this->Makefile->GetBacktrace());
+            artifactsSpecified = true;
           }
           if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) {
             archiveGenerator = CreateInstallTargetGenerator(
@@ -523,6 +529,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
             }
           } else {
             // The shared library uses the LIBRARY properties.
+            if (!libraryArgs.GetDestination().empty()) {
+              artifactsSpecified = true;
+            }
             if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
               libraryGenerator = CreateInstallTargetGenerator(
                 target, libraryArgs, false, this->Makefile->GetBacktrace(),
@@ -565,6 +574,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         } else {
           // Static libraries use ARCHIVE properties.
+          if (!archiveArgs.GetDestination().empty()) {
+            artifactsSpecified = true;
+          }
           archiveGenerator = CreateInstallTargetGenerator(
             target, archiveArgs, false, this->Makefile->GetBacktrace(),
             this->GetArchiveDestination(&archiveArgs));
@@ -635,6 +647,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
           }
         } else {
           // Executables use the RUNTIME properties.
+          if (!runtimeArgs.GetDestination().empty()) {
+            artifactsSpecified = true;
+          }
           runtimeGenerator = CreateInstallTargetGenerator(
             target, runtimeArgs, false, this->Makefile->GetBacktrace(),
             this->GetRuntimeDestination(&runtimeArgs));
@@ -646,6 +661,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
         if (dll_platform && !archiveArgs.GetDestination().empty() &&
             target.IsExecutableWithExports()) {
           // The import library uses the ARCHIVE properties.
+          artifactsSpecified = true;
           archiveGenerator = CreateInstallTargetGenerator(
             target, archiveArgs, true, this->Makefile->GetBacktrace(), true);
         }
@@ -683,9 +699,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
         }
 
         // Create the files install generator.
-        privateHeaderGenerator = CreateInstallFilesGenerator(
-          this->Makefile, absFiles, privateHeaderArgs, false,
-          this->GetIncludeDestination(&privateHeaderArgs));
+        if (!artifactsSpecified ||
+            !privateHeaderArgs.GetDestination().empty()) {
+          privateHeaderGenerator = CreateInstallFilesGenerator(
+            this->Makefile, absFiles, privateHeaderArgs, false,
+            this->GetIncludeDestination(&privateHeaderArgs));
+        } else {
+          std::ostringstream e;
+          e << "INSTALL TARGETS - target " << target.GetName() << " has "
+            << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
+          cmSystemTools::Message(e.str(), "Warning");
+        }
       }
 
       files = target.GetProperty("PUBLIC_HEADER");
@@ -698,9 +722,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
         }
 
         // Create the files install generator.
-        publicHeaderGenerator = CreateInstallFilesGenerator(
-          this->Makefile, absFiles, publicHeaderArgs, false,
-          this->GetIncludeDestination(&publicHeaderArgs));
+        if (!artifactsSpecified ||
+            !publicHeaderArgs.GetDestination().empty()) {
+          publicHeaderGenerator = CreateInstallFilesGenerator(
+            this->Makefile, absFiles, publicHeaderArgs, false,
+            this->GetIncludeDestination(&publicHeaderArgs));
+        } else {
+          std::ostringstream e;
+          e << "INSTALL TARGETS - target " << target.GetName() << " has "
+            << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
+          cmSystemTools::Message(e.str(), "Warning");
+        }
       }
 
       files = target.GetProperty("RESOURCE");

+ 3 - 6
Tests/RunCMake/install/TARGETS-Defaults-Cache-all-check.cmake

@@ -8,8 +8,7 @@ if(WIN32)
     [[mybin/exe\.exe]]
     [[mybin/(lib)?lib1\.dll]]
     [[myinclude]]
-    [[myinclude/obj4\.h]]
-    [[myinclude/obj5\.h]]
+    [[myinclude/obj3\.h]]
     [[mylib]]
     [[mylib/(lib)?lib1\.(dll\.a|lib)]]
     [[mylib/(lib)?lib2\.(a|lib)]]
@@ -24,8 +23,7 @@ elseif(CYGWIN)
     [[mybin/cyglib1\.dll]]
     [[mybin/exe\.exe]]
     [[myinclude]]
-    [[myinclude/obj4\.h]]
-    [[myinclude/obj5\.h]]
+    [[myinclude/obj3\.h]]
     [[mylib]]
     [[mylib/liblib1\.dll\.a]]
     [[mylib/liblib2\.a]]
@@ -39,8 +37,7 @@ else()
     [[mybin]]
     [[mybin/exe]]
     [[myinclude]]
-    [[myinclude/obj4\.h]]
-    [[myinclude/obj5\.h]]
+    [[myinclude/obj3\.h]]
     [[mylib]]
     [[mylib/liblib1\.(dylib|so)]]
     [[mylib/liblib2\.a]]

+ 2 - 0
Tests/RunCMake/install/TARGETS-Defaults-Cache-stderr.txt

@@ -0,0 +1,2 @@
+^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\.
+INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$

+ 1 - 0
Tests/RunCMake/install/TARGETS-Defaults-Cache.cmake

@@ -2,6 +2,7 @@ enable_language(C)
 
 add_executable(exe main.c)
 add_library(lib1 SHARED obj1.c)
+set_property(TARGET lib1 PROPERTY PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj3.h)
 add_library(lib2 STATIC obj3.c)
 add_library(lib3 SHARED obj4.c)
 set_property(TARGET lib3 PROPERTY PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj4.h)

+ 3 - 6
Tests/RunCMake/install/TARGETS-Defaults-all-check.cmake

@@ -6,8 +6,7 @@ if(WIN32)
     [[include]]
     [[include/obj1\.h]]
     [[include/obj2\.h]]
-    [[include/obj4\.h]]
-    [[include/obj5\.h]]
+    [[include/obj3\.h]]
     [[lib]]
     [[lib/(lib)?lib1\.(dll\.a|lib)]]
     [[lib/(lib)?lib2\.(a|lib)]]
@@ -24,8 +23,7 @@ elseif(CYGWIN)
     [[include]]
     [[include/obj1\.h]]
     [[include/obj2\.h]]
-    [[include/obj4\.h]]
-    [[include/obj5\.h]]
+    [[include/obj3\.h]]
     [[lib]]
     [[lib/liblib1\.dll\.a]]
     [[lib/liblib2\.a]]
@@ -41,8 +39,7 @@ else()
     [[include]]
     [[include/obj1\.h]]
     [[include/obj2\.h]]
-    [[include/obj4\.h]]
-    [[include/obj5\.h]]
+    [[include/obj3\.h]]
     [[lib]]
     [[lib/liblib1\.(dylib|so)]]
     [[lib/liblib2\.a]]

+ 2 - 0
Tests/RunCMake/install/TARGETS-Defaults-stderr.txt

@@ -0,0 +1,2 @@
+^INSTALL TARGETS - target lib3 has PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION\.
+INSTALL TARGETS - target lib4 has PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION\.$

+ 1 - 0
Tests/RunCMake/install/TARGETS-Defaults.cmake

@@ -2,6 +2,7 @@ enable_language(C)
 
 add_executable(exe main.c)
 add_library(lib1 SHARED obj1.c)
+set_property(TARGET lib1 PROPERTY PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj3.h)
 add_library(lib2 STATIC obj3.c)
 add_library(lib3 SHARED obj4.c)
 set_property(TARGET lib3 PROPERTY PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/obj4.h)