ENH: add CMAKE_DEFINE_FLAG_(LANG) that can replace -D flags with what the compiler actually uses

This commit is contained in:
Bill Hoffman 2008-01-11 13:00:29 -05:00
parent 510f578f8b
commit ee886fbbdb
2 changed files with 40 additions and 2 deletions

View File

@ -1182,7 +1182,10 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
{
flags[flags.size()-1] = ' ';
}
flags += this->Makefile->GetDefineFlags();
std::string defineFlags = this->Makefile->GetDefineFlags();
std::cout << defineFlags << "\n";
this->FixDefineFlags(defineFlags, lang);
flags += defineFlags;
this->LanguageToIncludeFlags[lang] = flags;
// Use this temorary variable for the return value to work-around a
@ -1191,6 +1194,41 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang)
return ret;
}
//----------------------------------------------------------------------------
void cmLocalGenerator::FixDefineFlags(std::string& flags,
const char* lang)
{
std::string defineFlagVar = "CMAKE_DEFINE_FLAG_";
defineFlagVar += lang;
std::string defineFlag =
this->Makefile->GetSafeDefinition(defineFlagVar.c_str());
if(defineFlag.size() == 0)
{
return;
}
std::vector<std::string> args;
cmSystemTools::ParseWindowsCommandLine(flags.c_str(), args);
std::string fixedFlags;
const char* sep = 0;
for(std::vector<std::string>::iterator i = args.begin();
i != args.end(); ++i)
{
if(sep)
{
fixedFlags += sep;
}
else
{
sep = " ";
}
cmSystemTools::ReplaceString(*i, "-D", defineFlag.c_str());
fixedFlags += *i;
}
flags = fixedFlags;
}
//----------------------------------------------------------------------------
void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
bool filter_system_dirs)

View File

@ -270,7 +270,7 @@ public:
unsigned int minor,
unsigned int patch = 0xFFu);
protected:
void FixDefineFlags(std::string& defineFlags, const char* lang);
/** Construct a comment for a custom command. */
std::string ConstructComment(const cmCustomCommand& cc,
const char* default_comment = "");