Commit eae743bf authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'unity-HEADER_FILE_ONLY' into release-3.16

9a541832

 Unity: Don't include sources with HEADER_FILE_ONLY property set
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4023
parents 88e0dca4 9a541832
...@@ -1081,6 +1081,7 @@ Json::Value Target::DumpSource(cmGeneratorTarget::SourceAndKind const& sk, ...@@ -1081,6 +1081,7 @@ Json::Value Target::DumpSource(cmGeneratorTarget::SourceAndKind const& sk,
case cmGeneratorTarget::SourceKindModuleDefinition: case cmGeneratorTarget::SourceKindModuleDefinition:
case cmGeneratorTarget::SourceKindResx: case cmGeneratorTarget::SourceKindResx:
case cmGeneratorTarget::SourceKindXaml: case cmGeneratorTarget::SourceKindXaml:
case cmGeneratorTarget::SourceKindUnityBatched:
break; break;
} }
......
...@@ -1569,6 +1569,8 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, ...@@ -1569,6 +1569,8 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
kind = SourceKindCustomCommand; kind = SourceKindCustomCommand;
} else if (this->Target->GetType() == cmStateEnums::UTILITY) { } else if (this->Target->GetType() == cmStateEnums::UTILITY) {
kind = SourceKindExtra; kind = SourceKindExtra;
} else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) {
kind = SourceKindUnityBatched;
} else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) { } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
kind = SourceKindHeader; kind = SourceKindHeader;
} else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
...@@ -3588,6 +3590,23 @@ std::string cmGeneratorTarget::GetPchUseCompileOptions( ...@@ -3588,6 +3590,23 @@ std::string cmGeneratorTarget::GetPchUseCompileOptions(
return inserted.first->second; return inserted.first->second;
} }
void cmGeneratorTarget::AddSourceFileToUnityBatch(
const std::string& sourceFilename)
{
this->UnityBatchedSourceFiles.insert(sourceFilename);
}
bool cmGeneratorTarget::IsSourceFilePartOfUnityBatch(
const std::string& sourceFilename) const
{
if (!this->GetPropertyAsBool("UNITY_BUILD")) {
return false;
}
return this->UnityBatchedSourceFiles.find(sourceFilename) !=
this->UnityBatchedSourceFiles.end();
}
void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result, void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
const std::string& config, const std::string& config,
const std::string& language) const const std::string& language) const
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <set> #include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -98,7 +99,8 @@ public: ...@@ -98,7 +99,8 @@ public:
SourceKindModuleDefinition, SourceKindModuleDefinition,
SourceKindObjectSource, SourceKindObjectSource,
SourceKindResx, SourceKindResx,
SourceKindXaml SourceKindXaml,
SourceKindUnityBatched
}; };
/** A source file paired with a kind (classification). */ /** A source file paired with a kind (classification). */
...@@ -471,6 +473,9 @@ public: ...@@ -471,6 +473,9 @@ public:
std::string GetPchUseCompileOptions(const std::string& config, std::string GetPchUseCompileOptions(const std::string& config,
const std::string& language); const std::string& language);
void AddSourceFileToUnityBatch(const std::string& sourceFilename);
bool IsSourceFilePartOfUnityBatch(const std::string& sourceFilename) const;
bool IsSystemIncludeDirectory(const std::string& dir, bool IsSystemIncludeDirectory(const std::string& dir,
const std::string& config, const std::string& config,
const std::string& language) const; const std::string& language) const;
...@@ -893,6 +898,8 @@ private: ...@@ -893,6 +898,8 @@ private:
mutable std::map<std::string, std::string> PchCreateCompileOptions; mutable std::map<std::string, std::string> PchCreateCompileOptions;
mutable std::map<std::string, std::string> PchUseCompileOptions; mutable std::map<std::string, std::string> PchUseCompileOptions;
std::unordered_set<std::string> UnityBatchedSourceFiles;
void ExpandLinkItems(std::string const& prop, std::string const& value, void ExpandLinkItems(std::string const& prop, std::string const& value,
std::string const& config, std::string const& config,
const cmGeneratorTarget* headTarget, const cmGeneratorTarget* headTarget,
......
...@@ -1174,7 +1174,9 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget( ...@@ -1174,7 +1174,9 @@ bool cmGlobalXCodeGenerator::CreateXCodeTarget(
headerFiles.push_back(xsf); headerFiles.push_back(xsf);
} else if (tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource) { } else if (tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource) {
resourceFiles.push_back(xsf); resourceFiles.push_back(xsf);
} else if (!sourceFile->GetPropertyAsBool("HEADER_FILE_ONLY")) { } else if (!sourceFile->GetPropertyAsBool("HEADER_FILE_ONLY") &&
!gtgt->IsSourceFilePartOfUnityBatch(
sourceFile->ResolveFullPath())) {
// Include this file in the build if it has a known language // Include this file in the build if it has a known language
// and has not been listed as an ignored extension for this // and has not been listed as an ignored extension for this
// generator. // generator.
......
...@@ -2441,6 +2441,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) ...@@ -2441,6 +2441,7 @@ 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("HEADER_FILE_ONLY") &&
!sf->GetProperty("COMPILE_OPTIONS") && !sf->GetProperty("COMPILE_OPTIONS") &&
!sf->GetProperty("COMPILE_DEFINITIONS") && !sf->GetProperty("COMPILE_DEFINITIONS") &&
!sf->GetProperty("COMPILE_FLAGS") && !sf->GetProperty("COMPILE_FLAGS") &&
...@@ -2475,11 +2476,10 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target) ...@@ -2475,11 +2476,10 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmSourceFile* sf = filtered_sources[begin]; cmSourceFile* sf = filtered_sources[begin];
// Only in Visual Studio generator we keep the source files // Only in Visual Studio generator we keep the source files
// for explicit processing. For the rest the source files will // for explicit processing.
// not be included in the project.
if (!this->GetGlobalGenerator()->IsMultiConfig() || if (!this->GetGlobalGenerator()->IsMultiConfig() ||
this->GetGlobalGenerator()->IsXcode()) { this->GetGlobalGenerator()->IsXcode()) {
sf->SetProperty("HEADER_FILE_ONLY", "ON"); target->AddSourceFileToUnityBatch(sf->ResolveFullPath());
} }
sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str()); sf->SetProperty("UNITY_SOURCE_FILE", filename.c_str());
......
...@@ -2141,6 +2141,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) ...@@ -2141,6 +2141,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
this->WriteExtraSource(e1, si.Source); this->WriteExtraSource(e1, si.Source);
break; break;
case cmGeneratorTarget::SourceKindHeader: case cmGeneratorTarget::SourceKindHeader:
case cmGeneratorTarget::SourceKindUnityBatched:
this->WriteHeaderSource(e1, si.Source); this->WriteHeaderSource(e1, si.Source);
break; break;
case cmGeneratorTarget::SourceKindIDL: case cmGeneratorTarget::SourceKindIDL:
......
...@@ -2,6 +2,7 @@ project(unitybuild_runtest C) ...@@ -2,6 +2,7 @@ project(unitybuild_runtest C)
set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property
add_library(lib main.c func.c)
add_executable(main main.c func.c) add_executable(main main.c func.c)
enable_testing() enable_testing()
......
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[2-6].c" matched_files_2_6 ${unitybuild_c_strings}) string(REGEX MATCH "\\/s[1-6].c" matched_files_1_6 ${unitybuild_c_strings})
if(matched_files_2_6) if(matched_files_1_6)
set(RunCMake_TEST_FAILED "Generated unity contains s2.c -> s6.c which should have been skipped") set(RunCMake_TEST_FAILED "Generated unity contains s1.c -> s6.c which should have been skipped")
return() return()
endif() endif()
......
project(unitybuild_skip C) project(unitybuild_skip C)
set(srcs "") set(srcs "")
foreach(s RANGE 2 8) foreach(s RANGE 1 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,6 +11,9 @@ add_library(tgt SHARED ${srcs}) ...@@ -11,6 +11,9 @@ 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 HEADER_FILE_ONLY 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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment