Merge branch 'backport-unity-object-libraries' into unity-object-libraries

This commit is contained in:
Brad King
2019-12-08 11:21:38 -05:00
6 changed files with 36 additions and 8 deletions

View File

@@ -1566,13 +1566,24 @@ bool cmGlobalGenerator::AddAutomaticSources()
for (cmLocalGenerator* lg : this->LocalGenerators) {
lg->CreateEvaluationFileOutputs();
for (const auto& gt : lg->GetGeneratorTargets()) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
gt->GetType() == cmStateEnums::UTILITY ||
gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
}
lg->AddUnityBuild(gt.get());
lg->AddPchDependencies(gt.get());
}
}
// The above transformations may have changed the classification of sources.
// Clear the source list and classification cache (KindedSources) of all
// targets so that it will be recomputed correctly by the generators later
// now that the above transformations are done for all targets.
for (cmLocalGenerator* lg : this->LocalGenerators) {
for (const auto& gt : lg->GetGeneratorTargets()) {
gt->ClearSourcesCache();
}
}
return true;
}

View File

@@ -2393,6 +2393,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
}
const std::string buildType = cmSystemTools::UpperCase(config);
// FIXME: Refactor collection of sources to not evaluate object libraries.
std::vector<cmSourceFile*> sources;
target->GetSourceFiles(sources, buildType);
@@ -2549,6 +2550,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/",
target->GetName(), ".dir/Unity/");
// FIXME: Refactor collection of sources to not evaluate object libraries.
std::vector<cmSourceFile*> sources;
target->GetSourceFiles(sources, buildType);
@@ -2598,12 +2600,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
for (; begin != end; ++begin) {
cmSourceFile* sf = filtered_sources[begin];
// Only in Visual Studio generator we keep the source files
// for explicit processing.
if (!this->GetGlobalGenerator()->IsMultiConfig() ||
this->GetGlobalGenerator()->IsXcode()) {
target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
}
target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str());
if (beforeInclude) {

View File

@@ -2160,7 +2160,6 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
this->WriteExtraSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindHeader:
case cmGeneratorTarget::SourceKindUnityBatched:
this->WriteHeaderSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindIDL:
@@ -2172,6 +2171,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
case cmGeneratorTarget::SourceKindModuleDefinition:
tool = "None";
break;
case cmGeneratorTarget::SourceKindUnityBatched:
case cmGeneratorTarget::SourceKindObjectSource: {
const std::string& lang = si.Source->GetLanguage();
if (lang == "C" || lang == "CXX") {

View File

@@ -4,4 +4,10 @@
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
+
CMake Error at OwnSources.cmake:[0-9]+ \(add_library\):
The SOURCES of "A" use a generator expression that depends on the SOURCES
themselves.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
+
CMake Generate step failed\. Build files cannot be regenerated correctly\.$

View File

@@ -21,3 +21,4 @@ function(run_test name)
endfunction()
run_test(unitybuild_runtest)
run_test(unitybuild_object_library)

View File

@@ -0,0 +1,13 @@
project(unitybuild_object_library C)
set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property
add_library(lib OBJECT func.c)
add_library(other-lib STATIC func.c)
add_executable(main main.c)
target_link_libraries(main PRIVATE lib)
enable_testing()
add_test(NAME main COMMAND main)