TODO: Most of the code is picked up from void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink), void cmMakefileTargetGenerator::WriteTargetLanguageFlags() Refactor it.
| 185 | // void cmMakefileTargetGenerator::WriteTargetLanguageFlags() |
| 186 | // Refactor it. |
| 187 | std::string cmNinjaTargetGenerator::ComputeFlagsForObject( |
| 188 | cmSourceFile const* source, std::string const& language, |
| 189 | std::string const& config, std::string const& objectFileName) |
| 190 | { |
| 191 | std::unordered_map<std::string, std::string> pchSources; |
| 192 | std::vector<std::string> pchArchs = |
| 193 | this->GeneratorTarget->GetPchArchs(config, language); |
| 194 | |
| 195 | std::string filterArch; |
| 196 | for (std::string const& arch : pchArchs) { |
| 197 | std::string const pchSource = |
| 198 | this->GeneratorTarget->GetPchSource(config, language, arch); |
| 199 | if (pchSource == source->GetFullPath()) { |
| 200 | filterArch = arch; |
| 201 | } |
| 202 | if (!pchSource.empty()) { |
| 203 | pchSources.insert(std::make_pair(pchSource, arch)); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | std::string flags; |
| 208 | // Explicitly add the explicit language flag before any other flag |
| 209 | // so user flags can override it. |
| 210 | this->GeneratorTarget->AddExplicitLanguageFlags(flags, *source); |
| 211 | |
| 212 | if (!flags.empty()) { |
| 213 | flags += " "; |
| 214 | } |
| 215 | flags += this->GetFlags(language, config, filterArch); |
| 216 | |
| 217 | // Add Fortran format flags. |
| 218 | if (language == "Fortran") { |
| 219 | this->AppendFortranFormatFlags(flags, *source); |
| 220 | this->AppendFortranPreprocessFlags(flags, *source, |
| 221 | PreprocessFlagsRequired::NO); |
| 222 | } |
| 223 | |
| 224 | // Add source file specific flags. |
| 225 | cmGeneratorExpressionInterpreter genexInterpreter( |
| 226 | this->LocalGenerator, config, this->GeneratorTarget, language); |
| 227 | |
| 228 | std::string const COMPILE_FLAGS("COMPILE_FLAGS"); |
| 229 | if (cmValue cflags = source->GetProperty(COMPILE_FLAGS)) { |
| 230 | this->LocalGenerator->AppendFlags( |
| 231 | flags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS)); |
| 232 | } |
| 233 | |
| 234 | std::string const COMPILE_OPTIONS("COMPILE_OPTIONS"); |
| 235 | if (cmValue coptions = source->GetProperty(COMPILE_OPTIONS)) { |
| 236 | this->LocalGenerator->AppendCompileOptions( |
| 237 | flags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS)); |
| 238 | } |
| 239 | |
| 240 | // Add precompile headers compile options. |
| 241 | if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) { |
| 242 | std::string pchOptions; |
| 243 | auto pchIt = pchSources.find(source->GetFullPath()); |
| 244 | if (pchIt != pchSources.end()) { |
no test coverage detected