From 35aab9df9f299d62edaa6ce611aa30614deb9e9d Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 3 Aug 2015 15:28:41 -0400 Subject: [PATCH] Reject TARGET_PDB_FILE for imported targets instead of crashing Reported-by: Justin Borodinsky --- Source/cmGeneratorExpressionNode.cxx | 7 +++++++ Source/cmGeneratorTarget.cxx | 1 + .../ImportedTarget-TARGET_PDB_FILE-result.txt | 1 + .../ImportedTarget-TARGET_PDB_FILE-stderr.txt | 8 ++++++++ .../ImportedTarget-TARGET_PDB_FILE.cmake | 2 ++ Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake | 1 + 6 files changed, 20 insertions(+) create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a86c2bcc0..44a9adb4d 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1600,6 +1600,13 @@ struct TargetFilesystemArtifactResultCreator cmGeneratorExpressionContext *context, const GeneratorExpressionContent *content) { + if (target->IsImported()) + { + ::reportError(context, content->GetOriginalExpression(), + "TARGET_PDB_FILE not allowed for IMPORTED targets."); + return std::string(); + } + std::string language = target->GetLinkerLanguage(context->Config); std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB"; diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c831704ac..e49036867 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1248,6 +1248,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config, UNORDERED_SET languages; cmTarget::LinkImplementation const* impl = this->Target->GetLinkImplementation(config); + assert(impl); for(std::vector::const_iterator li = impl->Languages.begin(); li != impl->Languages.end(); ++li) { diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt new file mode 100644 index 000000000..d915ecbbf --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at ImportedTarget-TARGET_PDB_FILE.cmake:2 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + TARGET_PDB_FILE not allowed for IMPORTED targets. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake new file mode 100644 index 000000000..c55c5d594 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/ImportedTarget-TARGET_PDB_FILE.cmake @@ -0,0 +1,2 @@ +add_library(empty UNKNOWN IMPORTED) +add_custom_target(custom COMMAND echo $) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index 1c8fab534..cba3941df 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -26,6 +26,7 @@ run_cmake(COMPILE_LANGUAGE-add_library) run_cmake(COMPILE_LANGUAGE-add_test) run_cmake(COMPILE_LANGUAGE-unknown-lang) +run_cmake(ImportedTarget-TARGET_PDB_FILE) if(LINKER_SUPPORTS_PDB) run_cmake(NonValidTarget-TARGET_PDB_FILE) run_cmake(ValidTarget-TARGET_PDB_FILE)