Unity build: Include GENERATED files into unity build

There is no reason to skip the generated files, in case of problems
one can use the SKIP_UNITY_BUILD_INCLUSION property.

Fixes: #19925
This commit is contained in:
Cristian Adam
2019-11-06 14:57:12 +01:00
committed by Brad King
parent e0ec13059a
commit 7ddf462304
4 changed files with 6 additions and 11 deletions
+2 -3
View File
@@ -40,9 +40,8 @@ Since multiple source files are included into one source file,
it can lead to ODR errors. This section contains properties it can lead to ODR errors. This section contains properties
which help fixing these errors. which help fixing these errors.
The source files marked by :prop_sf:`GENERATED` will be skipped The source files marked by :prop_sf:`SKIP_UNITY_BUILD_INCLUSION`
from unity build. This applies also for the source files marked will be skipped from unity build.
with :prop_sf:`SKIP_UNITY_BUILD_INCLUSION`.
The source files that have :prop_sf:`COMPILE_OPTIONS`, The source files that have :prop_sf:`COMPILE_OPTIONS`,
:prop_sf:`COMPILE_DEFINITIONS`, :prop_sf:`COMPILE_FLAGS`, or :prop_sf:`COMPILE_DEFINITIONS`, :prop_sf:`COMPILE_FLAGS`, or
-1
View File
@@ -2441,7 +2441,6 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
std::back_inserter(filtered_sources), [&](cmSourceFile* sf) { std::back_inserter(filtered_sources), [&](cmSourceFile* sf) {
return sf->GetLanguage() == lang && return sf->GetLanguage() == lang &&
!sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") && !sf->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION") &&
!sf->GetPropertyAsBool("GENERATED") &&
!sf->GetProperty("COMPILE_OPTIONS") && !sf->GetProperty("COMPILE_OPTIONS") &&
!sf->GetProperty("COMPILE_DEFINITIONS") && !sf->GetProperty("COMPILE_DEFINITIONS") &&
!sf->GetProperty("COMPILE_FLAGS") && !sf->GetProperty("COMPILE_FLAGS") &&
@@ -1,9 +1,9 @@
set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0.c") set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0.c")
file(STRINGS ${unitybuild_c} unitybuild_c_strings) file(STRINGS ${unitybuild_c} unitybuild_c_strings)
string(REGEX MATCH "\\/s[1-6].c" matched_files_1_6 ${unitybuild_c_strings}) string(REGEX MATCH "\\/s[2-6].c" matched_files_2_6 ${unitybuild_c_strings})
if(matched_files_1_6) if(matched_files_2_6)
set(RunCMake_TEST_FAILED "Generated unity contains s1.c -> s6.c which should have been skipped") set(RunCMake_TEST_FAILED "Generated unity contains s2.c -> s6.c which should have been skipped")
return() return()
endif() endif()
@@ -1,7 +1,7 @@
project(unitybuild_skip C) project(unitybuild_skip C)
set(srcs "") set(srcs "")
foreach(s RANGE 1 8) foreach(s RANGE 2 8)
set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c")
file(WRITE "${src}" "int s${s}(void) { return 0; }\n") file(WRITE "${src}" "int s${s}(void) { return 0; }\n")
list(APPEND srcs "${src}") list(APPEND srcs "${src}")
@@ -11,9 +11,6 @@ add_library(tgt SHARED ${srcs})
set_target_properties(tgt PROPERTIES UNITY_BUILD ON) set_target_properties(tgt PROPERTIES UNITY_BUILD ON)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s1.c
PROPERTIES GENERATED ON)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s2.c set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s2.c
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)