MCPcopy Create free account
hub / github.com/Kitware/CMake / AddUnityBuild

Method AddUnityBuild

Source/cmLocalGenerator.cxx:3251–3359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3249}
3250
3251void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
3252{
3253 // cmFastbuildNormalTargetGenerator handles unity build.
3254 if (this->GetGlobalGenerator()->IsFastbuild() ||
3255 !target->GetPropertyAsBool("UNITY_BUILD")) {
3256 return;
3257 }
3258
3259 std::vector<UnityBatchedSource> unitySources;
3260
3261 std::vector<std::string> configs =
3262 this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
3263
3264 std::map<cmSourceFile const*, size_t> index;
3265
3266 for (size_t ci = 0; ci < configs.size(); ++ci) {
3267 // FIXME: Refactor collection of sources to not evaluate object libraries.
3268 // Their final set of object files might be transformed by unity builds.
3269 std::vector<cmSourceFile*> sources;
3270 target->GetSourceFiles(sources, configs[ci]);
3271 for (cmSourceFile* sf : sources) {
3272 // Files which need C++ scanning cannot participate in unity builds as
3273 // there is a single place in TUs that may perform module-dependency bits
3274 // and a unity source cannot `#include` them in-order and represent a
3275 // valid TU.
3276 if (sf->GetLanguage() == "CXX"_s &&
3277 target->NeedDyndepForSource("CXX", configs[ci], sf)) {
3278 continue;
3279 }
3280
3281 auto mi = index.find(sf);
3282 if (mi == index.end()) {
3283 unitySources.emplace_back(sf);
3284 std::map<cmSourceFile const*, size_t>::value_type entry(
3285 sf, unitySources.size() - 1);
3286 mi = index.insert(entry).first;
3287 }
3288 unitySources[mi->second].Configs.emplace_back(ci);
3289 }
3290 }
3291
3292 std::string filename_base =
3293 cmStrCat(target->GetCMFSupportDirectory(), "/Unity/");
3294
3295 cmValue batchSizeString = target->GetProperty("UNITY_BUILD_BATCH_SIZE");
3296 size_t const unityBatchSize = batchSizeString
3297 ? static_cast<size_t>(std::atoi(batchSizeString->c_str()))
3298 : 0;
3299
3300 cmValue beforeInclude =
3301 target->GetProperty("UNITY_BUILD_CODE_BEFORE_INCLUDE");
3302 cmValue afterInclude = target->GetProperty("UNITY_BUILD_CODE_AFTER_INCLUDE");
3303 cmValue unityMode = target->GetProperty("UNITY_BUILD_MODE");
3304 UnityPathMode pathMode = target->GetPropertyAsBool("UNITY_BUILD_RELOCATABLE")
3305 ? UnityPathMode::Relative
3306 : UnityPathMode::Absolute;
3307
3308 for (std::string lang : { "C", "CXX", "OBJC", "OBJCXX", "CUDA" }) {

Callers 1

AddAutomaticSourcesMethod · 0.80

Calls 15

GetGlobalGeneratorMethod · 0.95
IssueMessageMethod · 0.95
GetMakefileMethod · 0.95
GetGeneratorConfigsMethod · 0.80
GetSourceFilesMethod · 0.80
GetLanguageMethod · 0.80
NeedDyndepForSourceMethod · 0.80
emplace_backMethod · 0.80
c_strMethod · 0.80
GetOrCreateSourceMethod · 0.80
SetSpecialSourceTypeMethod · 0.80

Tested by

no test coverage detected