From 7e9f908ef54a3c2fe42ae8f9376c77e5bc988a9a Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 21 Jul 2015 14:37:20 -0400 Subject: [PATCH] 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. --- Source/cmExportCommand.cxx | 6 ++++++ Tests/RunCMake/export/CustomTarget-result.txt | 1 + Tests/RunCMake/export/CustomTarget-stderr.txt | 4 ++++ Tests/RunCMake/export/CustomTarget.cmake | 2 ++ Tests/RunCMake/export/RunCMakeTest.cmake | 1 + 5 files changed, 14 insertions(+) create mode 100644 Tests/RunCMake/export/CustomTarget-result.txt create mode 100644 Tests/RunCMake/export/CustomTarget-stderr.txt create mode 100644 Tests/RunCMake/export/CustomTarget.cmake diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 43d26f9e49..96ea77b2d6 100644 --- a/Source/cmExportCommand.cxx +++ b/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 { diff --git a/Tests/RunCMake/export/CustomTarget-result.txt b/Tests/RunCMake/export/CustomTarget-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/export/CustomTarget-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/export/CustomTarget-stderr.txt b/Tests/RunCMake/export/CustomTarget-stderr.txt new file mode 100644 index 0000000000..57a9af3680 --- /dev/null +++ b/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\)$ diff --git a/Tests/RunCMake/export/CustomTarget.cmake b/Tests/RunCMake/export/CustomTarget.cmake new file mode 100644 index 0000000000..4d2bf18dbb --- /dev/null +++ b/Tests/RunCMake/export/CustomTarget.cmake @@ -0,0 +1,2 @@ +add_custom_target(CustomTarget) +export(TARGETS CustomTarget FILE somefile.cmake) diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake index 4b04f18589..6d0b7ca7cd 100644 --- a/Tests/RunCMake/export/RunCMakeTest.cmake +++ b/Tests/RunCMake/export/RunCMakeTest.cmake @@ -1,5 +1,6 @@ include(RunCMake) +run_cmake(CustomTarget) run_cmake(TargetNotFound) run_cmake(AppendExport) run_cmake(OldIface)