From 1cd1430b1fb0df91ff97d4ba3f360cdee0f56ce2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 2 Dec 2013 17:18:29 +0100 Subject: [PATCH] export(): Check targets exist at configure-time (#14608) Commit 66b290e7 (export(): Process the export() command at generate time., 2012-10-06 ) refactored export() so that it could evaluate strings at generate-time. This was intended for evaluating target properties, but that commit also removed a check for target existence at configure-time. Restore that check and add a test for this case. --- Source/cmExportCommand.cxx | 8 ++++++++ Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/export/CMakeLists.txt | 3 +++ Tests/RunCMake/export/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/export/TargetNotFound-result.txt | 1 + Tests/RunCMake/export/TargetNotFound-stderr.txt | 4 ++++ Tests/RunCMake/export/TargetNotFound.cmake | 1 + 7 files changed, 21 insertions(+) create mode 100644 Tests/RunCMake/export/CMakeLists.txt create mode 100644 Tests/RunCMake/export/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/export/TargetNotFound-result.txt create mode 100644 Tests/RunCMake/export/TargetNotFound-stderr.txt create mode 100644 Tests/RunCMake/export/TargetNotFound.cmake diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 86ddc3f44..3f6bc2e3d 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -135,6 +135,14 @@ bool cmExportCommand return false; } } + else + { + cmOStringStream e; + e << "given target \"" << *currentTarget + << "\" which is not built by this project."; + this->SetError(e.str().c_str()); + return false; + } } cmGlobalGenerator *gg = this->Makefile->GetLocalGenerator() diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 209b0b3b3..407f9655c 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -98,6 +98,7 @@ add_RunCMake_test(Syntax) add_RunCMake_test(add_dependencies) add_RunCMake_test(build_command) +add_RunCMake_test(export) add_RunCMake_test(cmake_minimum_required) add_RunCMake_test(find_package) add_RunCMake_test(get_filename_component) diff --git a/Tests/RunCMake/export/CMakeLists.txt b/Tests/RunCMake/export/CMakeLists.txt new file mode 100644 index 000000000..be9d4038d --- /dev/null +++ b/Tests/RunCMake/export/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.4) +project(${RunCMake_TEST}) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake new file mode 100644 index 000000000..b8d3f275f --- /dev/null +++ b/Tests/RunCMake/export/RunCMakeTest.cmake @@ -0,0 +1,3 @@ +include(RunCMake) + +run_cmake(TargetNotFound) diff --git a/Tests/RunCMake/export/TargetNotFound-result.txt b/Tests/RunCMake/export/TargetNotFound-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/export/TargetNotFound-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/export/TargetNotFound-stderr.txt b/Tests/RunCMake/export/TargetNotFound-stderr.txt new file mode 100644 index 000000000..944a68e0e --- /dev/null +++ b/Tests/RunCMake/export/TargetNotFound-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at TargetNotFound.cmake:1 \(export\): + export given target "nonexistenttarget" which is not built by this project. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/export/TargetNotFound.cmake b/Tests/RunCMake/export/TargetNotFound.cmake new file mode 100644 index 000000000..a7c398daf --- /dev/null +++ b/Tests/RunCMake/export/TargetNotFound.cmake @@ -0,0 +1 @@ +export(TARGETS nonexistenttarget FILE somefile.cmake)