From ee886fbbdba89aa0b850ee14d75c9f87211e3325 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Fri, 11 Jan 2008 13:00:29 -0500 Subject: [PATCH] ENH: add CMAKE_DEFINE_FLAG_(LANG) that can replace -D flags with what the compiler actually uses --- Source/cmLocalGenerator.cxx | 40 ++++++++++++++++++++++++++++++++++++- Source/cmLocalGenerator.h | 2 +- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f91ed10d0..e7d78cd23 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -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 args; + cmSystemTools::ParseWindowsCommandLine(flags.c_str(), args); + std::string fixedFlags; + const char* sep = 0; + for(std::vector::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& dirs, bool filter_system_dirs) diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index ac520b055..587a6f2b2 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -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 = "");