Merge topic 'cuda_unity'

b90ae10dda Add support for unity builds with CUDA sources
c99ff40b21 Unity: refactor unity extension logic to single function

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9655
This commit is contained in:
Brad King
2024-08-13 15:01:01 +00:00
committed by Kitware Robot
18 changed files with 248 additions and 15 deletions

View File

@@ -3163,6 +3163,25 @@ void cmLocalGenerator::WriteUnitySourceInclude(
unity_file << "\n";
}
namespace {
std::string unity_file_extension(std::string const& lang)
{
std::string extension;
if (lang == "C") {
extension = "_c.c";
} else if (lang == "CXX") {
extension = "_cxx.cxx";
} else if (lang == "CUDA") {
extension = "_cu.cu";
} else if (lang == "OBJC") {
extension = "_m.m";
} else if (lang == "OBJCXX") {
extension = "_mm.mm";
}
return extension;
}
}
std::vector<cmLocalGenerator::UnitySource>
cmLocalGenerator::AddUnityFilesModeAuto(
cmGeneratorTarget* target, std::string const& lang,
@@ -3181,17 +3200,8 @@ cmLocalGenerator::AddUnityFilesModeAuto(
chunk = std::min(itemsLeft, batchSize);
std::string extension;
if (lang == "C") {
extension = "_c.c";
} else if (lang == "CXX") {
extension = "_cxx.cxx";
} else if (lang == "OBJC") {
extension = "_m.m";
} else if (lang == "OBJCXX") {
extension = "_mm.mm";
}
std::string filename = cmStrCat(filename_base, "unity_", batch, extension);
std::string filename =
cmStrCat(filename_base, "unity_", batch, unity_file_extension(lang));
auto const begin = filtered_sources.begin() + batch * batchSize;
auto const end = begin + chunk;
unity_files.emplace_back(this->WriteUnitySource(
@@ -3229,8 +3239,8 @@ cmLocalGenerator::AddUnityFilesModeGroup(
for (auto const& item : explicit_mapping) {
auto const& name = item.first;
std::string filename = cmStrCat(filename_base, "unity_", name,
(lang == "C") ? "_c.c" : "_cxx.cxx");
std::string filename =
cmStrCat(filename_base, "unity_", name, unity_file_extension(lang));
unity_files.emplace_back(this->WriteUnitySource(
target, configs, cmMakeRange(item.second), beforeInclude, afterInclude,
std::move(filename)));
@@ -3292,7 +3302,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
cmValue afterInclude = target->GetProperty("UNITY_BUILD_CODE_AFTER_INCLUDE");
cmValue unityMode = target->GetProperty("UNITY_BUILD_MODE");
for (std::string lang : { "C", "CXX", "OBJC", "OBJCXX" }) {
for (std::string lang : { "C", "CXX", "OBJC", "OBJCXX", "CUDA" }) {
std::vector<UnityBatchedSource> filtered_sources;
std::copy_if(unitySources.begin(), unitySources.end(),
std::back_inserter(filtered_sources),

View File

@@ -2686,6 +2686,12 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
}
}
}
if (haveUnityBuild && strcmp(tool, "CudaCompile") == 0 &&
si.Source->GetProperty("UNITY_SOURCE_FILE")) {
if (!si.Source->GetPropertyAsBool("SKIP_UNITY_BUILD_INCLUSION")) {
exclude_configs = all_configs;
}
}
if (si.Kind == cmGeneratorTarget::SourceKindObjectSource ||
si.Kind == cmGeneratorTarget::SourceKindUnityBatched) {