Reject TARGET_PDB_FILE for imported targets instead of crashing

Reported-by: Justin Borodinsky <justin.borodinsky@gmail.com>
This commit is contained in:
Brad King 2015-08-03 15:28:41 -04:00
parent 22590805bf
commit 35aab9df9f
6 changed files with 20 additions and 0 deletions

View File

@ -1600,6 +1600,13 @@ struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
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";

View File

@ -1248,6 +1248,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
UNORDERED_SET<std::string> languages;
cmTarget::LinkImplementation const* impl =
this->Target->GetLinkImplementation(config);
assert(impl);
for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
li != impl->Languages.end(); ++li)
{

View File

@ -0,0 +1,8 @@
CMake Error at ImportedTarget-TARGET_PDB_FILE.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<TARGET_PDB_FILE:empty>
TARGET_PDB_FILE not allowed for IMPORTED targets.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
add_library(empty UNKNOWN IMPORTED)
add_custom_target(custom COMMAND echo $<TARGET_PDB_FILE:empty>)

View File

@ -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)