From af1354d6c14097f9ec9dda25460e9228fa592fbc Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 15 Mar 2017 10:50:23 +0100 Subject: Autogen: Add AUTOGEN_SOURCE_GROUP support Closes: #16501 --- Source/cmQtAutoGeneratorInitializer.cxx | 73 ++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 94cc981..6ebc234 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -134,6 +134,61 @@ static void AddDefinitionEscaped(cmMakefile* makefile, const char* key, key, cmOutputConverter::EscapeForCMake(cmJoin(values, ";")).c_str()); } +static bool AddToSourceGroup(cmMakefile* makefile, const std::string& fileName, + cmQtAutoGeneratorCommon::GeneratorType genType) +{ + cmSourceGroup* sourceGroup = CM_NULLPTR; + // Acquire source group + { + const char* groupName = CM_NULLPTR; + // Use generator specific group name + switch (genType) { + case cmQtAutoGeneratorCommon::MOC: + groupName = + makefile->GetState()->GetGlobalProperty("AUTOMOC_SOURCE_GROUP"); + break; + case cmQtAutoGeneratorCommon::RCC: + groupName = + makefile->GetState()->GetGlobalProperty("AUTORCC_SOURCE_GROUP"); + break; + default: + break; + } + // Use default group name on demand + if ((groupName == CM_NULLPTR) || (*groupName == 0)) { + groupName = + makefile->GetState()->GetGlobalProperty("AUTOGEN_SOURCE_GROUP"); + } + // Generate a source group on demand + if ((groupName != CM_NULLPTR) && (*groupName != 0)) { + { + const char* delimiter = + makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); + if (delimiter == CM_NULLPTR) { + delimiter = "\\"; + } + std::vector folders = + cmSystemTools::tokenize(groupName, delimiter); + sourceGroup = makefile->GetSourceGroup(folders); + if (sourceGroup == CM_NULLPTR) { + makefile->AddSourceGroup(folders); + sourceGroup = makefile->GetSourceGroup(folders); + } + } + if (sourceGroup == CM_NULLPTR) { + cmSystemTools::Error( + "Autogen: Could not create or find source group: ", + cmQtAutoGeneratorCommon::Quoted(groupName).c_str()); + return false; + } + } + } + if (sourceGroup != CM_NULLPTR) { + sourceGroup->AddGroupFile(fileName); + } + return true; +} + static void AcquireScanFiles(cmGeneratorTarget const* target, std::vector& mocUicSources, std::vector& mocUicHeaders, @@ -531,11 +586,14 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenSources( { if (target->GetPropertyAsBool("AUTOMOC")) { cmMakefile* makefile = target->Target->GetMakefile(); - const std::string mocCppFile = - GetAutogenTargetBuildDir(target) + "moc_compilation.cpp"; - cmSourceFile* gf = makefile->GetOrCreateSource(mocCppFile, true); - gf->SetProperty("SKIP_AUTOGEN", "On"); + std::string mocCppFile = GetAutogenTargetBuildDir(target); + mocCppFile += "moc_compilation.cpp"; + { + cmSourceFile* gFile = makefile->GetOrCreateSource(mocCppFile, true); + gFile->SetProperty("SKIP_AUTOGEN", "On"); + } target->AddSource(mocCppFile); + AddToSourceGroup(makefile, mocCppFile, cmQtAutoGeneratorCommon::MOC); } } @@ -700,9 +758,12 @@ void cmQtAutoGeneratorInitializer::InitializeAutogenTarget( autogenProvides.push_back(rccOut); // Add rcc output file to origin target sources - cmSourceFile* gf = makefile->GetOrCreateSource(rccOut, true); - gf->SetProperty("SKIP_AUTOGEN", "On"); + { + cmSourceFile* gFile = makefile->GetOrCreateSource(rccOut, true); + gFile->SetProperty("SKIP_AUTOGEN", "On"); + } target->AddSource(rccOut); + AddToSourceGroup(makefile, rccOut, cmQtAutoGeneratorCommon::RCC); } if (PropertyEnabled(sf, "GENERATED")) { -- cgit v0.12