diff options
author | Brad King <brad.king@kitware.com> | 2013-06-27 16:04:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-06-27 16:57:32 (GMT) |
commit | d221eac81261679d3580849218220290fcd122df (patch) | |
tree | 15df696e0e790c05387fd0441d52110e16a71ec1 /Source/cmLocalGenerator.cxx | |
parent | b6385cabec5356b471dc37bd999d1803555ba386 (diff) | |
download | CMake-d221eac81261679d3580849218220290fcd122df.zip CMake-d221eac81261679d3580849218220290fcd122df.tar.gz CMake-d221eac81261679d3580849218220290fcd122df.tar.bz2 |
Refactor target COMPILE_OPTIONS and COMPILE_FLAGS handling
Replace the cmLocalGenerator GetCompileOptions method with an
AddCompileOptions method since all call sites of the former simply
append the result to a flags string anyway.
Add a "lang" argument to AddCompileOptions and move the
CMAKE_<LANG>_FLAGS_REGEX filter into it. Move the call sites in each
generator to a location that has both the language and configuration
available. In the Makefile generator this also moves the flags from
build.make to flags.make where they belong.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ccbccb2..00846d5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1339,22 +1339,50 @@ std::string cmLocalGenerator::GetIncludeFlags( } //---------------------------------------------------------------------------- -void cmLocalGenerator::GetCompileOptions(std::string& flags, - cmTarget* target, - const char *config) +void cmLocalGenerator::AddCompileOptions( + std::string& flags, cmTarget* target, + const char* lang, const char* config + ) { - // Add target-specific flags. - if(const char *prop = target->GetProperty("COMPILE_FLAGS")) + std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX"; + if(const char* langFlagRegexStr = + this->Makefile->GetDefinition(langFlagRegexVar.c_str())) { - this->AppendFlags(flags, prop); + // Filter flags acceptable to this language. + cmsys::RegularExpression r(langFlagRegexStr); + std::vector<std::string> opts; + if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) + { + cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); + } + target->GetCompileOptions(opts, config); + for(std::vector<std::string>::const_iterator i = opts.begin(); + i != opts.end(); ++i) + { + if(r.find(i->c_str())) + { + // (Re-)Escape this flag. COMPILE_FLAGS were already parsed + // as a command line above, and COMPILE_OPTIONS are escaped. + this->AppendFlagEscape(flags, i->c_str()); + } + } } - - std::vector<std::string> opts; // TODO: Emitted. - target->GetCompileOptions(opts, config); - for(std::vector<std::string>::const_iterator li = opts.begin(); - li != opts.end(); ++li) + else { - this->AppendFlagEscape(flags, li->c_str()); + // Use all flags. + if(const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) + { + // COMPILE_FLAGS are not escaped for historical reasons. + this->AppendFlags(flags, targetFlags); + } + std::vector<std::string> opts; // TODO: Emitted. + target->GetCompileOptions(opts, config); + for(std::vector<std::string>::const_iterator i = opts.begin(); + i != opts.end(); ++i) + { + // COMPILE_OPTIONS are escaped. + this->AppendFlagEscape(flags, i->c_str()); + } } } |