Unity: Proper handling of object libraries

Fixes: #20051
This commit is contained in:
Cristian Adam
2019-12-07 15:03:16 +01:00
parent 5ae07e7166
commit fa93b4a59b
5 changed files with 31 additions and 0 deletions

View File

@@ -1567,6 +1567,15 @@ bool cmGlobalGenerator::AddAutomaticSources()
lg->AddPchDependencies(gt);
}
}
// 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 (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) {
gt->ClearSourcesCache();
}
}
return true;
}

View File

@@ -2307,6 +2307,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);
@@ -2469,6 +2470,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);

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)