Fix some generator crashes on undefined CMAKE_BUILD_TYPE

Since commit 84fdc9921 (stringapi: Pass configuration names as strings,
2014-02-09), it is not safe to use GetDefinition("CMAKE_BUILD_TYPE")
without checking the return value.  Use GetSafeDefinition instead so
that a missing definition is treated as an empty string like code paths
did prior to the above commit.

Reported-by: Richard Wirth <richard@califax.de>
This commit is contained in:
Brad King 2014-06-23 09:34:38 -04:00
parent 562d5f576a
commit c491cb1eb4
3 changed files with 3 additions and 3 deletions

View File

@ -574,7 +574,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout,
} }
} }
const char* buildType = makefile->GetDefinition("CMAKE_BUILD_TYPE"); std::string buildType = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
std::string location; std::string location;
if ( target->GetType()==cmTarget::OBJECT_LIBRARY) if ( target->GetType()==cmTarget::OBJECT_LIBRARY)
{ {

View File

@ -968,7 +968,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
continue; continue;
} }
std::vector<std::string> includeDirs; std::vector<std::string> includeDirs;
const char *config = mf->GetDefinition("CMAKE_BUILD_TYPE"); std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
(*it)->GetIncludeDirectories(includeDirs, l->second, "C", config); (*it)->GetIncludeDirectories(includeDirs, l->second, "C", config);
this->AppendIncludeDirectories(fout, includeDirs, emmited); this->AppendIncludeDirectories(fout, includeDirs, emmited);
} }

View File

@ -1861,7 +1861,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries,
((useWatcomQuote) ? WATCOMQUOTE : SHELL); ((useWatcomQuote) ? WATCOMQUOTE : SHELL);
bool escapeAllowMakeVars = !forResponseFile; bool escapeAllowMakeVars = !forResponseFile;
cmOStringStream fout; cmOStringStream fout;
const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"); std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config); cmComputeLinkInformation* pcli = tgt.Target->GetLinkInformation(config);
if(!pcli) if(!pcli)
{ {