| 236 | } |
| 237 | |
| 238 | void cmGlobalFastbuildGenerator::ProcessEnvironment() |
| 239 | { |
| 240 | bool const CaptureSystemEnv = |
| 241 | !this->GetGlobalSetting(FASTBUILD_CAPTURE_SYSTEM_ENV).IsSet() || |
| 242 | this->GetGlobalSetting(FASTBUILD_CAPTURE_SYSTEM_ENV).IsOn(); |
| 243 | // On Windows environment is needed for MSVC, but preserve ability to discard |
| 244 | // it from the generated file if requested. |
| 245 | if (CaptureSystemEnv) { |
| 246 | LocalEnvironment = cmSystemTools::GetEnvironmentVariables(); |
| 247 | } |
| 248 | // FASTBuild strips off "-isysroot" command line option (see : |
| 249 | // https://github.com/fastbuild/fastbuild/issues/1066). |
| 250 | // If 'SDK_ROOT' is not set via env and '-isysroot' is absent, AppleClang |
| 251 | // seems to use MacOS SDK by default (even though FBuild flattens includes |
| 252 | // before compiling). It breaks cross-compilation for iOS. Tested in |
| 253 | // "RunCMake.Framework" test. |
| 254 | std::string const osxRoot = this->GetSafeGlobalSetting("CMAKE_OSX_SYSROOT"); |
| 255 | if (!osxRoot.empty()) { |
| 256 | LocalEnvironment.emplace_back("SDKROOT=" + osxRoot); |
| 257 | } |
| 258 | |
| 259 | auto const EnvOverrides = |
| 260 | this->GetSafeGlobalSetting(FASTBUILD_ENV_OVERRIDES); |
| 261 | |
| 262 | if (!EnvOverrides.empty()) { |
| 263 | auto const overrideEnvVar = [this](std::string const& prefix, |
| 264 | std::string val) { |
| 265 | auto const iter = |
| 266 | std::find_if(LocalEnvironment.begin(), LocalEnvironment.end(), |
| 267 | [&prefix](std::string const& value) { |
| 268 | return cmSystemTools::StringStartsWith(value.c_str(), |
| 269 | prefix.c_str()); |
| 270 | }); |
| 271 | if (iter != LocalEnvironment.end()) { |
| 272 | *iter = std::move(val); |
| 273 | } else { |
| 274 | LocalEnvironment.emplace_back(std::move(val)); |
| 275 | } |
| 276 | }; |
| 277 | for (auto const& val : cmList{ EnvOverrides }) { |
| 278 | auto const pos = val.find('='); |
| 279 | if (pos != std::string::npos && ((pos + 1) < val.size())) { |
| 280 | overrideEnvVar(val.substr(0, pos + 1), val); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // Empty strings are not allowed. |
| 286 | LocalEnvironment.erase( |
| 287 | std::remove_if(LocalEnvironment.begin(), LocalEnvironment.end(), |
| 288 | [](std::string const& s) { return s.empty(); }), |
| 289 | LocalEnvironment.end()); |
| 290 | } |
| 291 | |
| 292 | std::unique_ptr<cmGlobalGeneratorFactory> |
| 293 | cmGlobalFastbuildGenerator::NewFactory() |
no test coverage detected