Browse Source

export: Reject custom target exports earlier (#15657)

Diagnose and reject custom targets given to the export() command
immediately.  Previously we would generate an internal error later.
Brad King 10 years ago
parent
commit
7e9f908ef5

+ 6 - 0
Source/cmExportCommand.cxx

@@ -177,6 +177,12 @@ bool cmExportCommand
           this->SetError(e.str());
           return false;
           }
+        if (target->GetType() == cmTarget::UTILITY)
+          {
+          this->SetError("given custom target \"" + *currentTarget
+                         + "\" which may not be exported.");
+          return false;
+          }
         }
       else
         {

+ 1 - 0
Tests/RunCMake/export/CustomTarget-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
Tests/RunCMake/export/CustomTarget-stderr.txt

@@ -0,0 +1,4 @@
+^CMake Error at CustomTarget.cmake:[0-9]+ \(export\):
+  export given custom target "CustomTarget" which may not be exported.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)$

+ 2 - 0
Tests/RunCMake/export/CustomTarget.cmake

@@ -0,0 +1,2 @@
+add_custom_target(CustomTarget)
+export(TARGETS CustomTarget FILE somefile.cmake)

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

@@ -1,5 +1,6 @@
 include(RunCMake)
 
+run_cmake(CustomTarget)
 run_cmake(TargetNotFound)
 run_cmake(AppendExport)
 run_cmake(OldIface)