From 5c058c8f12742dcb96b2e22b43208f345a865fbf Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 24 Sep 2013 20:07:45 +0200 Subject: Rename the cmQtAutomoc class to cmQtAutoGenerators. It will be extended to process .ui and .qrc files too. --- Source/CMakeLists.txt | 4 +- Source/cmGlobalGenerator.cxx | 14 +- Source/cmGlobalGenerator.h | 2 +- Source/cmQtAutoGenerators.cxx | 1321 +++++++++++++++++++++++++++++++++++++++++ Source/cmQtAutoGenerators.h | 96 +++ Source/cmQtAutomoc.cxx | 1317 ---------------------------------------- Source/cmQtAutomoc.h | 96 --- Source/cmcmd.cxx | 4 +- 8 files changed, 1429 insertions(+), 1425 deletions(-) create mode 100644 Source/cmQtAutoGenerators.cxx create mode 100644 Source/cmQtAutoGenerators.h delete mode 100644 Source/cmQtAutomoc.cxx delete mode 100644 Source/cmQtAutomoc.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 01e4f88..e13a304 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -250,8 +250,8 @@ set(SRCS cmPropertyDefinitionMap.h cmPropertyMap.cxx cmPropertyMap.h - cmQtAutomoc.cxx - cmQtAutomoc.h + cmQtAutoGenerators.cxx + cmQtAutoGenerators.h cmRST.cxx cmRST.h cmScriptGenerator.h diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index fb205be..f92fe60 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -18,7 +18,7 @@ #include "cmExternalMakefileProjectGenerator.h" #include "cmake.h" #include "cmMakefile.h" -#include "cmQtAutomoc.h" +#include "cmQtAutoGenerators.h" #include "cmSourceFile.h" #include "cmVersion.h" #include "cmTargetExport.h" @@ -1049,8 +1049,8 @@ void cmGlobalGenerator::Generate() } // Iterate through all targets and set up automoc for those which have - // the AUTOMOC property set - this->CreateAutomocTargets(); + // the AUTOMOC, AUTOUIC or AUTORCC property set + this->CreateQtAutoGeneratorsTargets(); // For each existing cmLocalGenerator unsigned int i; @@ -1206,10 +1206,10 @@ bool cmGlobalGenerator::CheckTargets() } //---------------------------------------------------------------------------- -void cmGlobalGenerator::CreateAutomocTargets() +void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() { #ifdef CMAKE_BUILD_WITH_CMAKE - typedef std::vector > Automocs; + typedef std::vector > Automocs; Automocs automocs; for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) { @@ -1227,7 +1227,7 @@ void cmGlobalGenerator::CreateAutomocTargets() { if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported()) { - cmQtAutomoc automoc; + cmQtAutoGenerators automoc; if(automoc.InitializeMocSourceFile(&target)) { automocs.push_back(std::make_pair(automoc, &target)); @@ -1239,7 +1239,7 @@ void cmGlobalGenerator::CreateAutomocTargets() for (Automocs::iterator it = automocs.begin(); it != automocs.end(); ++it) { - it->first.SetupAutomocTarget(it->second); + it->first.SetupAutoGenerateTarget(it->second); } #endif } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index c930b2b..773da38 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -319,7 +319,7 @@ protected: virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS(); bool CheckTargets(); - void CreateAutomocTargets(); + void CreateQtAutoGeneratorsTargets(); // Fill the ProjectMap, this must be called after LocalGenerators diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx new file mode 100644 index 0000000..24f4498 --- /dev/null +++ b/Source/cmQtAutoGenerators.cxx @@ -0,0 +1,1321 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "cmGlobalGenerator.h" +#include "cmLocalGenerator.h" +#include "cmMakefile.h" +#include "cmSourceFile.h" +#include "cmSystemTools.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) +# include "cmLocalVisualStudioGenerator.h" +#endif + +#include +#include + +#include +#if defined(__APPLE__) +#include +#endif + +#include "cmQtAutoGenerators.h" + + +static bool requiresMocing(const std::string& text, std::string ¯oName) +{ + // this simple check is much much faster than the regexp + if (strstr(text.c_str(), "Q_OBJECT") == NULL + && strstr(text.c_str(), "Q_GADGET") == NULL) + { + return false; + } + + cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); + if (qObjectRegExp.find(text)) + { + macroName = "Q_OBJECT"; + return true; + } + cmsys::RegularExpression qGadgetRegExp("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); + if (qGadgetRegExp.find(text)) + { + macroName = "Q_GADGET"; + return true; + } + return false; +} + + +static std::string findMatchingHeader(const std::string& absPath, + const std::string& mocSubDir, + const std::string& basename, + const std::vector& headerExtensions) +{ + std::string header; + for(std::vector::const_iterator ext = headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + std::string sourceFilePath = absPath + basename + "." + (*ext); + if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) + { + header = sourceFilePath; + break; + } + if (!mocSubDir.empty()) + { + sourceFilePath = mocSubDir + basename + "." + (*ext); + if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) + { + header = sourceFilePath; + break; + } + } + } + + return header; +} + + +static std::string extractSubDir(const std::string& absPath, + const std::string& currentMoc) +{ + std::string subDir; + if (currentMoc.find_first_of('/') != std::string::npos) + { + subDir = absPath + + cmsys::SystemTools::GetFilenamePath(currentMoc) + '/'; + } + return subDir; +} + + +static void copyTargetProperty(cmTarget* destinationTarget, + cmTarget* sourceTarget, + const char* propertyName) +{ + const char* propertyValue = sourceTarget->GetProperty(propertyName); + if (propertyValue) + { + destinationTarget->SetProperty(propertyName, propertyValue); + } +} + + +cmQtAutoGenerators::cmQtAutoGenerators() +:Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0) +,ColorOutput(true) +,RunMocFailed(false) +,GenerateAll(false) +{ + + std::string colorEnv = ""; + cmsys::SystemTools::GetEnv("COLOR", colorEnv); + if(!colorEnv.empty()) + { + if(cmSystemTools::IsOn(colorEnv.c_str())) + { + this->ColorOutput = true; + } + else + { + this->ColorOutput = false; + } + } +} + +bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) +{ + cmMakefile* makefile = target->GetMakefile(); + // don't do anything if there is no Qt4 or Qt5Core (which contains moc): + std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); + if (qtMajorVersion == "") + { + qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); + } + if (qtMajorVersion != "4" && qtMajorVersion != "5") + { + return false; + } + + std::string automocTargetName = target->GetName(); + automocTargetName += "_automoc"; + std::string mocCppFile = makefile->GetCurrentOutputDirectory(); + mocCppFile += "/"; + mocCppFile += automocTargetName; + mocCppFile += ".cpp"; + cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(), + true); + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", + mocCppFile.c_str(), false); + + target->AddSourceFile(mocCppSource); + return true; +} + +static void GetCompileDefinitionsAndDirectories(cmTarget *target, + const char * config, + std::string &incs, + std::string &defs) +{ + cmMakefile* makefile = target->GetMakefile(); + cmLocalGenerator* localGen = makefile->GetLocalGenerator(); + std::vector includeDirs; + cmGeneratorTarget gtgt(target); + // Get the include dirs for this target, without stripping the implicit + // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667 + localGen->GetIncludeDirectories(includeDirs, >gt, "CXX", config, false); + const char* sep = ""; + incs = ""; + for(std::vector::const_iterator incDirIt = includeDirs.begin(); + incDirIt != includeDirs.end(); + ++incDirIt) + { + incs += sep; + sep = ";"; + incs += *incDirIt; + } + + std::set defines; + localGen->AddCompileDefinitions(defines, target, config); + + sep = ""; + for(std::set::const_iterator defIt = defines.begin(); + defIt != defines.end(); + ++defIt) + { + defs += sep; + sep = ";"; + defs += *defIt; + } +} + +void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) +{ + cmMakefile* makefile = target->GetMakefile(); + const char* targetName = target->GetName(); + + bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE"); + + // create a custom target for running automoc at buildtime: + std::string automocTargetName = targetName; + automocTargetName += "_automoc"; + + std::string targetDir = makefile->GetCurrentOutputDirectory(); + targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); + targetDir += "/"; + targetDir += automocTargetName; + targetDir += ".dir/"; + + cmCustomCommandLine currentLine; + currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND")); + currentLine.push_back("-E"); + currentLine.push_back("cmake_automoc"); + currentLine.push_back(targetDir); + currentLine.push_back("$"); + + cmCustomCommandLines commandLines; + commandLines.push_back(currentLine); + + std::string workingDirectory = cmSystemTools::CollapseFullPath( + "", makefile->GetCurrentOutputDirectory()); + + std::vector depends; + std::string automocComment = "Automoc for target "; + automocComment += targetName; + +#if defined(_WIN32) && !defined(__CYGWIN__) + bool usePRE_BUILD = false; + cmLocalGenerator* localGen = makefile->GetLocalGenerator(); + cmGlobalGenerator* gg = localGen->GetGlobalGenerator(); + if(strstr(gg->GetName(), "Visual Studio")) + { + cmLocalVisualStudioGenerator* vslg = + static_cast(localGen); + // Under VS >= 7 use a PRE_BUILD event instead of a separate target to + // reduce the number of targets loaded into the IDE. + // This also works around a VS 11 bug that may skip updating the target: + // https://connect.microsoft.com/VisualStudio/feedback/details/769495 + usePRE_BUILD = vslg->GetVersion() >= cmLocalVisualStudioGenerator::VS7; + } + if(usePRE_BUILD) + { + // Add the pre-build command directly to bypass the OBJECT_LIBRARY + // rejection in cmMakefile::AddCustomCommandToTarget because we know + // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. + std::vector no_output; + cmCustomCommand cc(makefile, no_output, depends, + commandLines, automocComment.c_str(), + workingDirectory.c_str()); + cc.SetEscapeOldStyle(false); + cc.SetEscapeAllowMakeVars(true); + target->GetPreBuildCommands().push_back(cc); + } + else +#endif + { + cmTarget* automocTarget = makefile->AddUtilityCommand( + automocTargetName.c_str(), true, + workingDirectory.c_str(), depends, + commandLines, false, automocComment.c_str()); + // Set target folder + const char* automocFolder = makefile->GetCMakeInstance()->GetProperty( + "AUTOMOC_TARGETS_FOLDER"); + if (automocFolder && *automocFolder) + { + automocTarget->SetProperty("FOLDER", automocFolder); + } + else + { + // inherit FOLDER property from target (#13688) + copyTargetProperty(automocTarget, target, "FOLDER"); + } + + target->AddUtility(automocTargetName.c_str()); + } + + // configure a file to get all information to automoc at buildtime: + std::string _moc_files; + std::string _moc_headers; + const char* sepFiles = ""; + const char* sepHeaders = ""; + + const std::vector& srcFiles = target->GetSourceFiles(); + + for(std::vector::const_iterator fileIt = srcFiles.begin(); + fileIt != srcFiles.end(); + ++fileIt) + { + cmSourceFile* sf = *fileIt; + std::string absFile = cmsys::SystemTools::GetRealPath( + sf->GetFullPath().c_str()); + bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC")); + bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")); + + if ((skip==false) && (generated == false)) + { + std::string ext = sf->GetExtension(); + cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat( + ext.c_str()); + if (fileType == cmSystemTools::CXX_FILE_FORMAT) + { + _moc_files += sepFiles; + _moc_files += absFile; + sepFiles = ";"; + } + else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) + { + _moc_headers += sepHeaders; + _moc_headers += absFile; + sepHeaders = ";"; + } + } + } + + const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS"); + std::string _moc_options = (tmp!=0 ? tmp : ""); + + // forget the variables added here afterwards again: + cmMakefile::ScopePushPop varScope(makefile); + static_cast(varScope); + + makefile->AddDefinition("_moc_target_name", + cmLocalGenerator::EscapeForCMake(automocTargetName.c_str()).c_str()); + makefile->AddDefinition("_moc_options", + cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); + makefile->AddDefinition("_moc_files", + cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str()); + makefile->AddDefinition("_moc_headers", + cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); + makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE"); + + std::string _moc_incs; + std::string _moc_compile_defs; + std::vector configs; + const char *config = makefile->GetConfigurations(configs); + GetCompileDefinitionsAndDirectories(target, config, + _moc_incs, _moc_compile_defs); + + makefile->AddDefinition("_moc_incs", + cmLocalGenerator::EscapeForCMake(_moc_incs.c_str()).c_str()); + makefile->AddDefinition("_moc_compile_defs", + cmLocalGenerator::EscapeForCMake(_moc_compile_defs.c_str()).c_str()); + + std::map configIncludes; + std::map configDefines; + + for (std::vector::const_iterator li = configs.begin(); + li != configs.end(); ++li) + { + std::string config_moc_incs; + std::string config_moc_compile_defs; + GetCompileDefinitionsAndDirectories(target, li->c_str(), + config_moc_incs, + config_moc_compile_defs); + if (config_moc_incs != _moc_incs) + { + configIncludes["_moc_incs_" + *li] = + cmLocalGenerator::EscapeForCMake(config_moc_incs.c_str()); + if(_moc_incs.empty()) + { + _moc_incs = config_moc_incs; + } + } + if (config_moc_compile_defs != _moc_compile_defs) + { + configDefines["_moc_compile_defs_" + *li] = + cmLocalGenerator::EscapeForCMake(config_moc_compile_defs.c_str()); + if(_moc_compile_defs.empty()) + { + _moc_compile_defs = config_moc_compile_defs; + } + } + } + + const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); + if (!qtVersion) + { + qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); + } + if (const char *targetQtVersion = + target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) + { + qtVersion = targetQtVersion; + } + if (qtVersion) + { + makefile->AddDefinition("_target_qt_version", qtVersion); + } + + { + const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); + makefile->AddDefinition("_qt_moc_executable", qtMoc); + } + + if (strcmp(qtVersion, "5") == 0) + { + cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc"); + if (!qt5Moc) + { + cmSystemTools::Error("Qt5::moc target not found ", + automocTargetName.c_str()); + return; + } + makefile->AddDefinition("_qt_moc_executable", qt5Moc->GetLocation(0)); + } + else + { + if (strcmp(qtVersion, "4") != 0) + { + cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and " + "Qt 5 ", automocTargetName.c_str()); + } + } + + const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); + std::string inputFile = cmakeRoot; + inputFile += "/Modules/AutomocInfo.cmake.in"; + std::string outputFile = targetDir; + outputFile += "/AutomocInfo.cmake"; + makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), + false, true, false); + + if (!configDefines.empty() || !configIncludes.empty()) + { + std::ofstream infoFile(outputFile.c_str(), std::ios::app); + if ( !infoFile ) + { + std::string error = "Internal CMake error when trying to open file: "; + error += outputFile.c_str(); + error += " for writing."; + cmSystemTools::Error(error.c_str()); + return; + } + if (!configDefines.empty()) + { + for (std::map::iterator + it = configDefines.begin(), end = configDefines.end(); + it != end; ++it) + { + infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << + " " << it->second << ")\n"; + } + } + if (!configIncludes.empty()) + { + for (std::map::iterator + it = configIncludes.begin(), end = configIncludes.end(); + it != end; ++it) + { + infoFile << "set(AM_MOC_INCLUDES_" << it->first << + " " << it->second << ")\n"; + } + } + } +} + + +bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) +{ + bool success = true; + cmake cm; + cmGlobalGenerator* gg = this->CreateGlobalGenerator(&cm, targetDirectory); + cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile(); + + this->ReadAutomocInfoFile(makefile, targetDirectory, config); + this->ReadOldMocDefinitionsFile(makefile, targetDirectory); + + this->Init(); + + if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5") + { + success = this->RunAutomoc(makefile); + } + + this->WriteOldMocDefinitionsFile(targetDirectory); + + delete gg; + gg = NULL; + makefile = NULL; + return success; +} + + +cmGlobalGenerator* cmQtAutoGenerators::CreateGlobalGenerator(cmake* cm, + const char* targetDirectory) +{ + cmGlobalGenerator* gg = new cmGlobalGenerator(); + gg->SetCMakeInstance(cm); + + cmLocalGenerator* lg = gg->CreateLocalGenerator(); + lg->GetMakefile()->SetHomeOutputDirectory(targetDirectory); + lg->GetMakefile()->SetStartOutputDirectory(targetDirectory); + lg->GetMakefile()->SetHomeDirectory(targetDirectory); + lg->GetMakefile()->SetStartDirectory(targetDirectory); + gg->SetCurrentLocalGenerator(lg); + + return gg; +} + + +bool cmQtAutoGenerators::ReadAutomocInfoFile(cmMakefile* makefile, + const char* targetDirectory, + const char *config) +{ + std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); + cmSystemTools::ConvertToUnixSlashes(filename); + filename += "/AutomocInfo.cmake"; + + if (!makefile->ReadListFile(0, filename.c_str())) + { + cmSystemTools::Error("Error processing file: ", filename.c_str()); + return false; + } + + this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR"); + if (this->QtMajorVersion == "") + { + this->QtMajorVersion = makefile->GetSafeDefinition( + "AM_Qt5Core_VERSION_MAJOR"); + } + this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); + this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); + this->IncludeProjectDirsBefore = makefile->IsOn( + "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); + this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); + this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); + this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); + std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS"; + std::string compileDefsProp = compileDefsPropOrig; + if(config) + { + compileDefsProp += "_"; + compileDefsProp += config; + } + const char *compileDefs = makefile->GetDefinition(compileDefsProp.c_str()); + this->MocCompileDefinitionsStr = compileDefs ? compileDefs + : makefile->GetSafeDefinition(compileDefsPropOrig.c_str()); + std::string includesPropOrig = "AM_MOC_INCLUDES"; + std::string includesProp = includesPropOrig; + if(config) + { + includesProp += "_"; + includesProp += config; + } + const char *includes = makefile->GetDefinition(includesProp.c_str()); + this->MocIncludesStr = includes ? includes + : makefile->GetSafeDefinition(includesPropOrig.c_str()); + this->MocOptionsStr = makefile->GetSafeDefinition("AM_MOC_OPTIONS"); + this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); + this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); + this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); + + this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); + + this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE"); + + return true; +} + + +std::string cmQtAutoGenerators::MakeCompileSettingsString(cmMakefile* makefile) +{ + std::string s; + s += makefile->GetSafeDefinition("AM_MOC_COMPILE_DEFINITIONS"); + s += " ~~~ "; + s += makefile->GetSafeDefinition("AM_MOC_INCLUDES"); + s += " ~~~ "; + s += makefile->GetSafeDefinition("AM_MOC_OPTIONS"); + s += " ~~~ "; + s += makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE") ? "TRUE" + : "FALSE"; + s += " ~~~ "; + + return s; +} + + +bool cmQtAutoGenerators::ReadOldMocDefinitionsFile(cmMakefile* makefile, + const char* targetDirectory) +{ + std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); + cmSystemTools::ConvertToUnixSlashes(filename); + filename += "/AutomocOldMocDefinitions.cmake"; + + if (makefile->ReadListFile(0, filename.c_str())) + { + this->OldCompileSettingsStr = + makefile->GetSafeDefinition("AM_OLD_COMPILE_SETTINGS"); + } + return true; +} + + +void +cmQtAutoGenerators::WriteOldMocDefinitionsFile(const char* targetDirectory) +{ + std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); + cmSystemTools::ConvertToUnixSlashes(filename); + filename += "/AutomocOldMocDefinitions.cmake"; + + std::fstream outfile; + outfile.open(filename.c_str(), + std::ios::out | std::ios::trunc); + outfile << "set(AM_OLD_COMPILE_SETTINGS " + << cmLocalGenerator::EscapeForCMake( + this->CurrentCompileSettingsStr.c_str()) << ")\n"; + + outfile.close(); +} + + +void cmQtAutoGenerators::Init() +{ + this->OutMocCppFilename = this->Builddir; + this->OutMocCppFilename += this->TargetName; + this->OutMocCppFilename += ".cpp"; + + std::vector cdefList; + cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); + for(std::vector::const_iterator it = cdefList.begin(); + it != cdefList.end(); + ++it) + { + this->MocDefinitions.push_back("-D" + (*it)); + } + + cmSystemTools::ExpandListArgument(this->MocOptionsStr, this->MocOptions); + + std::vector incPaths; + cmSystemTools::ExpandListArgument(this->MocIncludesStr, incPaths); + + std::set frameworkPaths; + for(std::vector::const_iterator it = incPaths.begin(); + it != incPaths.end(); + ++it) + { + const std::string &path = *it; + this->MocIncludes.push_back("-I" + path); + if (this->EndsWith(path, ".framework/Headers")) + { + // Go up twice to get to the framework root + std::vector pathComponents; + cmsys::SystemTools::SplitPath(path.c_str(), pathComponents); + std::string frameworkPath =cmsys::SystemTools::JoinPath( + pathComponents.begin(), pathComponents.end() - 2); + frameworkPaths.insert(frameworkPath); + } + } + + for (std::set::const_iterator it = frameworkPaths.begin(); + it != frameworkPaths.end(); ++it) + { + this->MocIncludes.push_back("-F"); + this->MocIncludes.push_back(*it); + } + + + if (this->IncludeProjectDirsBefore) + { + const std::string &binDir = "-I" + this->ProjectBinaryDir; + + const std::string srcDir = "-I" + this->ProjectSourceDir; + + std::list sortedMocIncludes; + std::list::iterator it = this->MocIncludes.begin(); + while (it != this->MocIncludes.end()) + { + if (this->StartsWith(*it, binDir)) + { + sortedMocIncludes.push_back(*it); + it = this->MocIncludes.erase(it); + } + else + { + ++it; + } + } + it = this->MocIncludes.begin(); + while (it != this->MocIncludes.end()) + { + if (this->StartsWith(*it, srcDir)) + { + sortedMocIncludes.push_back(*it); + it = this->MocIncludes.erase(it); + } + else + { + ++it; + } + } + sortedMocIncludes.insert(sortedMocIncludes.end(), + this->MocIncludes.begin(), this->MocIncludes.end()); + this->MocIncludes = sortedMocIncludes; + } + +} + + +bool cmQtAutoGenerators::RunAutomoc(cmMakefile* makefile) +{ + if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str()) + || (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr)) + { + this->GenerateAll = true; + } + + // the program goes through all .cpp files to see which moc files are + // included. It is not really interesting how the moc file is named, but + // what file the moc is created from. Once a moc is included the same moc + // may not be included in the _automoc.cpp file anymore. OTOH if there's a + // header containing Q_OBJECT where no corresponding moc file is included + // anywhere a moc_.cpp file is created and included in + // the _automoc.cpp file. + + // key = moc source filepath, value = moc output filepath + std::map includedMocs; + // collect all headers which may need to be mocced + std::set headerFiles; + + std::vector sourceFiles; + cmSystemTools::ExpandListArgument(this->Sources, sourceFiles); + + const std::vector& headerExtensions = + makefile->GetHeaderExtensions(); + + for (std::vector::const_iterator it = sourceFiles.begin(); + it != sourceFiles.end(); + ++it) + { + const std::string &absFilename = *it; + if (this->Verbose) + { + std::cout << "AUTOMOC: Checking " << absFilename << std::endl; + } + if (this->RelaxedMode) + { + this->ParseCppFile(absFilename, headerExtensions, includedMocs); + } + else + { + this->StrictParseCppFile(absFilename, headerExtensions, includedMocs); + } + this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles); + } + + std::vector headerFilesVec; + cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec); + for (std::vector::const_iterator it = headerFilesVec.begin(); + it != headerFilesVec.end(); + ++it) + { + headerFiles.insert(*it); + } + + // key = moc source filepath, value = moc output filename + std::map notIncludedMocs; + this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs); + + // run moc on all the moc's that are #included in source files + for(std::map::const_iterator + it = includedMocs.begin(); + it != includedMocs.end(); + ++it) + { + this->GenerateMoc(it->first, it->second); + } + + cmsys_ios::stringstream outStream; + outStream << "/* This file is autogenerated, do not edit*/\n"; + + bool automocCppChanged = false; + if (notIncludedMocs.empty()) + { + outStream << "enum some_compilers { need_more_than_nothing };\n"; + } + else + { + // run moc on the remaining headers and include them in + // the _automoc.cpp file + for(std::map::const_iterator + it = notIncludedMocs.begin(); + it != notIncludedMocs.end(); + ++it) + { + bool mocSuccess = this->GenerateMoc(it->first, it->second); + if (mocSuccess) + { + automocCppChanged = true; + } + outStream << "#include \"" << it->second << "\"\n"; + } + } + + if (this->RunMocFailed) + { + std::cerr << "moc failed..."<< std::endl; + return false; + } + outStream.flush(); + std::string automocSource = outStream.str(); + if (!automocCppChanged) + { + // compare contents of the _automoc.cpp file + const std::string oldContents = this->ReadAll(this->OutMocCppFilename); + if (oldContents == automocSource) + { + // nothing changed: don't touch the _automoc.cpp file + return true; + } + } + + // source file that includes all remaining moc files (_automoc.cpp file) + std::fstream outfile; + outfile.open(this->OutMocCppFilename.c_str(), + std::ios::out | std::ios::trunc); + outfile << automocSource; + outfile.close(); + + return true; +} + + +void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::map& includedMocs) +{ + cmsys::RegularExpression mocIncludeRegExp( + "[\n][ \t]*#[ \t]*include[ \t]+" + "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); + + const std::string contentsString = this->ReadAll(absFilename); + if (contentsString.empty()) + { + std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" + << std::endl; + return; + } + const std::string absPath = cmsys::SystemTools::GetFilenamePath( + cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; + const std::string scannedFileBasename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(absFilename); + std::string macroName; + const bool requiresMoc = requiresMocing(contentsString, macroName); + bool dotMocIncluded = false; + bool mocUnderscoreIncluded = false; + std::string ownMocUnderscoreFile; + std::string ownDotMocFile; + std::string ownMocHeaderFile; + + std::string::size_type matchOffset = 0; + // first a simple string check for "moc" is *much* faster than the regexp, + // and if the string search already fails, we don't have to try the + // expensive regexp + if ((strstr(contentsString.c_str(), "moc") != NULL) + && (mocIncludeRegExp.find(contentsString))) + { + // for every moc include in the file + do + { + const std::string currentMoc = mocIncludeRegExp.match(1); + //std::cout << "found moc include: " << currentMoc << std::endl; + + std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(currentMoc); + const bool moc_style = this->StartsWith(basename, "moc_"); + + // If the moc include is of the moc_foo.cpp style we expect + // the Q_OBJECT class declaration in a header file. + // If the moc include is of the foo.moc style we need to look for + // a Q_OBJECT macro in the current source file, if it contains the + // macro we generate the moc file from the source file. + // Q_OBJECT + if (moc_style) + { + // basename should be the part of the moc filename used for + // finding the correct header, so we need to remove the moc_ part + basename = basename.substr(4); + std::string mocSubDir = extractSubDir(absPath, currentMoc); + std::string headerToMoc = findMatchingHeader( + absPath, mocSubDir, basename, headerExtensions); + + if (!headerToMoc.empty()) + { + includedMocs[headerToMoc] = currentMoc; + if (basename == scannedFileBasename) + { + mocUnderscoreIncluded = true; + ownMocUnderscoreFile = currentMoc; + ownMocHeaderFile = headerToMoc; + } + } + else + { + std::cerr << "AUTOMOC: error: " << absFilename << " The file " + << "includes the moc file \"" << currentMoc << "\", " + << "but could not find header \"" << basename + << '{' << this->Join(headerExtensions, ',') << "}\" "; + if (mocSubDir.empty()) + { + std::cerr << "in " << absPath << "\n" << std::endl; + } + else + { + std::cerr << "neither in " << absPath + << " nor in " << mocSubDir << "\n" << std::endl; + } + + ::exit(EXIT_FAILURE); + } + } + else + { + std::string fileToMoc = absFilename; + if ((basename != scannedFileBasename) || (requiresMoc==false)) + { + std::string mocSubDir = extractSubDir(absPath, currentMoc); + std::string headerToMoc = findMatchingHeader( + absPath, mocSubDir, basename, headerExtensions); + if (!headerToMoc.empty()) + { + // this is for KDE4 compatibility: + fileToMoc = headerToMoc; + if ((requiresMoc==false) &&(basename==scannedFileBasename)) + { + std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + "includes the moc file \"" << currentMoc << + "\", but does not contain a " << macroName + << " macro. Running moc on " + << "\"" << headerToMoc << "\" ! Include \"moc_" + << basename << ".cpp\" for a compatiblity with " + "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" + << std::endl; + } + else + { + std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + "includes the moc file \"" << currentMoc << + "\" instead of \"moc_" << basename << ".cpp\". " + "Running moc on " + << "\"" << headerToMoc << "\" ! Include \"moc_" + << basename << ".cpp\" for compatiblity with " + "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" + << std::endl; + } + } + else + { + std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " + "includes the moc file \"" << currentMoc << + "\", which seems to be the moc file from a different " + "source file. CMake also could not find a matching " + "header.\n" << std::endl; + ::exit(EXIT_FAILURE); + } + } + else + { + dotMocIncluded = true; + ownDotMocFile = currentMoc; + } + includedMocs[fileToMoc] = currentMoc; + } + matchOffset += mocIncludeRegExp.end(); + } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); + } + + // In this case, check whether the scanned file itself contains a Q_OBJECT. + // If this is the case, the moc_foo.cpp should probably be generated from + // foo.cpp instead of foo.h, because otherwise it won't build. + // But warn, since this is not how it is supposed to be used. + if ((dotMocIncluded == false) && (requiresMoc == true)) + { + if (mocUnderscoreIncluded == true) + { + // this is for KDE4 compatibility: + std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + << "contains a " << macroName << " macro, but does not " + "include " + << "\"" << scannedFileBasename << ".moc\", but instead " + "includes " + << "\"" << ownMocUnderscoreFile << "\". Running moc on " + << "\"" << absFilename << "\" ! Better include \"" + << scannedFileBasename << ".moc\" for compatiblity with " + "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" + << std::endl; + includedMocs[absFilename] = ownMocUnderscoreFile; + includedMocs.erase(ownMocHeaderFile); + } + else + { + // otherwise always error out since it will not compile: + std::cerr << "AUTOMOC: error: " << absFilename << ": The file " + << "contains a " << macroName << " macro, but does not " + "include " + << "\"" << scannedFileBasename << ".moc\" !\n" + << std::endl; + ::exit(EXIT_FAILURE); + } + } + +} + + +void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::map& includedMocs) +{ + cmsys::RegularExpression mocIncludeRegExp( + "[\n][ \t]*#[ \t]*include[ \t]+" + "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); + + const std::string contentsString = this->ReadAll(absFilename); + if (contentsString.empty()) + { + std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" + << std::endl; + return; + } + const std::string absPath = cmsys::SystemTools::GetFilenamePath( + cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; + const std::string scannedFileBasename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(absFilename); + + bool dotMocIncluded = false; + + std::string::size_type matchOffset = 0; + // first a simple string check for "moc" is *much* faster than the regexp, + // and if the string search already fails, we don't have to try the + // expensive regexp + if ((strstr(contentsString.c_str(), "moc") != NULL) + && (mocIncludeRegExp.find(contentsString))) + { + // for every moc include in the file + do + { + const std::string currentMoc = mocIncludeRegExp.match(1); + + std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(currentMoc); + const bool mocUnderscoreStyle = this->StartsWith(basename, "moc_"); + + // If the moc include is of the moc_foo.cpp style we expect + // the Q_OBJECT class declaration in a header file. + // If the moc include is of the foo.moc style we need to look for + // a Q_OBJECT macro in the current source file, if it contains the + // macro we generate the moc file from the source file. + if (mocUnderscoreStyle) + { + // basename should be the part of the moc filename used for + // finding the correct header, so we need to remove the moc_ part + basename = basename.substr(4); + std::string mocSubDir = extractSubDir(absPath, currentMoc); + std::string headerToMoc = findMatchingHeader( + absPath, mocSubDir, basename, headerExtensions); + + if (!headerToMoc.empty()) + { + includedMocs[headerToMoc] = currentMoc; + } + else + { + std::cerr << "AUTOMOC: error: " << absFilename << " The file " + << "includes the moc file \"" << currentMoc << "\", " + << "but could not find header \"" << basename + << '{' << this->Join(headerExtensions, ',') << "}\" "; + if (mocSubDir.empty()) + { + std::cerr << "in " << absPath << "\n" << std::endl; + } + else + { + std::cerr << "neither in " << absPath + << " nor in " << mocSubDir << "\n" << std::endl; + } + + ::exit(EXIT_FAILURE); + } + } + else + { + if (basename != scannedFileBasename) + { + std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " + "includes the moc file \"" << currentMoc << + "\", which seems to be the moc file from a different " + "source file. This is not supported. " + "Include \"" << scannedFileBasename << ".moc\" to run " + "moc on this source file.\n" << std::endl; + ::exit(EXIT_FAILURE); + } + dotMocIncluded = true; + includedMocs[absFilename] = currentMoc; + } + matchOffset += mocIncludeRegExp.end(); + } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); + } + + // In this case, check whether the scanned file itself contains a Q_OBJECT. + // If this is the case, the moc_foo.cpp should probably be generated from + // foo.cpp instead of foo.h, because otherwise it won't build. + // But warn, since this is not how it is supposed to be used. + std::string macroName; + if ((dotMocIncluded == false) && (requiresMocing(contentsString, + macroName))) + { + // otherwise always error out since it will not compile: + std::cerr << "AUTOMOC: error: " << absFilename << ": The file " + << "contains a " << macroName << " macro, but does not include " + << "\"" << scannedFileBasename << ".moc\" !\n" + << std::endl; + ::exit(EXIT_FAILURE); + } + +} + + +void +cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::set& absHeaders) +{ + // search for header files and private header files we may need to moc: + const std::string basename = + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); + const std::string absPath = cmsys::SystemTools::GetFilenamePath( + cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; + + for(std::vector::const_iterator ext = headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string headerName = absPath + basename + "." + (*ext); + if (cmsys::SystemTools::FileExists(headerName.c_str())) + { + absHeaders.insert(headerName); + break; + } + } + for(std::vector::const_iterator ext = headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string privateHeaderName = absPath+basename+"_p."+(*ext); + if (cmsys::SystemTools::FileExists(privateHeaderName.c_str())) + { + absHeaders.insert(privateHeaderName); + break; + } + } + +} + + +void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, + const std::map& includedMocs, + std::map& notIncludedMocs) +{ + for(std::set::const_iterator hIt=absHeaders.begin(); + hIt!=absHeaders.end(); + ++hIt) + { + const std::string& headerName = *hIt; + + if (includedMocs.find(headerName) == includedMocs.end()) + { + if (this->Verbose) + { + std::cout << "AUTOMOC: Checking " << headerName << std::endl; + } + + const std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(headerName); + + const std::string currentMoc = "moc_" + basename + ".cpp"; + const std::string contents = this->ReadAll(headerName); + std::string macroName; + if (requiresMocing(contents, macroName)) + { + //std::cout << "header contains Q_OBJECT macro"; + notIncludedMocs[headerName] = currentMoc; + } + } + } + +} + + +bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, + const std::string& mocFileName) +{ + const std::string mocFilePath = this->Builddir + mocFileName; + int sourceNewerThanMoc = 0; + bool success = cmsys::SystemTools::FileTimeCompare(sourceFile.c_str(), + mocFilePath.c_str(), + &sourceNewerThanMoc); + if (this->GenerateAll || !success || sourceNewerThanMoc >= 0) + { + // make sure the directory for the resulting moc file exists + std::string mocDir = mocFilePath.substr(0, mocFilePath.rfind('/')); + if (!cmsys::SystemTools::FileExists(mocDir.c_str(), false)) + { + cmsys::SystemTools::MakeDirectory(mocDir.c_str()); + } + + std::string msg = "Generating "; + msg += mocFileName; + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue + |cmsysTerminal_Color_ForegroundBold, + msg.c_str(), true, this->ColorOutput); + + std::vector command; + command.push_back(this->MocExecutable); + for (std::list::const_iterator it = this->MocIncludes.begin(); + it != this->MocIncludes.end(); + ++it) + { + command.push_back(*it); + } + for(std::list::const_iterator it=this->MocDefinitions.begin(); + it != this->MocDefinitions.end(); + ++it) + { + command.push_back(*it); + } + for(std::vector::const_iterator it=this->MocOptions.begin(); + it != this->MocOptions.end(); + ++it) + { + command.push_back(*it); + } +#ifdef _WIN32 + command.push_back("-DWIN32"); +#endif + command.push_back("-o"); + command.push_back(mocFilePath); + command.push_back(sourceFile); + + if (this->Verbose) + { + for(std::vector::const_iterator cmdIt = command.begin(); + cmdIt != command.end(); + ++cmdIt) + { + std::cout << *cmdIt << " "; + } + std::cout << std::endl; + } + + std::string output; + int retVal = 0; + bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal); + if (!result || retVal) + { + std::cerr << "AUTOMOC: error: process for " << mocFilePath <<" failed:\n" + << output << std::endl; + this->RunMocFailed = true; + cmSystemTools::RemoveFile(mocFilePath.c_str()); + } + return true; + } + return false; +} + + +std::string cmQtAutoGenerators::Join(const std::vector& lst, + char separator) +{ + if (lst.empty()) + { + return ""; + } + + std::string result; + for (std::vector::const_iterator it = lst.begin(); + it != lst.end(); + ++it) + { + result += "." + (*it) + separator; + } + result.erase(result.end() - 1); + return result; +} + + +bool cmQtAutoGenerators::StartsWith(const std::string& str, + const std::string& with) +{ + return (str.substr(0, with.length()) == with); +} + + +bool cmQtAutoGenerators::EndsWith(const std::string& str, + const std::string& with) +{ + if (with.length() > (str.length())) + { + return false; + } + return (str.substr(str.length() - with.length(), with.length()) == with); +} + + +std::string cmQtAutoGenerators::ReadAll(const std::string& filename) +{ + std::ifstream file(filename.c_str()); + cmsys_ios::stringstream stream; + stream << file.rdbuf(); + file.close(); + return stream.str(); +} diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h new file mode 100644 index 0000000..ef38a5b --- /dev/null +++ b/Source/cmQtAutoGenerators.h @@ -0,0 +1,96 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef cmQtAutoGenerators_h +#define cmQtAutoGenerators_h + +class cmGlobalGenerator; +class cmMakefile; + +class cmQtAutoGenerators +{ +public: + cmQtAutoGenerators(); + bool Run(const char* targetDirectory, const char *config); + + bool InitializeMocSourceFile(cmTarget* target); + void SetupAutoGenerateTarget(cmTarget* target); + +private: + cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, + const char* targetDirectory); + + bool ReadAutomocInfoFile(cmMakefile* makefile, + const char* targetDirectory, + const char *config); + bool ReadOldMocDefinitionsFile(cmMakefile* makefile, + const char* targetDirectory); + void WriteOldMocDefinitionsFile(const char* targetDirectory); + + std::string MakeCompileSettingsString(cmMakefile* makefile); + + bool RunAutomoc(cmMakefile* makefile); + bool GenerateMoc(const std::string& sourceFile, + const std::string& mocFileName); + void ParseCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::map& includedMocs); + void StrictParseCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::map& includedMocs); + void SearchHeadersForCppFile(const std::string& absFilename, + const std::vector& headerExtensions, + std::set& absHeaders); + + void ParseHeaders(const std::set& absHeaders, + const std::map& includedMocs, + std::map& notIncludedMocs); + + void Init(); + + std::string Join(const std::vector& lst, char separator); + bool EndsWith(const std::string& str, const std::string& with); + bool StartsWith(const std::string& str, const std::string& with); + std::string ReadAll(const std::string& filename); + + std::string QtMajorVersion; + std::string Sources; + std::string Headers; + bool IncludeProjectDirsBefore; + std::string Srcdir; + std::string Builddir; + std::string MocExecutable; + std::string MocCompileDefinitionsStr; + std::string MocIncludesStr; + std::string MocOptionsStr; + std::string ProjectBinaryDir; + std::string ProjectSourceDir; + std::string TargetName; + + std::string CurrentCompileSettingsStr; + std::string OldCompileSettingsStr; + + std::string OutMocCppFilename; + std::list MocIncludes; + std::list MocDefinitions; + std::vector MocOptions; + + bool Verbose; + bool ColorOutput; + bool RunMocFailed; + bool GenerateAll; + bool RelaxedMode; + +}; + +#endif diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx deleted file mode 100644 index 651e0ad..0000000 --- a/Source/cmQtAutomoc.cxx +++ /dev/null @@ -1,1317 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#include "cmGlobalGenerator.h" -#include "cmLocalGenerator.h" -#include "cmMakefile.h" -#include "cmSourceFile.h" -#include "cmSystemTools.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -# include "cmLocalVisualStudioGenerator.h" -#endif - -#include -#include - -#include -#if defined(__APPLE__) -#include -#endif - -#include "cmQtAutomoc.h" - - -static bool requiresMocing(const std::string& text, std::string ¯oName) -{ - // this simple check is much much faster than the regexp - if (strstr(text.c_str(), "Q_OBJECT") == NULL - && strstr(text.c_str(), "Q_GADGET") == NULL) - { - return false; - } - - cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); - if (qObjectRegExp.find(text)) - { - macroName = "Q_OBJECT"; - return true; - } - cmsys::RegularExpression qGadgetRegExp("[\n][ \t]*Q_GADGET[^a-zA-Z0-9_]"); - if (qGadgetRegExp.find(text)) - { - macroName = "Q_GADGET"; - return true; - } - return false; -} - - -static std::string findMatchingHeader(const std::string& absPath, - const std::string& mocSubDir, - const std::string& basename, - const std::vector& headerExtensions) -{ - std::string header; - for(std::vector::const_iterator ext = headerExtensions.begin(); - ext != headerExtensions.end(); - ++ext) - { - std::string sourceFilePath = absPath + basename + "." + (*ext); - if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) - { - header = sourceFilePath; - break; - } - if (!mocSubDir.empty()) - { - sourceFilePath = mocSubDir + basename + "." + (*ext); - if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) - { - header = sourceFilePath; - break; - } - } - } - - return header; -} - - -static std::string extractSubDir(const std::string& absPath, - const std::string& currentMoc) -{ - std::string subDir; - if (currentMoc.find_first_of('/') != std::string::npos) - { - subDir = absPath - + cmsys::SystemTools::GetFilenamePath(currentMoc) + '/'; - } - return subDir; -} - - -static void copyTargetProperty(cmTarget* destinationTarget, - cmTarget* sourceTarget, - const char* propertyName) -{ - const char* propertyValue = sourceTarget->GetProperty(propertyName); - if (propertyValue) - { - destinationTarget->SetProperty(propertyName, propertyValue); - } -} - - -cmQtAutomoc::cmQtAutomoc() -:Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0) -,ColorOutput(true) -,RunMocFailed(false) -,GenerateAll(false) -{ - - std::string colorEnv = ""; - cmsys::SystemTools::GetEnv("COLOR", colorEnv); - if(!colorEnv.empty()) - { - if(cmSystemTools::IsOn(colorEnv.c_str())) - { - this->ColorOutput = true; - } - else - { - this->ColorOutput = false; - } - } -} - -bool cmQtAutomoc::InitializeMocSourceFile(cmTarget* target) -{ - cmMakefile* makefile = target->GetMakefile(); - // don't do anything if there is no Qt4 or Qt5Core (which contains moc): - std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); - if (qtMajorVersion == "") - { - qtMajorVersion = makefile->GetSafeDefinition("Qt5Core_VERSION_MAJOR"); - } - if (qtMajorVersion != "4" && qtMajorVersion != "5") - { - return false; - } - - std::string automocTargetName = target->GetName(); - automocTargetName += "_automoc"; - std::string mocCppFile = makefile->GetCurrentOutputDirectory(); - mocCppFile += "/"; - mocCppFile += automocTargetName; - mocCppFile += ".cpp"; - cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(), - true); - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", - mocCppFile.c_str(), false); - - target->AddSourceFile(mocCppSource); - return true; -} - -static void GetCompileDefinitionsAndDirectories(cmTarget *target, - const char * config, - std::string &incs, - std::string &defs) -{ - cmMakefile* makefile = target->GetMakefile(); - cmLocalGenerator* localGen = makefile->GetLocalGenerator(); - std::vector includeDirs; - cmGeneratorTarget gtgt(target); - // Get the include dirs for this target, without stripping the implicit - // include dirs off, see http://public.kitware.com/Bug/view.php?id=13667 - localGen->GetIncludeDirectories(includeDirs, >gt, "CXX", config, false); - const char* sep = ""; - incs = ""; - for(std::vector::const_iterator incDirIt = includeDirs.begin(); - incDirIt != includeDirs.end(); - ++incDirIt) - { - incs += sep; - sep = ";"; - incs += *incDirIt; - } - - std::set defines; - localGen->AddCompileDefinitions(defines, target, config); - - sep = ""; - for(std::set::const_iterator defIt = defines.begin(); - defIt != defines.end(); - ++defIt) - { - defs += sep; - sep = ";"; - defs += *defIt; - } -} - -void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) -{ - cmMakefile* makefile = target->GetMakefile(); - const char* targetName = target->GetName(); - - bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE"); - - // create a custom target for running automoc at buildtime: - std::string automocTargetName = targetName; - automocTargetName += "_automoc"; - - std::string targetDir = makefile->GetCurrentOutputDirectory(); - targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); - targetDir += "/"; - targetDir += automocTargetName; - targetDir += ".dir/"; - - cmCustomCommandLine currentLine; - currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND")); - currentLine.push_back("-E"); - currentLine.push_back("cmake_automoc"); - currentLine.push_back(targetDir); - currentLine.push_back("$"); - - cmCustomCommandLines commandLines; - commandLines.push_back(currentLine); - - std::string workingDirectory = cmSystemTools::CollapseFullPath( - "", makefile->GetCurrentOutputDirectory()); - - std::vector depends; - std::string automocComment = "Automoc for target "; - automocComment += targetName; - -#if defined(_WIN32) && !defined(__CYGWIN__) - bool usePRE_BUILD = false; - cmLocalGenerator* localGen = makefile->GetLocalGenerator(); - cmGlobalGenerator* gg = localGen->GetGlobalGenerator(); - if(strstr(gg->GetName(), "Visual Studio")) - { - cmLocalVisualStudioGenerator* vslg = - static_cast(localGen); - // Under VS >= 7 use a PRE_BUILD event instead of a separate target to - // reduce the number of targets loaded into the IDE. - // This also works around a VS 11 bug that may skip updating the target: - // https://connect.microsoft.com/VisualStudio/feedback/details/769495 - usePRE_BUILD = vslg->GetVersion() >= cmLocalVisualStudioGenerator::VS7; - } - if(usePRE_BUILD) - { - // Add the pre-build command directly to bypass the OBJECT_LIBRARY - // rejection in cmMakefile::AddCustomCommandToTarget because we know - // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. - std::vector no_output; - cmCustomCommand cc(makefile, no_output, depends, - commandLines, automocComment.c_str(), - workingDirectory.c_str()); - cc.SetEscapeOldStyle(false); - cc.SetEscapeAllowMakeVars(true); - target->GetPreBuildCommands().push_back(cc); - } - else -#endif - { - cmTarget* automocTarget = makefile->AddUtilityCommand( - automocTargetName.c_str(), true, - workingDirectory.c_str(), depends, - commandLines, false, automocComment.c_str()); - // Set target folder - const char* automocFolder = makefile->GetCMakeInstance()->GetProperty( - "AUTOMOC_TARGETS_FOLDER"); - if (automocFolder && *automocFolder) - { - automocTarget->SetProperty("FOLDER", automocFolder); - } - else - { - // inherit FOLDER property from target (#13688) - copyTargetProperty(automocTarget, target, "FOLDER"); - } - - target->AddUtility(automocTargetName.c_str()); - } - - // configure a file to get all information to automoc at buildtime: - std::string _moc_files; - std::string _moc_headers; - const char* sepFiles = ""; - const char* sepHeaders = ""; - - const std::vector& srcFiles = target->GetSourceFiles(); - - for(std::vector::const_iterator fileIt = srcFiles.begin(); - fileIt != srcFiles.end(); - ++fileIt) - { - cmSourceFile* sf = *fileIt; - std::string absFile = cmsys::SystemTools::GetRealPath( - sf->GetFullPath().c_str()); - bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC")); - bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")); - - if ((skip==false) && (generated == false)) - { - std::string ext = sf->GetExtension(); - cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat( - ext.c_str()); - if (fileType == cmSystemTools::CXX_FILE_FORMAT) - { - _moc_files += sepFiles; - _moc_files += absFile; - sepFiles = ";"; - } - else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) - { - _moc_headers += sepHeaders; - _moc_headers += absFile; - sepHeaders = ";"; - } - } - } - - const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS"); - std::string _moc_options = (tmp!=0 ? tmp : ""); - - // forget the variables added here afterwards again: - cmMakefile::ScopePushPop varScope(makefile); - static_cast(varScope); - - makefile->AddDefinition("_moc_target_name", - cmLocalGenerator::EscapeForCMake(automocTargetName.c_str()).c_str()); - makefile->AddDefinition("_moc_options", - cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); - makefile->AddDefinition("_moc_files", - cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str()); - makefile->AddDefinition("_moc_headers", - cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); - makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE"); - - std::string _moc_incs; - std::string _moc_compile_defs; - std::vector configs; - const char *config = makefile->GetConfigurations(configs); - GetCompileDefinitionsAndDirectories(target, config, - _moc_incs, _moc_compile_defs); - - makefile->AddDefinition("_moc_incs", - cmLocalGenerator::EscapeForCMake(_moc_incs.c_str()).c_str()); - makefile->AddDefinition("_moc_compile_defs", - cmLocalGenerator::EscapeForCMake(_moc_compile_defs.c_str()).c_str()); - - std::map configIncludes; - std::map configDefines; - - for (std::vector::const_iterator li = configs.begin(); - li != configs.end(); ++li) - { - std::string config_moc_incs; - std::string config_moc_compile_defs; - GetCompileDefinitionsAndDirectories(target, li->c_str(), - config_moc_incs, - config_moc_compile_defs); - if (config_moc_incs != _moc_incs) - { - configIncludes["_moc_incs_" + *li] = - cmLocalGenerator::EscapeForCMake(config_moc_incs.c_str()); - if(_moc_incs.empty()) - { - _moc_incs = config_moc_incs; - } - } - if (config_moc_compile_defs != _moc_compile_defs) - { - configDefines["_moc_compile_defs_" + *li] = - cmLocalGenerator::EscapeForCMake(config_moc_compile_defs.c_str()); - if(_moc_compile_defs.empty()) - { - _moc_compile_defs = config_moc_compile_defs; - } - } - } - - const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); - if (!qtVersion) - { - qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); - } - if (const char *targetQtVersion = - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) - { - qtVersion = targetQtVersion; - } - if (qtVersion) - { - makefile->AddDefinition("_target_qt_version", qtVersion); - } - - { - const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); - makefile->AddDefinition("_qt_moc_executable", qtMoc); - } - - if (strcmp(qtVersion, "5") == 0) - { - cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc"); - if (!qt5Moc) - { - cmSystemTools::Error("Qt5::moc target not found ", - automocTargetName.c_str()); - return; - } - makefile->AddDefinition("_qt_moc_executable", qt5Moc->GetLocation(0)); - } - else - { - if (strcmp(qtVersion, "4") != 0) - { - cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and " - "Qt 5 ", automocTargetName.c_str()); - } - } - - const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); - std::string inputFile = cmakeRoot; - inputFile += "/Modules/AutomocInfo.cmake.in"; - std::string outputFile = targetDir; - outputFile += "/AutomocInfo.cmake"; - makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), - false, true, false); - - if (!configDefines.empty() || !configIncludes.empty()) - { - std::ofstream infoFile(outputFile.c_str(), std::ios::app); - if ( !infoFile ) - { - std::string error = "Internal CMake error when trying to open file: "; - error += outputFile.c_str(); - error += " for writing."; - cmSystemTools::Error(error.c_str()); - return; - } - if (!configDefines.empty()) - { - for (std::map::iterator - it = configDefines.begin(), end = configDefines.end(); - it != end; ++it) - { - infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << - " " << it->second << ")\n"; - } - } - if (!configIncludes.empty()) - { - for (std::map::iterator - it = configIncludes.begin(), end = configIncludes.end(); - it != end; ++it) - { - infoFile << "set(AM_MOC_INCLUDES_" << it->first << - " " << it->second << ")\n"; - } - } - } -} - - -bool cmQtAutomoc::Run(const char* targetDirectory, const char *config) -{ - bool success = true; - cmake cm; - cmGlobalGenerator* gg = this->CreateGlobalGenerator(&cm, targetDirectory); - cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile(); - - this->ReadAutomocInfoFile(makefile, targetDirectory, config); - this->ReadOldMocDefinitionsFile(makefile, targetDirectory); - - this->Init(); - - if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5") - { - success = this->RunAutomoc(makefile); - } - - this->WriteOldMocDefinitionsFile(targetDirectory); - - delete gg; - gg = NULL; - makefile = NULL; - return success; -} - - -cmGlobalGenerator* cmQtAutomoc::CreateGlobalGenerator(cmake* cm, - const char* targetDirectory) -{ - cmGlobalGenerator* gg = new cmGlobalGenerator(); - gg->SetCMakeInstance(cm); - - cmLocalGenerator* lg = gg->CreateLocalGenerator(); - lg->GetMakefile()->SetHomeOutputDirectory(targetDirectory); - lg->GetMakefile()->SetStartOutputDirectory(targetDirectory); - lg->GetMakefile()->SetHomeDirectory(targetDirectory); - lg->GetMakefile()->SetStartDirectory(targetDirectory); - gg->SetCurrentLocalGenerator(lg); - - return gg; -} - - -bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile, - const char* targetDirectory, - const char *config) -{ - std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); - cmSystemTools::ConvertToUnixSlashes(filename); - filename += "/AutomocInfo.cmake"; - - if (!makefile->ReadListFile(0, filename.c_str())) - { - cmSystemTools::Error("Error processing file: ", filename.c_str()); - return false; - } - - this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR"); - if (this->QtMajorVersion == "") - { - this->QtMajorVersion = makefile->GetSafeDefinition( - "AM_Qt5Core_VERSION_MAJOR"); - } - this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); - this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); - this->IncludeProjectDirsBefore = makefile->IsOn( - "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); - this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); - this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); - this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); - std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS"; - std::string compileDefsProp = compileDefsPropOrig; - if(config) - { - compileDefsProp += "_"; - compileDefsProp += config; - } - const char *compileDefs = makefile->GetDefinition(compileDefsProp.c_str()); - this->MocCompileDefinitionsStr = compileDefs ? compileDefs - : makefile->GetSafeDefinition(compileDefsPropOrig.c_str()); - std::string includesPropOrig = "AM_MOC_INCLUDES"; - std::string includesProp = includesPropOrig; - if(config) - { - includesProp += "_"; - includesProp += config; - } - const char *includes = makefile->GetDefinition(includesProp.c_str()); - this->MocIncludesStr = includes ? includes - : makefile->GetSafeDefinition(includesPropOrig.c_str()); - this->MocOptionsStr = makefile->GetSafeDefinition("AM_MOC_OPTIONS"); - this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); - this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); - this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); - - this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); - - this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE"); - - return true; -} - - -std::string cmQtAutomoc::MakeCompileSettingsString(cmMakefile* makefile) -{ - std::string s; - s += makefile->GetSafeDefinition("AM_MOC_COMPILE_DEFINITIONS"); - s += " ~~~ "; - s += makefile->GetSafeDefinition("AM_MOC_INCLUDES"); - s += " ~~~ "; - s += makefile->GetSafeDefinition("AM_MOC_OPTIONS"); - s += " ~~~ "; - s += makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE") ? "TRUE" - : "FALSE"; - s += " ~~~ "; - - return s; -} - - -bool cmQtAutomoc::ReadOldMocDefinitionsFile(cmMakefile* makefile, - const char* targetDirectory) -{ - std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); - cmSystemTools::ConvertToUnixSlashes(filename); - filename += "/AutomocOldMocDefinitions.cmake"; - - if (makefile->ReadListFile(0, filename.c_str())) - { - this->OldCompileSettingsStr = - makefile->GetSafeDefinition("AM_OLD_COMPILE_SETTINGS"); - } - return true; -} - - -void cmQtAutomoc::WriteOldMocDefinitionsFile(const char* targetDirectory) -{ - std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); - cmSystemTools::ConvertToUnixSlashes(filename); - filename += "/AutomocOldMocDefinitions.cmake"; - - std::fstream outfile; - outfile.open(filename.c_str(), - std::ios::out | std::ios::trunc); - outfile << "set(AM_OLD_COMPILE_SETTINGS " - << cmLocalGenerator::EscapeForCMake( - this->CurrentCompileSettingsStr.c_str()) << ")\n"; - - outfile.close(); -} - - -void cmQtAutomoc::Init() -{ - this->OutMocCppFilename = this->Builddir; - this->OutMocCppFilename += this->TargetName; - this->OutMocCppFilename += ".cpp"; - - std::vector cdefList; - cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); - for(std::vector::const_iterator it = cdefList.begin(); - it != cdefList.end(); - ++it) - { - this->MocDefinitions.push_back("-D" + (*it)); - } - - cmSystemTools::ExpandListArgument(this->MocOptionsStr, this->MocOptions); - - std::vector incPaths; - cmSystemTools::ExpandListArgument(this->MocIncludesStr, incPaths); - - std::set frameworkPaths; - for(std::vector::const_iterator it = incPaths.begin(); - it != incPaths.end(); - ++it) - { - const std::string &path = *it; - this->MocIncludes.push_back("-I" + path); - if (this->EndsWith(path, ".framework/Headers")) - { - // Go up twice to get to the framework root - std::vector pathComponents; - cmsys::SystemTools::SplitPath(path.c_str(), pathComponents); - std::string frameworkPath =cmsys::SystemTools::JoinPath( - pathComponents.begin(), pathComponents.end() - 2); - frameworkPaths.insert(frameworkPath); - } - } - - for (std::set::const_iterator it = frameworkPaths.begin(); - it != frameworkPaths.end(); ++it) - { - this->MocIncludes.push_back("-F"); - this->MocIncludes.push_back(*it); - } - - - if (this->IncludeProjectDirsBefore) - { - const std::string &binDir = "-I" + this->ProjectBinaryDir; - - const std::string srcDir = "-I" + this->ProjectSourceDir; - - std::list sortedMocIncludes; - std::list::iterator it = this->MocIncludes.begin(); - while (it != this->MocIncludes.end()) - { - if (this->StartsWith(*it, binDir)) - { - sortedMocIncludes.push_back(*it); - it = this->MocIncludes.erase(it); - } - else - { - ++it; - } - } - it = this->MocIncludes.begin(); - while (it != this->MocIncludes.end()) - { - if (this->StartsWith(*it, srcDir)) - { - sortedMocIncludes.push_back(*it); - it = this->MocIncludes.erase(it); - } - else - { - ++it; - } - } - sortedMocIncludes.insert(sortedMocIncludes.end(), - this->MocIncludes.begin(), this->MocIncludes.end()); - this->MocIncludes = sortedMocIncludes; - } - -} - - -bool cmQtAutomoc::RunAutomoc(cmMakefile* makefile) -{ - if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str()) - || (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr)) - { - this->GenerateAll = true; - } - - // the program goes through all .cpp files to see which moc files are - // included. It is not really interesting how the moc file is named, but - // what file the moc is created from. Once a moc is included the same moc - // may not be included in the _automoc.cpp file anymore. OTOH if there's a - // header containing Q_OBJECT where no corresponding moc file is included - // anywhere a moc_.cpp file is created and included in - // the _automoc.cpp file. - - // key = moc source filepath, value = moc output filepath - std::map includedMocs; - // collect all headers which may need to be mocced - std::set headerFiles; - - std::vector sourceFiles; - cmSystemTools::ExpandListArgument(this->Sources, sourceFiles); - - const std::vector& headerExtensions = - makefile->GetHeaderExtensions(); - - for (std::vector::const_iterator it = sourceFiles.begin(); - it != sourceFiles.end(); - ++it) - { - const std::string &absFilename = *it; - if (this->Verbose) - { - std::cout << "AUTOMOC: Checking " << absFilename << std::endl; - } - if (this->RelaxedMode) - { - this->ParseCppFile(absFilename, headerExtensions, includedMocs); - } - else - { - this->StrictParseCppFile(absFilename, headerExtensions, includedMocs); - } - this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles); - } - - std::vector headerFilesVec; - cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec); - for (std::vector::const_iterator it = headerFilesVec.begin(); - it != headerFilesVec.end(); - ++it) - { - headerFiles.insert(*it); - } - - // key = moc source filepath, value = moc output filename - std::map notIncludedMocs; - this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs); - - // run moc on all the moc's that are #included in source files - for(std::map::const_iterator - it = includedMocs.begin(); - it != includedMocs.end(); - ++it) - { - this->GenerateMoc(it->first, it->second); - } - - cmsys_ios::stringstream outStream; - outStream << "/* This file is autogenerated, do not edit*/\n"; - - bool automocCppChanged = false; - if (notIncludedMocs.empty()) - { - outStream << "enum some_compilers { need_more_than_nothing };\n"; - } - else - { - // run moc on the remaining headers and include them in - // the _automoc.cpp file - for(std::map::const_iterator - it = notIncludedMocs.begin(); - it != notIncludedMocs.end(); - ++it) - { - bool mocSuccess = this->GenerateMoc(it->first, it->second); - if (mocSuccess) - { - automocCppChanged = true; - } - outStream << "#include \"" << it->second << "\"\n"; - } - } - - if (this->RunMocFailed) - { - std::cerr << "moc failed..."<< std::endl; - return false; - } - outStream.flush(); - std::string automocSource = outStream.str(); - if (!automocCppChanged) - { - // compare contents of the _automoc.cpp file - const std::string oldContents = this->ReadAll(this->OutMocCppFilename); - if (oldContents == automocSource) - { - // nothing changed: don't touch the _automoc.cpp file - return true; - } - } - - // source file that includes all remaining moc files (_automoc.cpp file) - std::fstream outfile; - outfile.open(this->OutMocCppFilename.c_str(), - std::ios::out | std::ios::trunc); - outfile << automocSource; - outfile.close(); - - return true; -} - - -void cmQtAutomoc::ParseCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::map& includedMocs) -{ - cmsys::RegularExpression mocIncludeRegExp( - "[\n][ \t]*#[ \t]*include[ \t]+" - "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); - - const std::string contentsString = this->ReadAll(absFilename); - if (contentsString.empty()) - { - std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" - << std::endl; - return; - } - const std::string absPath = cmsys::SystemTools::GetFilenamePath( - cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; - const std::string scannedFileBasename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(absFilename); - std::string macroName; - const bool requiresMoc = requiresMocing(contentsString, macroName); - bool dotMocIncluded = false; - bool mocUnderscoreIncluded = false; - std::string ownMocUnderscoreFile; - std::string ownDotMocFile; - std::string ownMocHeaderFile; - - std::string::size_type matchOffset = 0; - // first a simple string check for "moc" is *much* faster than the regexp, - // and if the string search already fails, we don't have to try the - // expensive regexp - if ((strstr(contentsString.c_str(), "moc") != NULL) - && (mocIncludeRegExp.find(contentsString))) - { - // for every moc include in the file - do - { - const std::string currentMoc = mocIncludeRegExp.match(1); - //std::cout << "found moc include: " << currentMoc << std::endl; - - std::string basename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(currentMoc); - const bool moc_style = this->StartsWith(basename, "moc_"); - - // If the moc include is of the moc_foo.cpp style we expect - // the Q_OBJECT class declaration in a header file. - // If the moc include is of the foo.moc style we need to look for - // a Q_OBJECT macro in the current source file, if it contains the - // macro we generate the moc file from the source file. - // Q_OBJECT - if (moc_style) - { - // basename should be the part of the moc filename used for - // finding the correct header, so we need to remove the moc_ part - basename = basename.substr(4); - std::string mocSubDir = extractSubDir(absPath, currentMoc); - std::string headerToMoc = findMatchingHeader( - absPath, mocSubDir, basename, headerExtensions); - - if (!headerToMoc.empty()) - { - includedMocs[headerToMoc] = currentMoc; - if (basename == scannedFileBasename) - { - mocUnderscoreIncluded = true; - ownMocUnderscoreFile = currentMoc; - ownMocHeaderFile = headerToMoc; - } - } - else - { - std::cerr << "AUTOMOC: error: " << absFilename << " The file " - << "includes the moc file \"" << currentMoc << "\", " - << "but could not find header \"" << basename - << '{' << this->Join(headerExtensions, ',') << "}\" "; - if (mocSubDir.empty()) - { - std::cerr << "in " << absPath << "\n" << std::endl; - } - else - { - std::cerr << "neither in " << absPath - << " nor in " << mocSubDir << "\n" << std::endl; - } - - ::exit(EXIT_FAILURE); - } - } - else - { - std::string fileToMoc = absFilename; - if ((basename != scannedFileBasename) || (requiresMoc==false)) - { - std::string mocSubDir = extractSubDir(absPath, currentMoc); - std::string headerToMoc = findMatchingHeader( - absPath, mocSubDir, basename, headerExtensions); - if (!headerToMoc.empty()) - { - // this is for KDE4 compatibility: - fileToMoc = headerToMoc; - if ((requiresMoc==false) &&(basename==scannedFileBasename)) - { - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " - "includes the moc file \"" << currentMoc << - "\", but does not contain a " << macroName - << " macro. Running moc on " - << "\"" << headerToMoc << "\" ! Include \"moc_" - << basename << ".cpp\" for a compatiblity with " - "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" - << std::endl; - } - else - { - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " - "includes the moc file \"" << currentMoc << - "\" instead of \"moc_" << basename << ".cpp\". " - "Running moc on " - << "\"" << headerToMoc << "\" ! Include \"moc_" - << basename << ".cpp\" for compatiblity with " - "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" - << std::endl; - } - } - else - { - std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " - "includes the moc file \"" << currentMoc << - "\", which seems to be the moc file from a different " - "source file. CMake also could not find a matching " - "header.\n" << std::endl; - ::exit(EXIT_FAILURE); - } - } - else - { - dotMocIncluded = true; - ownDotMocFile = currentMoc; - } - includedMocs[fileToMoc] = currentMoc; - } - matchOffset += mocIncludeRegExp.end(); - } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); - } - - // In this case, check whether the scanned file itself contains a Q_OBJECT. - // If this is the case, the moc_foo.cpp should probably be generated from - // foo.cpp instead of foo.h, because otherwise it won't build. - // But warn, since this is not how it is supposed to be used. - if ((dotMocIncluded == false) && (requiresMoc == true)) - { - if (mocUnderscoreIncluded == true) - { - // this is for KDE4 compatibility: - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " - << "contains a " << macroName << " macro, but does not " - "include " - << "\"" << scannedFileBasename << ".moc\", but instead " - "includes " - << "\"" << ownMocUnderscoreFile << "\". Running moc on " - << "\"" << absFilename << "\" ! Better include \"" - << scannedFileBasename << ".moc\" for compatiblity with " - "strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n" - << std::endl; - includedMocs[absFilename] = ownMocUnderscoreFile; - includedMocs.erase(ownMocHeaderFile); - } - else - { - // otherwise always error out since it will not compile: - std::cerr << "AUTOMOC: error: " << absFilename << ": The file " - << "contains a " << macroName << " macro, but does not " - "include " - << "\"" << scannedFileBasename << ".moc\" !\n" - << std::endl; - ::exit(EXIT_FAILURE); - } - } - -} - - -void cmQtAutomoc::StrictParseCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::map& includedMocs) -{ - cmsys::RegularExpression mocIncludeRegExp( - "[\n][ \t]*#[ \t]*include[ \t]+" - "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); - - const std::string contentsString = this->ReadAll(absFilename); - if (contentsString.empty()) - { - std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" - << std::endl; - return; - } - const std::string absPath = cmsys::SystemTools::GetFilenamePath( - cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; - const std::string scannedFileBasename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(absFilename); - - bool dotMocIncluded = false; - - std::string::size_type matchOffset = 0; - // first a simple string check for "moc" is *much* faster than the regexp, - // and if the string search already fails, we don't have to try the - // expensive regexp - if ((strstr(contentsString.c_str(), "moc") != NULL) - && (mocIncludeRegExp.find(contentsString))) - { - // for every moc include in the file - do - { - const std::string currentMoc = mocIncludeRegExp.match(1); - - std::string basename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(currentMoc); - const bool mocUnderscoreStyle = this->StartsWith(basename, "moc_"); - - // If the moc include is of the moc_foo.cpp style we expect - // the Q_OBJECT class declaration in a header file. - // If the moc include is of the foo.moc style we need to look for - // a Q_OBJECT macro in the current source file, if it contains the - // macro we generate the moc file from the source file. - if (mocUnderscoreStyle) - { - // basename should be the part of the moc filename used for - // finding the correct header, so we need to remove the moc_ part - basename = basename.substr(4); - std::string mocSubDir = extractSubDir(absPath, currentMoc); - std::string headerToMoc = findMatchingHeader( - absPath, mocSubDir, basename, headerExtensions); - - if (!headerToMoc.empty()) - { - includedMocs[headerToMoc] = currentMoc; - } - else - { - std::cerr << "AUTOMOC: error: " << absFilename << " The file " - << "includes the moc file \"" << currentMoc << "\", " - << "but could not find header \"" << basename - << '{' << this->Join(headerExtensions, ',') << "}\" "; - if (mocSubDir.empty()) - { - std::cerr << "in " << absPath << "\n" << std::endl; - } - else - { - std::cerr << "neither in " << absPath - << " nor in " << mocSubDir << "\n" << std::endl; - } - - ::exit(EXIT_FAILURE); - } - } - else - { - if (basename != scannedFileBasename) - { - std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " - "includes the moc file \"" << currentMoc << - "\", which seems to be the moc file from a different " - "source file. This is not supported. " - "Include \"" << scannedFileBasename << ".moc\" to run " - "moc on this source file.\n" << std::endl; - ::exit(EXIT_FAILURE); - } - dotMocIncluded = true; - includedMocs[absFilename] = currentMoc; - } - matchOffset += mocIncludeRegExp.end(); - } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); - } - - // In this case, check whether the scanned file itself contains a Q_OBJECT. - // If this is the case, the moc_foo.cpp should probably be generated from - // foo.cpp instead of foo.h, because otherwise it won't build. - // But warn, since this is not how it is supposed to be used. - std::string macroName; - if ((dotMocIncluded == false) && (requiresMocing(contentsString, - macroName))) - { - // otherwise always error out since it will not compile: - std::cerr << "AUTOMOC: error: " << absFilename << ": The file " - << "contains a " << macroName << " macro, but does not include " - << "\"" << scannedFileBasename << ".moc\" !\n" - << std::endl; - ::exit(EXIT_FAILURE); - } - -} - - -void cmQtAutomoc::SearchHeadersForCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::set& absHeaders) -{ - // search for header files and private header files we may need to moc: - const std::string basename = - cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); - const std::string absPath = cmsys::SystemTools::GetFilenamePath( - cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; - - for(std::vector::const_iterator ext = headerExtensions.begin(); - ext != headerExtensions.end(); - ++ext) - { - const std::string headerName = absPath + basename + "." + (*ext); - if (cmsys::SystemTools::FileExists(headerName.c_str())) - { - absHeaders.insert(headerName); - break; - } - } - for(std::vector::const_iterator ext = headerExtensions.begin(); - ext != headerExtensions.end(); - ++ext) - { - const std::string privateHeaderName = absPath+basename+"_p."+(*ext); - if (cmsys::SystemTools::FileExists(privateHeaderName.c_str())) - { - absHeaders.insert(privateHeaderName); - break; - } - } - -} - - -void cmQtAutomoc::ParseHeaders(const std::set& absHeaders, - const std::map& includedMocs, - std::map& notIncludedMocs) -{ - for(std::set::const_iterator hIt=absHeaders.begin(); - hIt!=absHeaders.end(); - ++hIt) - { - const std::string& headerName = *hIt; - - if (includedMocs.find(headerName) == includedMocs.end()) - { - if (this->Verbose) - { - std::cout << "AUTOMOC: Checking " << headerName << std::endl; - } - - const std::string basename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(headerName); - - const std::string currentMoc = "moc_" + basename + ".cpp"; - const std::string contents = this->ReadAll(headerName); - std::string macroName; - if (requiresMocing(contents, macroName)) - { - //std::cout << "header contains Q_OBJECT macro"; - notIncludedMocs[headerName] = currentMoc; - } - } - } - -} - - -bool cmQtAutomoc::GenerateMoc(const std::string& sourceFile, - const std::string& mocFileName) -{ - const std::string mocFilePath = this->Builddir + mocFileName; - int sourceNewerThanMoc = 0; - bool success = cmsys::SystemTools::FileTimeCompare(sourceFile.c_str(), - mocFilePath.c_str(), - &sourceNewerThanMoc); - if (this->GenerateAll || !success || sourceNewerThanMoc >= 0) - { - // make sure the directory for the resulting moc file exists - std::string mocDir = mocFilePath.substr(0, mocFilePath.rfind('/')); - if (!cmsys::SystemTools::FileExists(mocDir.c_str(), false)) - { - cmsys::SystemTools::MakeDirectory(mocDir.c_str()); - } - - std::string msg = "Generating "; - msg += mocFileName; - cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue - |cmsysTerminal_Color_ForegroundBold, - msg.c_str(), true, this->ColorOutput); - - std::vector command; - command.push_back(this->MocExecutable); - for (std::list::const_iterator it = this->MocIncludes.begin(); - it != this->MocIncludes.end(); - ++it) - { - command.push_back(*it); - } - for(std::list::const_iterator it=this->MocDefinitions.begin(); - it != this->MocDefinitions.end(); - ++it) - { - command.push_back(*it); - } - for(std::vector::const_iterator it=this->MocOptions.begin(); - it != this->MocOptions.end(); - ++it) - { - command.push_back(*it); - } -#ifdef _WIN32 - command.push_back("-DWIN32"); -#endif - command.push_back("-o"); - command.push_back(mocFilePath); - command.push_back(sourceFile); - - if (this->Verbose) - { - for(std::vector::const_iterator cmdIt = command.begin(); - cmdIt != command.end(); - ++cmdIt) - { - std::cout << *cmdIt << " "; - } - std::cout << std::endl; - } - - std::string output; - int retVal = 0; - bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal); - if (!result || retVal) - { - std::cerr << "AUTOMOC: error: process for " << mocFilePath <<" failed:\n" - << output << std::endl; - this->RunMocFailed = true; - cmSystemTools::RemoveFile(mocFilePath.c_str()); - } - return true; - } - return false; -} - - -std::string cmQtAutomoc::Join(const std::vector& lst, - char separator) -{ - if (lst.empty()) - { - return ""; - } - - std::string result; - for (std::vector::const_iterator it = lst.begin(); - it != lst.end(); - ++it) - { - result += "." + (*it) + separator; - } - result.erase(result.end() - 1); - return result; -} - - -bool cmQtAutomoc::StartsWith(const std::string& str, const std::string& with) -{ - return (str.substr(0, with.length()) == with); -} - - -bool cmQtAutomoc::EndsWith(const std::string& str, const std::string& with) -{ - if (with.length() > (str.length())) - { - return false; - } - return (str.substr(str.length() - with.length(), with.length()) == with); -} - - -std::string cmQtAutomoc::ReadAll(const std::string& filename) -{ - std::ifstream file(filename.c_str()); - cmsys_ios::stringstream stream; - stream << file.rdbuf(); - file.close(); - return stream.str(); -} diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h deleted file mode 100644 index ebeeb0e..0000000 --- a/Source/cmQtAutomoc.h +++ /dev/null @@ -1,96 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef cmQtAutomoc_h -#define cmQtAutomoc_h - -class cmGlobalGenerator; -class cmMakefile; - -class cmQtAutomoc -{ -public: - cmQtAutomoc(); - bool Run(const char* targetDirectory, const char *config); - - bool InitializeMocSourceFile(cmTarget* target); - void SetupAutomocTarget(cmTarget* target); - -private: - cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, - const char* targetDirectory); - - bool ReadAutomocInfoFile(cmMakefile* makefile, - const char* targetDirectory, - const char *config); - bool ReadOldMocDefinitionsFile(cmMakefile* makefile, - const char* targetDirectory); - void WriteOldMocDefinitionsFile(const char* targetDirectory); - - std::string MakeCompileSettingsString(cmMakefile* makefile); - - bool RunAutomoc(cmMakefile* makefile); - bool GenerateMoc(const std::string& sourceFile, - const std::string& mocFileName); - void ParseCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::map& includedMocs); - void StrictParseCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::map& includedMocs); - void SearchHeadersForCppFile(const std::string& absFilename, - const std::vector& headerExtensions, - std::set& absHeaders); - - void ParseHeaders(const std::set& absHeaders, - const std::map& includedMocs, - std::map& notIncludedMocs); - - void Init(); - - std::string Join(const std::vector& lst, char separator); - bool EndsWith(const std::string& str, const std::string& with); - bool StartsWith(const std::string& str, const std::string& with); - std::string ReadAll(const std::string& filename); - - std::string QtMajorVersion; - std::string Sources; - std::string Headers; - bool IncludeProjectDirsBefore; - std::string Srcdir; - std::string Builddir; - std::string MocExecutable; - std::string MocCompileDefinitionsStr; - std::string MocIncludesStr; - std::string MocOptionsStr; - std::string ProjectBinaryDir; - std::string ProjectSourceDir; - std::string TargetName; - - std::string CurrentCompileSettingsStr; - std::string OldCompileSettingsStr; - - std::string OutMocCppFilename; - std::list MocIncludes; - std::list MocDefinitions; - std::vector MocOptions; - - bool Verbose; - bool ColorOutput; - bool RunMocFailed; - bool GenerateAll; - bool RelaxedMode; - -}; - -#endif diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 9814aea..2fba5dc 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -13,7 +13,7 @@ #include "cmMakefile.h" #include "cmLocalGenerator.h" #include "cmGlobalGenerator.h" -#include "cmQtAutomoc.h" +#include "cmQtAutoGenerators.h" #include "cmVersion.h" #if defined(CMAKE_BUILD_WITH_CMAKE) @@ -634,7 +634,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } else if (args[1] == "cmake_automoc") { - cmQtAutomoc automoc; + cmQtAutoGenerators automoc; const char *config = args[3].empty() ? 0 : args[3].c_str(); bool automocSuccess = automoc.Run(args[2].c_str(), config); return automocSuccess ? 0 : 1; -- cgit v0.12 From 52d5d4e9154644597630ed844a254dfb8de524dd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 2 Oct 2013 13:39:50 +0200 Subject: Rename the cmQtAutoGenerator instances to reflect coming features. --- Source/cmGlobalGenerator.cxx | 12 ++++++------ Source/cmcmd.cxx | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index f92fe60..386af6d 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1209,8 +1209,8 @@ bool cmGlobalGenerator::CheckTargets() void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() { #ifdef CMAKE_BUILD_WITH_CMAKE - typedef std::vector > Automocs; - Automocs automocs; + typedef std::vector > Autogens; + Autogens autogens; for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) { cmTargets& targets = @@ -1227,16 +1227,16 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() { if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported()) { - cmQtAutoGenerators automoc; - if(automoc.InitializeMocSourceFile(&target)) + cmQtAutoGenerators autogen; + if(autogen.InitializeMocSourceFile(&target)) { - automocs.push_back(std::make_pair(automoc, &target)); + autogens.push_back(std::make_pair(autogen, &target)); } } } } } - for (Automocs::iterator it = automocs.begin(); it != automocs.end(); + for (Autogens::iterator it = autogens.begin(); it != autogens.end(); ++it) { it->first.SetupAutoGenerateTarget(it->second); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 2fba5dc..79a3969 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -634,10 +634,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) } else if (args[1] == "cmake_automoc") { - cmQtAutoGenerators automoc; + cmQtAutoGenerators autogen; const char *config = args[3].empty() ? 0 : args[3].c_str(); - bool automocSuccess = automoc.Run(args[2].c_str(), config); - return automocSuccess ? 0 : 1; + bool autogenSuccess = autogen.Run(args[2].c_str(), config); + return autogenSuccess ? 0 : 1; } #endif -- cgit v0.12 From be23dcfeb1ef2d855bd24bb933ae7da4a6b4b9da Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 2 Oct 2013 13:40:49 +0200 Subject: Rename the cmake_automoc command to cmake_autogen. There is no need for a "cmake_automoc" backward compatibility command because it is internal, undocumented, and only executed from a matching version of cmake. --- Source/cmQtAutoGenerators.cxx | 2 +- Source/cmcmd.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 24f4498..ee30987 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -221,7 +221,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) cmCustomCommandLine currentLine; currentLine.push_back(makefile->GetSafeDefinition("CMAKE_COMMAND")); currentLine.push_back("-E"); - currentLine.push_back("cmake_automoc"); + currentLine.push_back("cmake_autogen"); currentLine.push_back(targetDir); currentLine.push_back("$"); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 79a3969..26251b3 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -632,7 +632,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector& args) { return cmcmd::ExecuteEchoColor(args); } - else if (args[1] == "cmake_automoc") + else if (args[1] == "cmake_autogen") { cmQtAutoGenerators autogen; const char *config = args[3].empty() ? 0 : args[3].c_str(); -- cgit v0.12 From 03878c9a22719eb8e86025c3cb489af8fd47a250 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 2 Oct 2013 13:49:19 +0200 Subject: Move variable set to where it is used. --- Source/cmQtAutoGenerators.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ee30987..7e61772 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -206,8 +206,6 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) cmMakefile* makefile = target->GetMakefile(); const char* targetName = target->GetName(); - bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE"); - // create a custom target for running automoc at buildtime: std::string automocTargetName = targetName; automocTargetName += "_automoc"; @@ -338,6 +336,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str()); makefile->AddDefinition("_moc_headers", cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); + bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE"); makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE"); std::string _moc_incs; -- cgit v0.12 From 4abb111584c4f0738cd2858cfa7d3adee5248a83 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 2 Oct 2013 13:50:07 +0200 Subject: Rename local variable to reflect generic use. --- Source/cmQtAutoGenerators.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 7e61772..26e003f 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -207,13 +207,13 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) const char* targetName = target->GetName(); // create a custom target for running automoc at buildtime: - std::string automocTargetName = targetName; - automocTargetName += "_automoc"; + std::string autogenTargetName = targetName; + autogenTargetName += "_automoc"; std::string targetDir = makefile->GetCurrentOutputDirectory(); targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); targetDir += "/"; - targetDir += automocTargetName; + targetDir += autogenTargetName; targetDir += ".dir/"; cmCustomCommandLine currentLine; @@ -264,7 +264,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) #endif { cmTarget* automocTarget = makefile->AddUtilityCommand( - automocTargetName.c_str(), true, + autogenTargetName.c_str(), true, workingDirectory.c_str(), depends, commandLines, false, automocComment.c_str()); // Set target folder @@ -280,7 +280,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) copyTargetProperty(automocTarget, target, "FOLDER"); } - target->AddUtility(automocTargetName.c_str()); + target->AddUtility(autogenTargetName.c_str()); } // configure a file to get all information to automoc at buildtime: @@ -329,7 +329,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) static_cast(varScope); makefile->AddDefinition("_moc_target_name", - cmLocalGenerator::EscapeForCMake(automocTargetName.c_str()).c_str()); + cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); makefile->AddDefinition("_moc_options", cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); makefile->AddDefinition("_moc_files", @@ -408,7 +408,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) if (!qt5Moc) { cmSystemTools::Error("Qt5::moc target not found ", - automocTargetName.c_str()); + autogenTargetName.c_str()); return; } makefile->AddDefinition("_qt_moc_executable", qt5Moc->GetLocation(0)); @@ -418,7 +418,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) if (strcmp(qtVersion, "4") != 0) { cmSystemTools::Error("The CMAKE_AUTOMOC feature supports only Qt 4 and " - "Qt 5 ", automocTargetName.c_str()); + "Qt 5 ", autogenTargetName.c_str()); } } -- cgit v0.12 From 97f1aa39da3e56ea4839e918f05928440d9d9dfa Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 2 Oct 2013 13:50:31 +0200 Subject: Rename method to reflect generic use. --- Source/cmQtAutoGenerators.cxx | 4 ++-- Source/cmQtAutoGenerators.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 26e003f..391f7bb 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -472,7 +472,7 @@ bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) cmGlobalGenerator* gg = this->CreateGlobalGenerator(&cm, targetDirectory); cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile(); - this->ReadAutomocInfoFile(makefile, targetDirectory, config); + this->ReadAutogenInfoFile(makefile, targetDirectory, config); this->ReadOldMocDefinitionsFile(makefile, targetDirectory); this->Init(); @@ -508,7 +508,7 @@ cmGlobalGenerator* cmQtAutoGenerators::CreateGlobalGenerator(cmake* cm, } -bool cmQtAutoGenerators::ReadAutomocInfoFile(cmMakefile* makefile, +bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, const char* targetDirectory, const char *config) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index ef38a5b..68a2d27 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -30,7 +30,7 @@ private: cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, const char* targetDirectory); - bool ReadAutomocInfoFile(cmMakefile* makefile, + bool ReadAutogenInfoFile(cmMakefile* makefile, const char* targetDirectory, const char *config); bool ReadOldMocDefinitionsFile(cmMakefile* makefile, -- cgit v0.12 From 63378baa1ceacbfdd52753e6dc7228ccfc53f4e5 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:26:51 +0200 Subject: Rename some variables to reflect broader scope. --- Source/cmQtAutoGenerators.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 391f7bb..b41ef75 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -206,7 +206,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) cmMakefile* makefile = target->GetMakefile(); const char* targetName = target->GetName(); - // create a custom target for running automoc at buildtime: + // create a custom target for running generators at buildtime: std::string autogenTargetName = targetName; autogenTargetName += "_automoc"; @@ -230,8 +230,9 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) "", makefile->GetCurrentOutputDirectory()); std::vector depends; - std::string automocComment = "Automoc for target "; - automocComment += targetName; + std::string tools = "moc"; + std::string autogenComment = "Automatic " + tools + " for target "; + autogenComment += targetName; #if defined(_WIN32) && !defined(__CYGWIN__) bool usePRE_BUILD = false; @@ -254,7 +255,7 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. std::vector no_output; cmCustomCommand cc(makefile, no_output, depends, - commandLines, automocComment.c_str(), + commandLines, autogenComment.c_str(), workingDirectory.c_str()); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); @@ -263,21 +264,21 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) else #endif { - cmTarget* automocTarget = makefile->AddUtilityCommand( + cmTarget* autogenTarget = makefile->AddUtilityCommand( autogenTargetName.c_str(), true, workingDirectory.c_str(), depends, - commandLines, false, automocComment.c_str()); + commandLines, false, autogenComment.c_str()); // Set target folder const char* automocFolder = makefile->GetCMakeInstance()->GetProperty( "AUTOMOC_TARGETS_FOLDER"); if (automocFolder && *automocFolder) { - automocTarget->SetProperty("FOLDER", automocFolder); + autogenTarget->SetProperty("FOLDER", automocFolder); } else { // inherit FOLDER property from target (#13688) - copyTargetProperty(automocTarget, target, "FOLDER"); + copyTargetProperty(autogenTarget, target, "FOLDER"); } target->AddUtility(autogenTargetName.c_str()); -- cgit v0.12 From 98632effebc7ed59105a67c549989265a3b207f1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:26:53 +0200 Subject: Add the AUTOGEN_TARGETS_FOLDER and obsolete AUTOMOC_TARGETS_FOLDER. --- Help/manual/cmake-properties.7.rst | 1 + Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst | 8 ++++++++ Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst | 2 ++ Source/cmQtAutoGenerators.cxx | 11 ++++++++--- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index bb3acff..c248085 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -10,6 +10,7 @@ Properties of Global Scope .. toctree:: /prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS + /prop_gbl/AUTOGEN_TARGETS_FOLDER /prop_gbl/AUTOMOC_TARGETS_FOLDER /prop_gbl/DEBUG_CONFIGURATIONS /prop_gbl/DISABLED_FEATURES diff --git a/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst new file mode 100644 index 0000000..48cc8a1 --- /dev/null +++ b/Help/prop_gbl/AUTOGEN_TARGETS_FOLDER.rst @@ -0,0 +1,8 @@ +AUTOGEN_TARGETS_FOLDER +---------------------- + +Name of FOLDER for ``*_automoc`` targets that are added automatically by CMake for targets for which AUTOMOC is enabled. + +If not set, CMake uses the FOLDER property of the parent target as a +default value for this property. See also the documentation for the +FOLDER target property and the AUTOMOC target property. diff --git a/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst index c83fb8b..185e0ec 100644 --- a/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst +++ b/Help/prop_gbl/AUTOMOC_TARGETS_FOLDER.rst @@ -3,6 +3,8 @@ AUTOMOC_TARGETS_FOLDER Name of FOLDER for ``*_automoc`` targets that are added automatically by CMake for targets for which AUTOMOC is enabled. +This property is obsolete. Use AUTOGEN_TARGETS_FOLDER instead. + If not set, CMake uses the FOLDER property of the parent target as a default value for this property. See also the documentation for the FOLDER target property and the AUTOMOC target property. diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index b41ef75..3d915dd 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -269,11 +269,16 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) workingDirectory.c_str(), depends, commandLines, false, autogenComment.c_str()); // Set target folder - const char* automocFolder = makefile->GetCMakeInstance()->GetProperty( + const char* autogenFolder = makefile->GetCMakeInstance()->GetProperty( "AUTOMOC_TARGETS_FOLDER"); - if (automocFolder && *automocFolder) + if (!autogenFolder) { - autogenTarget->SetProperty("FOLDER", automocFolder); + autogenFolder = makefile->GetCMakeInstance()->GetProperty( + "AUTOGEN_TARGETS_FOLDER"); + } + if (autogenFolder && *autogenFolder) + { + autogenTarget->SetProperty("FOLDER", autogenFolder); } else { -- cgit v0.12 From a342c9ffedb865919b7a13b5620caecbb5076865 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:26:54 +0200 Subject: Move some makefile definitions up away from moc-specific code. --- Source/cmQtAutoGenerators.cxx | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 3d915dd..5fbdb83 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -206,10 +206,31 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) cmMakefile* makefile = target->GetMakefile(); const char* targetName = target->GetName(); + // forget the variables added here afterwards again: + cmMakefile::ScopePushPop varScope(makefile); + static_cast(varScope); + + const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); + if (!qtVersion) + { + qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); + } + if (const char *targetQtVersion = + target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) + { + qtVersion = targetQtVersion; + } + if (qtVersion) + { + makefile->AddDefinition("_target_qt_version", qtVersion); + } // create a custom target for running generators at buildtime: std::string autogenTargetName = targetName; autogenTargetName += "_automoc"; + makefile->AddDefinition("_moc_target_name", + cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); + std::string targetDir = makefile->GetCurrentOutputDirectory(); targetDir += makefile->GetCMakeInstance()->GetCMakeFilesDirectory(); targetDir += "/"; @@ -329,13 +350,6 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) const char* tmp = target->GetProperty("AUTOMOC_MOC_OPTIONS"); std::string _moc_options = (tmp!=0 ? tmp : ""); - - // forget the variables added here afterwards again: - cmMakefile::ScopePushPop varScope(makefile); - static_cast(varScope); - - makefile->AddDefinition("_moc_target_name", - cmLocalGenerator::EscapeForCMake(autogenTargetName.c_str()).c_str()); makefile->AddDefinition("_moc_options", cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); makefile->AddDefinition("_moc_files", @@ -388,21 +402,6 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) } } - const char *qtVersion = makefile->GetDefinition("Qt5Core_VERSION_MAJOR"); - if (!qtVersion) - { - qtVersion = makefile->GetDefinition("QT_VERSION_MAJOR"); - } - if (const char *targetQtVersion = - target->GetLinkInterfaceDependentStringProperty("QT_MAJOR_VERSION", 0)) - { - qtVersion = targetQtVersion; - } - if (qtVersion) - { - makefile->AddDefinition("_target_qt_version", qtVersion); - } - { const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); makefile->AddDefinition("_qt_moc_executable", qtMoc); -- cgit v0.12 From ca124a15150b5f88a9dcd9edfc4f61cf473efc64 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:26:55 +0200 Subject: Rename the AutomocInfo.cmake file to be more generic. --- Modules/AutogenInfo.cmake.in | 14 ++++++++++++++ Modules/AutomocInfo.cmake.in | 14 -------------- Source/cmQtAutoGenerators.cxx | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 Modules/AutogenInfo.cmake.in delete mode 100644 Modules/AutomocInfo.cmake.in diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in new file mode 100644 index 0000000..9cff735 --- /dev/null +++ b/Modules/AutogenInfo.cmake.in @@ -0,0 +1,14 @@ +set(AM_SOURCES @_moc_files@ ) +set(AM_HEADERS @_moc_headers@ ) +set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) +set(AM_MOC_INCLUDES @_moc_incs@) +set(AM_MOC_OPTIONS @_moc_options@) +set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE@") +set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") +set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") +set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@") +set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/") +set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") +set(AM_QT_VERSION_MAJOR "@_target_qt_version@") +set(AM_TARGET_NAME @_moc_target_name@) +set(AM_RELAXED_MODE "@_moc_relaxed_mode@") diff --git a/Modules/AutomocInfo.cmake.in b/Modules/AutomocInfo.cmake.in deleted file mode 100644 index 9cff735..0000000 --- a/Modules/AutomocInfo.cmake.in +++ /dev/null @@ -1,14 +0,0 @@ -set(AM_SOURCES @_moc_files@ ) -set(AM_HEADERS @_moc_headers@ ) -set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) -set(AM_MOC_INCLUDES @_moc_incs@) -set(AM_MOC_OPTIONS @_moc_options@) -set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE@") -set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") -set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") -set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@") -set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/") -set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") -set(AM_QT_VERSION_MAJOR "@_target_qt_version@") -set(AM_TARGET_NAME @_moc_target_name@) -set(AM_RELAXED_MODE "@_moc_relaxed_mode@") diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 5fbdb83..9016827 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -429,9 +429,9 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); std::string inputFile = cmakeRoot; - inputFile += "/Modules/AutomocInfo.cmake.in"; + inputFile += "/Modules/AutogenInfo.cmake.in"; std::string outputFile = targetDir; - outputFile += "/AutomocInfo.cmake"; + outputFile += "/AutogenInfo.cmake"; makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), false, true, false); @@ -519,7 +519,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, { std::string filename(cmSystemTools::CollapseFullPath(targetDirectory)); cmSystemTools::ConvertToUnixSlashes(filename); - filename += "/AutomocInfo.cmake"; + filename += "/AutogenInfo.cmake"; if (!makefile->ReadListFile(0, filename.c_str())) { -- cgit v0.12 From 85b3d6e73d1d5620229c7fc67a705fd50c8bcff0 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:26:56 +0200 Subject: Extract an SetupAutoMocTarget method. This class will soon gain methods for autouic and autorcc. --- Source/cmQtAutoGenerators.cxx | 104 +++++++++++++++++++++++------------------- Source/cmQtAutoGenerators.h | 5 ++ 2 files changed, 61 insertions(+), 48 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 9016827..8d3de52 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -310,7 +310,61 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) target->AddUtility(autogenTargetName.c_str()); } - // configure a file to get all information to automoc at buildtime: + std::map configIncludes; + std::map configDefines; + + this->SetupAutoMocTarget(target, autogenTargetName, + configIncludes, configDefines); + + const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); + std::string inputFile = cmakeRoot; + inputFile += "/Modules/AutogenInfo.cmake.in"; + std::string outputFile = targetDir; + outputFile += "/AutogenInfo.cmake"; + makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), + false, true, false); + + if (!configDefines.empty() || !configIncludes.empty()) + { + std::ofstream infoFile(outputFile.c_str(), std::ios::app); + if ( !infoFile ) + { + std::string error = "Internal CMake error when trying to open file: "; + error += outputFile.c_str(); + error += " for writing."; + cmSystemTools::Error(error.c_str()); + return; + } + if (!configDefines.empty()) + { + for (std::map::iterator + it = configDefines.begin(), end = configDefines.end(); + it != end; ++it) + { + infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << + " " << it->second << ")\n"; + } + } + if (!configIncludes.empty()) + { + for (std::map::iterator + it = configIncludes.begin(), end = configIncludes.end(); + it != end; ++it) + { + infoFile << "set(AM_MOC_INCLUDES_" << it->first << + " " << it->second << ")\n"; + } + } + } +} + +void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target, + const std::string &autogenTargetName, + std::map &configIncludes, + std::map &configDefines) +{ + cmMakefile* makefile = target->GetMakefile(); + std::string _moc_files; std::string _moc_headers; const char* sepFiles = ""; @@ -371,9 +425,6 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) makefile->AddDefinition("_moc_compile_defs", cmLocalGenerator::EscapeForCMake(_moc_compile_defs.c_str()).c_str()); - std::map configIncludes; - std::map configDefines; - for (std::vector::const_iterator li = configs.begin(); li != configs.end(); ++li) { @@ -402,11 +453,10 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) } } - { const char *qtMoc = makefile->GetSafeDefinition("QT_MOC_EXECUTABLE"); makefile->AddDefinition("_qt_moc_executable", qtMoc); - } + const char *qtVersion = makefile->GetDefinition("_target_qt_version"); if (strcmp(qtVersion, "5") == 0) { cmTarget *qt5Moc = makefile->FindTargetToUse("Qt5::moc"); @@ -426,50 +476,8 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) "Qt 5 ", autogenTargetName.c_str()); } } - - const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); - std::string inputFile = cmakeRoot; - inputFile += "/Modules/AutogenInfo.cmake.in"; - std::string outputFile = targetDir; - outputFile += "/AutogenInfo.cmake"; - makefile->ConfigureFile(inputFile.c_str(), outputFile.c_str(), - false, true, false); - - if (!configDefines.empty() || !configIncludes.empty()) - { - std::ofstream infoFile(outputFile.c_str(), std::ios::app); - if ( !infoFile ) - { - std::string error = "Internal CMake error when trying to open file: "; - error += outputFile.c_str(); - error += " for writing."; - cmSystemTools::Error(error.c_str()); - return; - } - if (!configDefines.empty()) - { - for (std::map::iterator - it = configDefines.begin(), end = configDefines.end(); - it != end; ++it) - { - infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << - " " << it->second << ")\n"; - } - } - if (!configIncludes.empty()) - { - for (std::map::iterator - it = configIncludes.begin(), end = configIncludes.end(); - it != end; ++it) - { - infoFile << "set(AM_MOC_INCLUDES_" << it->first << - " " << it->second << ")\n"; - } - } - } } - bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) { bool success = true; diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 68a2d27..ce70890 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -27,6 +27,11 @@ public: void SetupAutoGenerateTarget(cmTarget* target); private: + void SetupAutoMocTarget(cmTarget* target, + const std::string &autogenTargetName, + std::map &configIncludes, + std::map &configDefines); + cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, const char* targetDirectory); -- cgit v0.12 From f371ab5803b3d675170f4b163701d707e56b47d9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 13:28:08 +0200 Subject: Rename RunAutomoc to RunAutogen. It will soon be used to process ui and rcc files too. --- Source/cmQtAutoGenerators.cxx | 4 ++-- Source/cmQtAutoGenerators.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 8d3de52..4f67241 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -492,7 +492,7 @@ bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) if (this->QtMajorVersion == "4" || this->QtMajorVersion == "5") { - success = this->RunAutomoc(makefile); + success = this->RunAutogen(makefile); } this->WriteOldMocDefinitionsFile(targetDirectory); @@ -719,7 +719,7 @@ void cmQtAutoGenerators::Init() } -bool cmQtAutoGenerators::RunAutomoc(cmMakefile* makefile) +bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) { if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str()) || (this->OldCompileSettingsStr != this->CurrentCompileSettingsStr)) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index ce70890..fe38b05 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -44,7 +44,7 @@ private: std::string MakeCompileSettingsString(cmMakefile* makefile); - bool RunAutomoc(cmMakefile* makefile); + bool RunAutogen(cmMakefile* makefile); bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); void ParseCppFile(const std::string& absFilename, -- cgit v0.12 From 32771fc7ca959a90ef5e267831650323f3c0cf13 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 13:28:48 +0200 Subject: Update output messages for generic use. --- Source/cmQtAutoGenerators.cxx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 4f67241..4e75733 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -753,7 +753,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) const std::string &absFilename = *it; if (this->Verbose) { - std::cout << "AUTOMOC: Checking " << absFilename << std::endl; + std::cout << "AUTOGEN: Checking " << absFilename << std::endl; } if (this->RelaxedMode) { @@ -854,7 +854,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, const std::string contentsString = this->ReadAll(absFilename); if (contentsString.empty()) { - std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" + std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; return; } @@ -914,7 +914,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, } else { - std::cerr << "AUTOMOC: error: " << absFilename << " The file " + std::cerr << "AUTOGEN: error: " << absFilename << " The file " << "includes the moc file \"" << currentMoc << "\", " << "but could not find header \"" << basename << '{' << this->Join(headerExtensions, ',') << "}\" "; @@ -945,7 +945,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, fileToMoc = headerToMoc; if ((requiresMoc==false) &&(basename==scannedFileBasename)) { - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + std::cerr << "AUTOGEN: warning: " << absFilename << ": The file " "includes the moc file \"" << currentMoc << "\", but does not contain a " << macroName << " macro. Running moc on " @@ -956,7 +956,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, } else { - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + std::cerr << "AUTOGEN: warning: " << absFilename << ": The file " "includes the moc file \"" << currentMoc << "\" instead of \"moc_" << basename << ".cpp\". " "Running moc on " @@ -968,7 +968,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, } else { - std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " + std::cerr <<"AUTOGEN: error: " << absFilename << ": The file " "includes the moc file \"" << currentMoc << "\", which seems to be the moc file from a different " "source file. CMake also could not find a matching " @@ -996,7 +996,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, if (mocUnderscoreIncluded == true) { // this is for KDE4 compatibility: - std::cerr << "AUTOMOC: warning: " << absFilename << ": The file " + std::cerr << "AUTOGEN: warning: " << absFilename << ": The file " << "contains a " << macroName << " macro, but does not " "include " << "\"" << scannedFileBasename << ".moc\", but instead " @@ -1012,7 +1012,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, else { // otherwise always error out since it will not compile: - std::cerr << "AUTOMOC: error: " << absFilename << ": The file " + std::cerr << "AUTOGEN: error: " << absFilename << ": The file " << "contains a " << macroName << " macro, but does not " "include " << "\"" << scannedFileBasename << ".moc\" !\n" @@ -1035,7 +1035,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, const std::string contentsString = this->ReadAll(absFilename); if (contentsString.empty()) { - std::cerr << "AUTOMOC: warning: " << absFilename << ": file is empty\n" + std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n" << std::endl; return; } @@ -1082,7 +1082,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, } else { - std::cerr << "AUTOMOC: error: " << absFilename << " The file " + std::cerr << "AUTOGEN: error: " << absFilename << " The file " << "includes the moc file \"" << currentMoc << "\", " << "but could not find header \"" << basename << '{' << this->Join(headerExtensions, ',') << "}\" "; @@ -1103,7 +1103,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, { if (basename != scannedFileBasename) { - std::cerr <<"AUTOMOC: error: " << absFilename << ": The file " + std::cerr <<"AUTOGEN: error: " << absFilename << ": The file " "includes the moc file \"" << currentMoc << "\", which seems to be the moc file from a different " "source file. This is not supported. " @@ -1127,7 +1127,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, macroName))) { // otherwise always error out since it will not compile: - std::cerr << "AUTOMOC: error: " << absFilename << ": The file " + std::cerr << "AUTOGEN: error: " << absFilename << ": The file " << "contains a " << macroName << " macro, but does not include " << "\"" << scannedFileBasename << ".moc\" !\n" << std::endl; @@ -1188,7 +1188,7 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, { if (this->Verbose) { - std::cout << "AUTOMOC: Checking " << headerName << std::endl; + std::cout << "AUTOGEN: Checking " << headerName << std::endl; } const std::string basename = cmsys::SystemTools:: @@ -1274,7 +1274,7 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal); if (!result || retVal) { - std::cerr << "AUTOMOC: error: process for " << mocFilePath <<" failed:\n" + std::cerr << "AUTOGEN: error: process for " << mocFilePath <<" failed:\n" << output << std::endl; this->RunMocFailed = true; cmSystemTools::RemoveFile(mocFilePath.c_str()); -- cgit v0.12 From 7ce65c3c9738414213ae307005277c774daea669 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 13:30:54 +0200 Subject: Add extra checks for the AUTOMOC target property. In an upcoming commit, this class will be used even if it is not set. --- Source/cmQtAutoGenerators.cxx | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 4e75733..656bb0c 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -149,18 +149,22 @@ bool cmQtAutoGenerators::InitializeMocSourceFile(cmTarget* target) return false; } - std::string automocTargetName = target->GetName(); - automocTargetName += "_automoc"; - std::string mocCppFile = makefile->GetCurrentOutputDirectory(); - mocCppFile += "/"; - mocCppFile += automocTargetName; - mocCppFile += ".cpp"; - cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(), - true); - makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", - mocCppFile.c_str(), false); - - target->AddSourceFile(mocCppSource); + if (target->GetPropertyAsBool("AUTOMOC")) + { + std::string automocTargetName = target->GetName(); + automocTargetName += "_automoc"; + std::string mocCppFile = makefile->GetCurrentOutputDirectory(); + mocCppFile += "/"; + mocCppFile += automocTargetName; + mocCppFile += ".cpp"; + cmSourceFile* mocCppSource = makefile->GetOrCreateSource( + mocCppFile.c_str(), + true); + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", + mocCppFile.c_str(), false); + + target->AddSourceFile(mocCppSource); + } return true; } @@ -313,8 +317,11 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) std::map configIncludes; std::map configDefines; - this->SetupAutoMocTarget(target, autogenTargetName, - configIncludes, configDefines); + if (target->GetPropertyAsBool("AUTOMOC")) + { + this->SetupAutoMocTarget(target, autogenTargetName, + configIncludes, configDefines); + } const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); std::string inputFile = cmakeRoot; -- cgit v0.12 From e485ba12193d36ffc4faee89bb80dbe611ad7e82 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 14:17:32 +0200 Subject: Rename the QtAutomoc tests to QtAutogen. --- Tests/CMakeLists.txt | 24 +- Tests/QtAutogen/Adir/CMakeLists.txt | 8 + Tests/QtAutogen/Adir/libA.cpp | 13 + Tests/QtAutogen/Adir/libA.h | 18 ++ Tests/QtAutogen/Bdir/CMakeLists.txt | 10 + Tests/QtAutogen/Bdir/libB.cpp | 13 + Tests/QtAutogen/Bdir/libB.h | 21 ++ Tests/QtAutogen/CMakeLists.txt | 68 ++++ Tests/QtAutogen/abc.cpp | 49 +++ Tests/QtAutogen/abc.h | 28 ++ Tests/QtAutogen/abc_p.h | 30 ++ Tests/QtAutogen/bar.cpp | 28 ++ Tests/QtAutogen/blub.cpp | 40 +++ Tests/QtAutogen/blub.h | 26 ++ Tests/QtAutogen/calwidget.cpp | 431 ++++++++++++++++++++++++++ Tests/QtAutogen/calwidget.h | 121 ++++++++ Tests/QtAutogen/codeeditor.cpp | 153 +++++++++ Tests/QtAutogen/codeeditor.h | 99 ++++++ Tests/QtAutogen/defines_test/CMakeLists.txt | 6 + Tests/QtAutogen/defines_test/defines_test.cpp | 38 +++ Tests/QtAutogen/empty.cpp | 1 + Tests/QtAutogen/empty.h | 9 + Tests/QtAutogen/foo.cpp | 39 +++ Tests/QtAutogen/foo.h | 28 ++ Tests/QtAutogen/gadget.cpp | 4 + Tests/QtAutogen/gadget.h | 18 ++ Tests/QtAutogen/libC.cpp | 13 + Tests/QtAutogen/libC.h | 22 ++ Tests/QtAutogen/main.cpp | 86 +++++ Tests/QtAutogen/private_slot.cpp | 21 ++ Tests/QtAutogen/private_slot.h | 20 ++ Tests/QtAutogen/sub/bar.h | 28 ++ Tests/QtAutogen/xyz.cpp | 28 ++ Tests/QtAutogen/xyz.h | 28 ++ Tests/QtAutogen/yaf.cpp | 32 ++ Tests/QtAutogen/yaf.h | 25 ++ Tests/QtAutogen/yaf_p.h | 30 ++ Tests/QtAutomoc/Adir/CMakeLists.txt | 8 - Tests/QtAutomoc/Adir/libA.cpp | 13 - Tests/QtAutomoc/Adir/libA.h | 18 -- Tests/QtAutomoc/Bdir/CMakeLists.txt | 10 - Tests/QtAutomoc/Bdir/libB.cpp | 13 - Tests/QtAutomoc/Bdir/libB.h | 21 -- Tests/QtAutomoc/CMakeLists.txt | 68 ---- Tests/QtAutomoc/abc.cpp | 49 --- Tests/QtAutomoc/abc.h | 28 -- Tests/QtAutomoc/abc_p.h | 30 -- Tests/QtAutomoc/bar.cpp | 28 -- Tests/QtAutomoc/blub.cpp | 40 --- Tests/QtAutomoc/blub.h | 26 -- Tests/QtAutomoc/calwidget.cpp | 431 -------------------------- Tests/QtAutomoc/calwidget.h | 121 -------- Tests/QtAutomoc/codeeditor.cpp | 153 --------- Tests/QtAutomoc/codeeditor.h | 99 ------ Tests/QtAutomoc/defines_test/CMakeLists.txt | 6 - Tests/QtAutomoc/defines_test/defines_test.cpp | 38 --- Tests/QtAutomoc/empty.cpp | 1 - Tests/QtAutomoc/empty.h | 9 - Tests/QtAutomoc/foo.cpp | 39 --- Tests/QtAutomoc/foo.h | 28 -- Tests/QtAutomoc/gadget.cpp | 4 - Tests/QtAutomoc/gadget.h | 18 -- Tests/QtAutomoc/libC.cpp | 13 - Tests/QtAutomoc/libC.h | 22 -- Tests/QtAutomoc/main.cpp | 86 ----- Tests/QtAutomoc/private_slot.cpp | 21 -- Tests/QtAutomoc/private_slot.h | 20 -- Tests/QtAutomoc/sub/bar.h | 28 -- Tests/QtAutomoc/xyz.cpp | 28 -- Tests/QtAutomoc/xyz.h | 28 -- Tests/QtAutomoc/yaf.cpp | 32 -- Tests/QtAutomoc/yaf.h | 25 -- Tests/QtAutomoc/yaf_p.h | 30 -- 73 files changed, 1644 insertions(+), 1644 deletions(-) create mode 100644 Tests/QtAutogen/Adir/CMakeLists.txt create mode 100644 Tests/QtAutogen/Adir/libA.cpp create mode 100644 Tests/QtAutogen/Adir/libA.h create mode 100644 Tests/QtAutogen/Bdir/CMakeLists.txt create mode 100644 Tests/QtAutogen/Bdir/libB.cpp create mode 100644 Tests/QtAutogen/Bdir/libB.h create mode 100644 Tests/QtAutogen/CMakeLists.txt create mode 100644 Tests/QtAutogen/abc.cpp create mode 100644 Tests/QtAutogen/abc.h create mode 100644 Tests/QtAutogen/abc_p.h create mode 100644 Tests/QtAutogen/bar.cpp create mode 100644 Tests/QtAutogen/blub.cpp create mode 100644 Tests/QtAutogen/blub.h create mode 100644 Tests/QtAutogen/calwidget.cpp create mode 100644 Tests/QtAutogen/calwidget.h create mode 100644 Tests/QtAutogen/codeeditor.cpp create mode 100644 Tests/QtAutogen/codeeditor.h create mode 100644 Tests/QtAutogen/defines_test/CMakeLists.txt create mode 100644 Tests/QtAutogen/defines_test/defines_test.cpp create mode 100644 Tests/QtAutogen/empty.cpp create mode 100644 Tests/QtAutogen/empty.h create mode 100644 Tests/QtAutogen/foo.cpp create mode 100644 Tests/QtAutogen/foo.h create mode 100644 Tests/QtAutogen/gadget.cpp create mode 100644 Tests/QtAutogen/gadget.h create mode 100644 Tests/QtAutogen/libC.cpp create mode 100644 Tests/QtAutogen/libC.h create mode 100644 Tests/QtAutogen/main.cpp create mode 100644 Tests/QtAutogen/private_slot.cpp create mode 100644 Tests/QtAutogen/private_slot.h create mode 100644 Tests/QtAutogen/sub/bar.h create mode 100644 Tests/QtAutogen/xyz.cpp create mode 100644 Tests/QtAutogen/xyz.h create mode 100644 Tests/QtAutogen/yaf.cpp create mode 100644 Tests/QtAutogen/yaf.h create mode 100644 Tests/QtAutogen/yaf_p.h delete mode 100644 Tests/QtAutomoc/Adir/CMakeLists.txt delete mode 100644 Tests/QtAutomoc/Adir/libA.cpp delete mode 100644 Tests/QtAutomoc/Adir/libA.h delete mode 100644 Tests/QtAutomoc/Bdir/CMakeLists.txt delete mode 100644 Tests/QtAutomoc/Bdir/libB.cpp delete mode 100644 Tests/QtAutomoc/Bdir/libB.h delete mode 100644 Tests/QtAutomoc/CMakeLists.txt delete mode 100644 Tests/QtAutomoc/abc.cpp delete mode 100644 Tests/QtAutomoc/abc.h delete mode 100644 Tests/QtAutomoc/abc_p.h delete mode 100644 Tests/QtAutomoc/bar.cpp delete mode 100644 Tests/QtAutomoc/blub.cpp delete mode 100644 Tests/QtAutomoc/blub.h delete mode 100644 Tests/QtAutomoc/calwidget.cpp delete mode 100644 Tests/QtAutomoc/calwidget.h delete mode 100644 Tests/QtAutomoc/codeeditor.cpp delete mode 100644 Tests/QtAutomoc/codeeditor.h delete mode 100644 Tests/QtAutomoc/defines_test/CMakeLists.txt delete mode 100644 Tests/QtAutomoc/defines_test/defines_test.cpp delete mode 100644 Tests/QtAutomoc/empty.cpp delete mode 100644 Tests/QtAutomoc/empty.h delete mode 100644 Tests/QtAutomoc/foo.cpp delete mode 100644 Tests/QtAutomoc/foo.h delete mode 100644 Tests/QtAutomoc/gadget.cpp delete mode 100644 Tests/QtAutomoc/gadget.h delete mode 100644 Tests/QtAutomoc/libC.cpp delete mode 100644 Tests/QtAutomoc/libC.h delete mode 100644 Tests/QtAutomoc/main.cpp delete mode 100644 Tests/QtAutomoc/private_slot.cpp delete mode 100644 Tests/QtAutomoc/private_slot.h delete mode 100644 Tests/QtAutomoc/sub/bar.h delete mode 100644 Tests/QtAutomoc/xyz.cpp delete mode 100644 Tests/QtAutomoc/xyz.h delete mode 100644 Tests/QtAutomoc/yaf.cpp delete mode 100644 Tests/QtAutomoc/yaf.h delete mode 100644 Tests/QtAutomoc/yaf_p.h diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b9c99e3..38b2a0c 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1031,32 +1031,32 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ find_package(Qt5Widgets QUIET NO_MODULE) if(Qt5Widgets_FOUND) - add_test(Qt5Automoc ${CMAKE_CTEST_COMMAND} + add_test(Qt5Autogen ${CMAKE_CTEST_COMMAND} --build-and-test - "${CMake_SOURCE_DIR}/Tests/QtAutomoc" - "${CMake_BINARY_DIR}/Tests/Qt5Automoc" + "${CMake_SOURCE_DIR}/Tests/QtAutogen" + "${CMake_BINARY_DIR}/Tests/Qt5Autogen" ${build_generator_args} - --build-project QtAutomoc - --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5Automoc" + --build-project QtAutogen + --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5Autogen" --force-new-ctest-process --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=5 --test-command ${CMAKE_CTEST_COMMAND} -V ) - list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5Automoc") + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5Autogen") endif() if(QT4_WORKS AND QT_QTGUI_FOUND) - add_test(Qt4Automoc ${CMAKE_CTEST_COMMAND} + add_test(Qt4Autogen ${CMAKE_CTEST_COMMAND} --build-and-test - "${CMake_SOURCE_DIR}/Tests/QtAutomoc" - "${CMake_BINARY_DIR}/Tests/Qt4Automoc" + "${CMake_SOURCE_DIR}/Tests/QtAutogen" + "${CMake_BINARY_DIR}/Tests/Qt4Autogen" ${build_generator_args} - --build-project QtAutomoc - --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Automoc" + --build-project QtAutogen + --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Autogen" --force-new-ctest-process --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4 --test-command ${CMAKE_CTEST_COMMAND} -V ) - list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Automoc") + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Autogen") add_test(Qt4Targets ${CMAKE_CTEST_COMMAND} --build-and-test diff --git a/Tests/QtAutogen/Adir/CMakeLists.txt b/Tests/QtAutogen/Adir/CMakeLists.txt new file mode 100644 index 0000000..a1c36ff --- /dev/null +++ b/Tests/QtAutogen/Adir/CMakeLists.txt @@ -0,0 +1,8 @@ + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) + +add_library(libA SHARED libA.cpp) +target_link_libraries(libA LINK_PUBLIC ${QT_QTCORE_TARGET}) +generate_export_header(libA) diff --git a/Tests/QtAutogen/Adir/libA.cpp b/Tests/QtAutogen/Adir/libA.cpp new file mode 100644 index 0000000..3968c44 --- /dev/null +++ b/Tests/QtAutogen/Adir/libA.cpp @@ -0,0 +1,13 @@ + +#include "libA.h" + +LibA::LibA(QObject *parent) + : QObject(parent) +{ + +} + +int LibA::foo() +{ + return 0; +} diff --git a/Tests/QtAutogen/Adir/libA.h b/Tests/QtAutogen/Adir/libA.h new file mode 100644 index 0000000..03ad1e0 --- /dev/null +++ b/Tests/QtAutogen/Adir/libA.h @@ -0,0 +1,18 @@ + +#ifndef LIBA_H +#define LIBA_H + +#include "liba_export.h" + +#include + +class LIBA_EXPORT LibA : public QObject +{ + Q_OBJECT +public: + explicit LibA(QObject *parent = 0); + + int foo(); +}; + +#endif diff --git a/Tests/QtAutogen/Bdir/CMakeLists.txt b/Tests/QtAutogen/Bdir/CMakeLists.txt new file mode 100644 index 0000000..d9d4aa7 --- /dev/null +++ b/Tests/QtAutogen/Bdir/CMakeLists.txt @@ -0,0 +1,10 @@ + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) + +add_library(libB SHARED libB.cpp) +generate_export_header(libB) + +# set_property(TARGET libB APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) +target_link_libraries(libB LINK_PUBLIC libA) diff --git a/Tests/QtAutogen/Bdir/libB.cpp b/Tests/QtAutogen/Bdir/libB.cpp new file mode 100644 index 0000000..72f2cfa --- /dev/null +++ b/Tests/QtAutogen/Bdir/libB.cpp @@ -0,0 +1,13 @@ + +#include "libB.h" + +LibB::LibB(QObject *parent) + : QObject(parent) +{ + +} + +int LibB::foo() +{ + return a.foo(); +} diff --git a/Tests/QtAutogen/Bdir/libB.h b/Tests/QtAutogen/Bdir/libB.h new file mode 100644 index 0000000..510c17f --- /dev/null +++ b/Tests/QtAutogen/Bdir/libB.h @@ -0,0 +1,21 @@ + +#ifndef LIBB_H +#define LIBB_H + +#include "libb_export.h" + +#include +#include "libA.h" + +class LIBB_EXPORT LibB : public QObject +{ + Q_OBJECT +public: + explicit LibB(QObject *parent = 0); + + int foo(); +private: + LibA a; +}; + +#endif diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt new file mode 100644 index 0000000..a7f553f --- /dev/null +++ b/Tests/QtAutogen/CMakeLists.txt @@ -0,0 +1,68 @@ +cmake_minimum_required(VERSION 2.8) + +project(QtAutogen) + +if (QT_TEST_VERSION STREQUAL 4) + find_package(Qt4 REQUIRED) + + # Include this directory before using the UseQt4 file. + add_subdirectory(defines_test) + + include(UseQt4) + + set(QT_QTCORE_TARGET Qt4::QtCore) +else() + if (NOT QT_TEST_VERSION STREQUAL 5) + message(SEND_ERROR "Invalid Qt version specified.") + endif() + find_package(Qt5Widgets REQUIRED) + + set(QT_QTCORE_TARGET Qt5::Core) + + include_directories(${Qt5Widgets_INCLUDE_DIRS}) + set(QT_LIBRARIES Qt5::Widgets) + + if(Qt5_POSITION_INDEPENDENT_CODE) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() +endif() + + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_definitions(-DFOO -DSomeDefine="Barx") + +# enable relaxed mode so automoc can handle all the special cases: +set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) + +# create an executable and two library targets, each requiring automoc: +add_library(codeeditorLib STATIC codeeditor.cpp) + +add_library(privateSlot OBJECT private_slot.cpp) + +add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp + xyz.cpp yaf.cpp gadget.cpp $) + +set_target_properties(foo codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) + +include(GenerateExportHeader) +# The order is relevant here. B depends on A, and B headers depend on A +# headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we +# test that CMAKE_AUTOMOC successfully reads the include directories +# for the build interface from those targets. There has previously been +# a bug where caching of the include directories happened before +# extracting the includes to pass to moc. +add_subdirectory(Bdir) +add_subdirectory(Adir) +add_library(libC SHARED libC.cpp) +set_target_properties(libC PROPERTIES AUTOMOC TRUE) +generate_export_header(libC) +target_link_libraries(libC LINK_PUBLIC libB) + +target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} libC) + +add_library(empty STATIC empty.cpp) +set_target_properties(empty PROPERTIES AUTOMOC TRUE) +target_link_libraries(empty no_link_language) +add_library(no_link_language STATIC empty.h) +set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutogen/abc.cpp b/Tests/QtAutogen/abc.cpp new file mode 100644 index 0000000..4bbc769 --- /dev/null +++ b/Tests/QtAutogen/abc.cpp @@ -0,0 +1,49 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + + +#include "abc.h" +#include "abc_p.h" + +#include + +class PrintAbc : public QObject +{ + Q_OBJECT + public: + PrintAbc():QObject() {} + public slots: + void print() const { printf("abc\n"); } +}; + +Abc::Abc() +:QObject() +{ +} + + +void Abc::doAbc() +{ + PrintAbc pa; + pa.print(); + AbcP abcP; + abcP.doAbcP(); +} + +// check that including the moc file for the cpp file and the header works: +#include "abc.moc" +#include "moc_abc.cpp" +#include "moc_abc_p.cpp" + +// check that including a moc file from another header works: +#include "moc_xyz.cpp" diff --git a/Tests/QtAutogen/abc.h b/Tests/QtAutogen/abc.h new file mode 100644 index 0000000..d1924b0 --- /dev/null +++ b/Tests/QtAutogen/abc.h @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef ABC_H +#define ABC_H + +#include + +class Abc : public QObject +{ + Q_OBJECT + public: + Abc(); + public slots: + void doAbc(); +}; + +#endif diff --git a/Tests/QtAutogen/abc_p.h b/Tests/QtAutogen/abc_p.h new file mode 100644 index 0000000..952fff3 --- /dev/null +++ b/Tests/QtAutogen/abc_p.h @@ -0,0 +1,30 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef ABC_P_H +#define ABC_P_H + +#include + +#include + +class AbcP : public QObject +{ + Q_OBJECT + public: + AbcP() {} + public slots: + void doAbcP() { printf("I am private abc !\n"); } +}; + +#endif diff --git a/Tests/QtAutogen/bar.cpp b/Tests/QtAutogen/bar.cpp new file mode 100644 index 0000000..8be4815 --- /dev/null +++ b/Tests/QtAutogen/bar.cpp @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "sub/bar.h" + +#include + +Bar::Bar() +:QObject() +{ +} + +void Bar::doBar() +{ + printf("Hello bar !\n"); +} + +#include "sub/moc_bar.cpp" diff --git a/Tests/QtAutogen/blub.cpp b/Tests/QtAutogen/blub.cpp new file mode 100644 index 0000000..bd53972 --- /dev/null +++ b/Tests/QtAutogen/blub.cpp @@ -0,0 +1,40 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "blub.h" + +#include + +class BlubBlub : public QObject +{ + Q_OBJECT + public: + BlubBlub():QObject() {} + public slots: + int getValue() const { return 13; } +}; + +Blub::Blub() +{ +} + + +void Blub::blubber() +{ + BlubBlub bb; + printf("Blub blub %d ! \n", bb.getValue()); +} + +// test the case that the wrong moc-file is included, it should +// actually be "blub.moc" +#include "moc_blub.cpp" diff --git a/Tests/QtAutogen/blub.h b/Tests/QtAutogen/blub.h new file mode 100644 index 0000000..1967bc1 --- /dev/null +++ b/Tests/QtAutogen/blub.h @@ -0,0 +1,26 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef BLUB_H +#define BLUB_H + +#include + +class Blub +{ + public: + Blub(); + void blubber(); +}; + +#endif diff --git a/Tests/QtAutogen/calwidget.cpp b/Tests/QtAutogen/calwidget.cpp new file mode 100644 index 0000000..cbfa5a8 --- /dev/null +++ b/Tests/QtAutogen/calwidget.cpp @@ -0,0 +1,431 @@ +/**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the examples of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + ** the names of its contributors may be used to endorse or promote + ** products derived from this software without specific prior written + ** permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + + #include + #include + #include + #include + #include + #include + #include + #include + + #include "calwidget.h" + + Window::Window() + { + createPreviewGroupBox(); + createGeneralOptionsGroupBox(); + createDatesGroupBox(); + createTextFormatsGroupBox(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(previewGroupBox, 0, 0); + layout->addWidget(generalOptionsGroupBox, 0, 1); + layout->addWidget(datesGroupBox, 1, 0); + layout->addWidget(textFormatsGroupBox, 1, 1); + layout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(layout); + + previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height()); + previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width()); + + setWindowTitle(tr("Calendar Widget")); + } + + void Window::localeChanged(int index) + { + calendar->setLocale(localeCombo->itemData(index).toLocale()); + } + + void Window::firstDayChanged(int index) + { + calendar->setFirstDayOfWeek(Qt::DayOfWeek( + firstDayCombo->itemData(index).toInt())); + } + + void Window::selectionModeChanged(int index) + { + calendar->setSelectionMode(QCalendarWidget::SelectionMode( + selectionModeCombo->itemData(index).toInt())); + } + + void Window::horizontalHeaderChanged(int index) + { + calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat( + horizontalHeaderCombo->itemData(index).toInt())); + } + + void Window::verticalHeaderChanged(int index) + { + calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat( + verticalHeaderCombo->itemData(index).toInt())); + } + + void Window::selectedDateChanged() + { + currentDateEdit->setDate(calendar->selectedDate()); + } + + void Window::minimumDateChanged(const QDate &date) + { + calendar->setMinimumDate(date); + maximumDateEdit->setDate(calendar->maximumDate()); + } + + void Window::maximumDateChanged(const QDate &date) + { + calendar->setMaximumDate(date); + minimumDateEdit->setDate(calendar->minimumDate()); + } + + void Window::weekdayFormatChanged() + { + QTextCharFormat format; + + format.setForeground(qvariant_cast( + weekdayColorCombo->itemData(weekdayColorCombo->currentIndex()))); + calendar->setWeekdayTextFormat(Qt::Monday, format); + calendar->setWeekdayTextFormat(Qt::Tuesday, format); + calendar->setWeekdayTextFormat(Qt::Wednesday, format); + calendar->setWeekdayTextFormat(Qt::Thursday, format); + calendar->setWeekdayTextFormat(Qt::Friday, format); + } + + void Window::weekendFormatChanged() + { + QTextCharFormat format; + + format.setForeground(qvariant_cast( + weekendColorCombo->itemData(weekendColorCombo->currentIndex()))); + calendar->setWeekdayTextFormat(Qt::Saturday, format); + calendar->setWeekdayTextFormat(Qt::Sunday, format); + } + + void Window::reformatHeaders() + { + QString text = headerTextFormatCombo->currentText(); + QTextCharFormat format; + + if (text == tr("Bold")) { + format.setFontWeight(QFont::Bold); + } else if (text == tr("Italic")) { + format.setFontItalic(true); + } else if (text == tr("Green")) { + format.setForeground(Qt::green); + } + calendar->setHeaderTextFormat(format); + } + + void Window::reformatCalendarPage() + { + if (firstFridayCheckBox->isChecked()) { + QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1); + while (firstFriday.dayOfWeek() != Qt::Friday) + firstFriday = firstFriday.addDays(1); + QTextCharFormat firstFridayFormat; + firstFridayFormat.setForeground(Qt::blue); + calendar->setDateTextFormat(firstFriday, firstFridayFormat); + } + + //May First in Red takes precedence + if (mayFirstCheckBox->isChecked()) { + const QDate mayFirst(calendar->yearShown(), 5, 1); + QTextCharFormat mayFirstFormat; + mayFirstFormat.setForeground(Qt::red); + calendar->setDateTextFormat(mayFirst, mayFirstFormat); + } + } + + void Window::createPreviewGroupBox() + { + previewGroupBox = new QGroupBox(tr("Preview")); + + calendar = new QCalendarWidget; + calendar->setMinimumDate(QDate(1900, 1, 1)); + calendar->setMaximumDate(QDate(3000, 1, 1)); + calendar->setGridVisible(true); + + connect(calendar, SIGNAL(currentPageChanged(int,int)), + this, SLOT(reformatCalendarPage())); + + previewLayout = new QGridLayout; + previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter); + previewGroupBox->setLayout(previewLayout); + } + + void Window::createGeneralOptionsGroupBox() + { + generalOptionsGroupBox = new QGroupBox(tr("General Options")); + + localeCombo = new QComboBox; + int curLocaleIndex = -1; + int index = 0; + for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { + QLocale::Language lang = static_cast(_lang); + QList countries = QLocale::countriesForLanguage(lang); + for (int i = 0; i < countries.count(); ++i) { + QLocale::Country country = countries.at(i); + QString label = QLocale::languageToString(lang); + label += QLatin1Char('/'); + label += QLocale::countryToString(country); + QLocale locale(lang, country); + if (this->locale().language() == lang && this->locale().country() == country) + curLocaleIndex = index; + localeCombo->addItem(label, locale); + ++index; + } + } + if (curLocaleIndex != -1) + localeCombo->setCurrentIndex(curLocaleIndex); + localeLabel = new QLabel(tr("&Locale")); + localeLabel->setBuddy(localeCombo); + + firstDayCombo = new QComboBox; + firstDayCombo->addItem(tr("Sunday"), Qt::Sunday); + firstDayCombo->addItem(tr("Monday"), Qt::Monday); + firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday); + firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday); + firstDayCombo->addItem(tr("Thursday"), Qt::Thursday); + firstDayCombo->addItem(tr("Friday"), Qt::Friday); + firstDayCombo->addItem(tr("Saturday"), Qt::Saturday); + + firstDayLabel = new QLabel(tr("Wee&k starts on:")); + firstDayLabel->setBuddy(firstDayCombo); + + selectionModeCombo = new QComboBox; + selectionModeCombo->addItem(tr("Single selection"), + QCalendarWidget::SingleSelection); + selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection); + + selectionModeLabel = new QLabel(tr("&Selection mode:")); + selectionModeLabel->setBuddy(selectionModeCombo); + + gridCheckBox = new QCheckBox(tr("&Grid")); + gridCheckBox->setChecked(calendar->isGridVisible()); + + navigationCheckBox = new QCheckBox(tr("&Navigation bar")); + navigationCheckBox->setChecked(true); + + horizontalHeaderCombo = new QComboBox; + horizontalHeaderCombo->addItem(tr("Single letter day names"), + QCalendarWidget::SingleLetterDayNames); + horizontalHeaderCombo->addItem(tr("Short day names"), + QCalendarWidget::ShortDayNames); + horizontalHeaderCombo->addItem(tr("None"), + QCalendarWidget::NoHorizontalHeader); + horizontalHeaderCombo->setCurrentIndex(1); + + horizontalHeaderLabel = new QLabel(tr("&Horizontal header:")); + horizontalHeaderLabel->setBuddy(horizontalHeaderCombo); + + verticalHeaderCombo = new QComboBox; + verticalHeaderCombo->addItem(tr("ISO week numbers"), + QCalendarWidget::ISOWeekNumbers); + verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader); + + verticalHeaderLabel = new QLabel(tr("&Vertical header:")); + verticalHeaderLabel->setBuddy(verticalHeaderCombo); + + connect(localeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(localeChanged(int))); + connect(firstDayCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(firstDayChanged(int))); + connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(selectionModeChanged(int))); + connect(gridCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setGridVisible(bool))); + connect(navigationCheckBox, SIGNAL(toggled(bool)), + calendar, SLOT(setNavigationBarVisible(bool))); + connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(horizontalHeaderChanged(int))); + connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(verticalHeaderChanged(int))); + + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(gridCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(navigationCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(localeLabel, 0, 0); + outerLayout->addWidget(localeCombo, 0, 1); + outerLayout->addWidget(firstDayLabel, 1, 0); + outerLayout->addWidget(firstDayCombo, 1, 1); + outerLayout->addWidget(selectionModeLabel, 2, 0); + outerLayout->addWidget(selectionModeCombo, 2, 1); + outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); + outerLayout->addWidget(horizontalHeaderLabel, 4, 0); + outerLayout->addWidget(horizontalHeaderCombo, 4, 1); + outerLayout->addWidget(verticalHeaderLabel, 5, 0); + outerLayout->addWidget(verticalHeaderCombo, 5, 1); + generalOptionsGroupBox->setLayout(outerLayout); + + firstDayChanged(firstDayCombo->currentIndex()); + selectionModeChanged(selectionModeCombo->currentIndex()); + horizontalHeaderChanged(horizontalHeaderCombo->currentIndex()); + verticalHeaderChanged(verticalHeaderCombo->currentIndex()); + } + + void Window::createDatesGroupBox() + { + datesGroupBox = new QGroupBox(tr("Dates")); + + minimumDateEdit = new QDateEdit; + minimumDateEdit->setDisplayFormat("MMM d yyyy"); + minimumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + minimumDateEdit->setDate(calendar->minimumDate()); + + minimumDateLabel = new QLabel(tr("&Minimum Date:")); + minimumDateLabel->setBuddy(minimumDateEdit); + + currentDateEdit = new QDateEdit; + currentDateEdit->setDisplayFormat("MMM d yyyy"); + currentDateEdit->setDate(calendar->selectedDate()); + currentDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + + currentDateLabel = new QLabel(tr("&Current Date:")); + currentDateLabel->setBuddy(currentDateEdit); + + maximumDateEdit = new QDateEdit; + maximumDateEdit->setDisplayFormat("MMM d yyyy"); + maximumDateEdit->setDateRange(calendar->minimumDate(), + calendar->maximumDate()); + maximumDateEdit->setDate(calendar->maximumDate()); + + maximumDateLabel = new QLabel(tr("Ma&ximum Date:")); + maximumDateLabel->setBuddy(maximumDateEdit); + + connect(currentDateEdit, SIGNAL(dateChanged(QDate)), + calendar, SLOT(setSelectedDate(QDate))); + connect(calendar, SIGNAL(selectionChanged()), + this, SLOT(selectedDateChanged())); + connect(minimumDateEdit, SIGNAL(dateChanged(QDate)), + this, SLOT(minimumDateChanged(QDate))); + connect(maximumDateEdit, SIGNAL(dateChanged(QDate)), + this, SLOT(maximumDateChanged(QDate))); + + QGridLayout *dateBoxLayout = new QGridLayout; + dateBoxLayout->addWidget(currentDateLabel, 1, 0); + dateBoxLayout->addWidget(currentDateEdit, 1, 1); + dateBoxLayout->addWidget(minimumDateLabel, 0, 0); + dateBoxLayout->addWidget(minimumDateEdit, 0, 1); + dateBoxLayout->addWidget(maximumDateLabel, 2, 0); + dateBoxLayout->addWidget(maximumDateEdit, 2, 1); + dateBoxLayout->setRowStretch(3, 1); + + datesGroupBox->setLayout(dateBoxLayout); + } + + void Window::createTextFormatsGroupBox() + { + textFormatsGroupBox = new QGroupBox(tr("Text Formats")); + + weekdayColorCombo = createColorComboBox(); + weekdayColorCombo->setCurrentIndex( + weekdayColorCombo->findText(tr("Black"))); + + weekdayColorLabel = new QLabel(tr("&Weekday color:")); + weekdayColorLabel->setBuddy(weekdayColorCombo); + + weekendColorCombo = createColorComboBox(); + weekendColorCombo->setCurrentIndex( + weekendColorCombo->findText(tr("Red"))); + + weekendColorLabel = new QLabel(tr("Week&end color:")); + weekendColorLabel->setBuddy(weekendColorCombo); + + headerTextFormatCombo = new QComboBox; + headerTextFormatCombo->addItem(tr("Bold")); + headerTextFormatCombo->addItem(tr("Italic")); + headerTextFormatCombo->addItem(tr("Plain")); + + headerTextFormatLabel = new QLabel(tr("&Header text:")); + headerTextFormatLabel->setBuddy(headerTextFormatCombo); + + firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue")); + + mayFirstCheckBox = new QCheckBox(tr("May &1 in red")); + + connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekdayFormatChanged())); + connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)), + this, SLOT(weekendFormatChanged())); + connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)), + this, SLOT(reformatHeaders())); + connect(firstFridayCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + connect(mayFirstCheckBox, SIGNAL(toggled(bool)), + this, SLOT(reformatCalendarPage())); + + QHBoxLayout *checkBoxLayout = new QHBoxLayout; + checkBoxLayout->addWidget(firstFridayCheckBox); + checkBoxLayout->addStretch(); + checkBoxLayout->addWidget(mayFirstCheckBox); + + QGridLayout *outerLayout = new QGridLayout; + outerLayout->addWidget(weekdayColorLabel, 0, 0); + outerLayout->addWidget(weekdayColorCombo, 0, 1); + outerLayout->addWidget(weekendColorLabel, 1, 0); + outerLayout->addWidget(weekendColorCombo, 1, 1); + outerLayout->addWidget(headerTextFormatLabel, 2, 0); + outerLayout->addWidget(headerTextFormatCombo, 2, 1); + outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); + textFormatsGroupBox->setLayout(outerLayout); + + weekdayFormatChanged(); + weekendFormatChanged(); + reformatHeaders(); + reformatCalendarPage(); + } + +QComboBox *Window::createColorComboBox() + { + QComboBox *comboBox = new QComboBox; + comboBox->addItem(tr("Red"), QColor(Qt::red)); + comboBox->addItem(tr("Blue"), QColor(Qt::blue)); + comboBox->addItem(tr("Black"), QColor(Qt::black)); + comboBox->addItem(tr("Magenta"), QColor(Qt::magenta)); + return comboBox; + } + +//#include "moc_calwidget.cpp" diff --git a/Tests/QtAutogen/calwidget.h b/Tests/QtAutogen/calwidget.h new file mode 100644 index 0000000..8447389 --- /dev/null +++ b/Tests/QtAutogen/calwidget.h @@ -0,0 +1,121 @@ + /**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the examples of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + ** the names of its contributors may be used to endorse or promote + ** products derived from this software without specific prior written + ** permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#ifndef WINDOW_H +#define WINDOW_H + +#include + + class QCalendarWidget; + class QCheckBox; + class QComboBox; + class QDate; + class QDateEdit; + class QGridLayout; + class QGroupBox; + class QLabel; + + class Window : public QWidget + { + Q_OBJECT + + public: + Window(); + + private slots: + void localeChanged(int index); + void firstDayChanged(int index); + void selectionModeChanged(int index); + void horizontalHeaderChanged(int index); + void verticalHeaderChanged(int index); + void selectedDateChanged(); + void minimumDateChanged(const QDate &date); + void maximumDateChanged(const QDate &date); + void weekdayFormatChanged(); + void weekendFormatChanged(); + void reformatHeaders(); + void reformatCalendarPage(); + + private: + void createPreviewGroupBox(); + void createGeneralOptionsGroupBox(); + void createDatesGroupBox(); + void createTextFormatsGroupBox(); + QComboBox *createColorComboBox(); + + QGroupBox *previewGroupBox; + QGridLayout *previewLayout; + QCalendarWidget *calendar; + + QGroupBox *generalOptionsGroupBox; + QLabel *localeLabel; + QLabel *firstDayLabel; + QLabel *selectionModeLabel; + QLabel *horizontalHeaderLabel; + QLabel *verticalHeaderLabel; + QComboBox *localeCombo; + QComboBox *firstDayCombo; + QComboBox *selectionModeCombo; + QCheckBox *gridCheckBox; + QCheckBox *navigationCheckBox; + QComboBox *horizontalHeaderCombo; + QComboBox *verticalHeaderCombo; + + QGroupBox *datesGroupBox; + QLabel *currentDateLabel; + QLabel *minimumDateLabel; + QLabel *maximumDateLabel; + QDateEdit *currentDateEdit; + QDateEdit *minimumDateEdit; + QDateEdit *maximumDateEdit; + + QGroupBox *textFormatsGroupBox; + QLabel *weekdayColorLabel; + QLabel *weekendColorLabel; + QLabel *headerTextFormatLabel; + QComboBox *weekdayColorCombo; + QComboBox *weekendColorCombo; + QComboBox *headerTextFormatCombo; + + QCheckBox *firstFridayCheckBox; + QCheckBox *mayFirstCheckBox; + }; + + #endif diff --git a/Tests/QtAutogen/codeeditor.cpp b/Tests/QtAutogen/codeeditor.cpp new file mode 100644 index 0000000..01da062 --- /dev/null +++ b/Tests/QtAutogen/codeeditor.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the examples of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + ** the names of its contributors may be used to endorse or promote + ** products derived from this software without specific prior written + ** permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + + #include + + #include "codeeditor.h" + + + CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) + { + lineNumberArea = new LineNumberArea(this); + + connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); + connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); + + updateLineNumberAreaWidth(0); + highlightCurrentLine(); + } + + + + int CodeEditor::lineNumberAreaWidth() + { + int digits = 1; + int max = qMax(1, blockCount()); + while (max >= 10) { + max /= 10; + ++digits; + } + + int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; + + return space; + } + + + + void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) + { + setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); + } + + + + void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) + { + if (dy) + lineNumberArea->scroll(0, dy); + else + lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); + + if (rect.contains(viewport()->rect())) + updateLineNumberAreaWidth(0); + } + + + + void CodeEditor::resizeEvent(QResizeEvent *e) + { + QPlainTextEdit::resizeEvent(e); + + QRect cr = contentsRect(); + lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); + } + + + + void CodeEditor::highlightCurrentLine() + { + QList extraSelections; + + if (!isReadOnly()) { + QTextEdit::ExtraSelection selection; + + QColor lineColor = QColor(Qt::yellow).lighter(160); + + selection.format.setBackground(lineColor); + selection.format.setProperty(QTextFormat::FullWidthSelection, true); + selection.cursor = textCursor(); + selection.cursor.clearSelection(); + extraSelections.append(selection); + } + + setExtraSelections(extraSelections); + } + + + + void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) + { + QPainter painter(lineNumberArea); + painter.fillRect(event->rect(), Qt::lightGray); + + + QTextBlock block = firstVisibleBlock(); + int blockNumber = block.blockNumber(); + int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); + int bottom = top + (int) blockBoundingRect(block).height(); + + while (block.isValid() && top <= event->rect().bottom()) { + if (block.isVisible() && bottom >= event->rect().top()) { + QString number = QString::number(blockNumber + 1); + painter.setPen(Qt::black); + painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), + Qt::AlignRight, number); + } + + block = block.next(); + top = bottom; + bottom = top + (int) blockBoundingRect(block).height(); + ++blockNumber; + } + } + +#include "codeeditor.moc" diff --git a/Tests/QtAutogen/codeeditor.h b/Tests/QtAutogen/codeeditor.h new file mode 100644 index 0000000..56e9e792 --- /dev/null +++ b/Tests/QtAutogen/codeeditor.h @@ -0,0 +1,99 @@ + /**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the examples of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + ** the names of its contributors may be used to endorse or promote + ** products derived from this software without specific prior written + ** permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + + #ifndef CODEEDITOR_H + #define CODEEDITOR_H + + #include + #include + + class QPaintEvent; + class QResizeEvent; + class QSize; + class QWidget; + + class LineNumberArea; + + + class CodeEditor : public QPlainTextEdit + { + Q_OBJECT + + public: + CodeEditor(QWidget *parent = 0); + + void lineNumberAreaPaintEvent(QPaintEvent *event); + int lineNumberAreaWidth(); + + protected: + void resizeEvent(QResizeEvent *event); + + private slots: + void updateLineNumberAreaWidth(int newBlockCount); + void highlightCurrentLine(); + void updateLineNumberArea(const QRect &, int); + + private: + QWidget *lineNumberArea; + }; + + + class LineNumberArea : public QWidget + { + public: + LineNumberArea(CodeEditor *editor) : QWidget(editor) { + codeEditor = editor; + } + + QSize sizeHint() const { + return QSize(codeEditor->lineNumberAreaWidth(), 0); + } + + protected: + void paintEvent(QPaintEvent *event) { + codeEditor->lineNumberAreaPaintEvent(event); + } + + private: + CodeEditor *codeEditor; + }; + + + #endif diff --git a/Tests/QtAutogen/defines_test/CMakeLists.txt b/Tests/QtAutogen/defines_test/CMakeLists.txt new file mode 100644 index 0000000..ad4e684 --- /dev/null +++ b/Tests/QtAutogen/defines_test/CMakeLists.txt @@ -0,0 +1,6 @@ + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(defines_test defines_test.cpp) +set_target_properties(defines_test PROPERTIES AUTOMOC TRUE) +target_link_libraries(defines_test Qt4::QtGui) diff --git a/Tests/QtAutogen/defines_test/defines_test.cpp b/Tests/QtAutogen/defines_test/defines_test.cpp new file mode 100644 index 0000000..2836d35 --- /dev/null +++ b/Tests/QtAutogen/defines_test/defines_test.cpp @@ -0,0 +1,38 @@ + +#include + +#ifdef QT_GUI_LIB +#include + +class SomeDocument : public QTextDocument +{ + Q_OBJECT + +Q_SIGNALS: + void someSig(); +}; +#endif + +#ifdef QT_CORE_LIB +class SomeObject : public QObject +{ + Q_OBJECT + +Q_SIGNALS: + void someSig(); +}; +#endif + +int main(int argc, char **argv) +{ +#ifdef QT_CORE_LIB + QMetaObject sosmo = SomeObject::staticMetaObject; +#endif +#ifdef QT_GUI_LIB + QMetaObject sdsmo = SomeDocument::staticMetaObject; +#endif + + return 0; +} + +#include "defines_test.moc" diff --git a/Tests/QtAutogen/empty.cpp b/Tests/QtAutogen/empty.cpp new file mode 100644 index 0000000..ab32cf6 --- /dev/null +++ b/Tests/QtAutogen/empty.cpp @@ -0,0 +1 @@ +// No content diff --git a/Tests/QtAutogen/empty.h b/Tests/QtAutogen/empty.h new file mode 100644 index 0000000..4566142 --- /dev/null +++ b/Tests/QtAutogen/empty.h @@ -0,0 +1,9 @@ + +#include + +class Empty : public QObject +{ + Q_OBJECT +public: + explicit Empty(QObject *parent = 0) {} +}; diff --git a/Tests/QtAutogen/foo.cpp b/Tests/QtAutogen/foo.cpp new file mode 100644 index 0000000..699ba09 --- /dev/null +++ b/Tests/QtAutogen/foo.cpp @@ -0,0 +1,39 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#include "foo.h" + +#include + +class FooFoo : public QObject +{ + Q_OBJECT + public: + FooFoo():QObject() {} + public slots: + int getValue() const { return 12; } +}; + +Foo::Foo() +:QObject() +{ +} + + +void Foo::doFoo() +{ + FooFoo ff; + printf("Hello automoc: %d\n", ff.getValue()); +} + +#include "foo.moc" diff --git a/Tests/QtAutogen/foo.h b/Tests/QtAutogen/foo.h new file mode 100644 index 0000000..32d4c8d --- /dev/null +++ b/Tests/QtAutogen/foo.h @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef FOO_H +#define FOO_H + +#include + +class Foo : public QObject +{ + Q_OBJECT + public: + Foo(); + public slots: + void doFoo(); +}; + +#endif diff --git a/Tests/QtAutogen/gadget.cpp b/Tests/QtAutogen/gadget.cpp new file mode 100644 index 0000000..23d95fa --- /dev/null +++ b/Tests/QtAutogen/gadget.cpp @@ -0,0 +1,4 @@ + +#include "gadget.h" + +#include "moc_gadget.cpp" diff --git a/Tests/QtAutogen/gadget.h b/Tests/QtAutogen/gadget.h new file mode 100644 index 0000000..7c688ee --- /dev/null +++ b/Tests/QtAutogen/gadget.h @@ -0,0 +1,18 @@ + +#ifndef GADGET_H +#define GADGET_H + +#include + +class Gadget +{ + Q_GADGET + Q_ENUMS(Type) +public: + enum Type { + Type0, + Type1 + }; +}; + +#endif diff --git a/Tests/QtAutogen/libC.cpp b/Tests/QtAutogen/libC.cpp new file mode 100644 index 0000000..8d61cb1 --- /dev/null +++ b/Tests/QtAutogen/libC.cpp @@ -0,0 +1,13 @@ + +#include "libC.h" + +LibC::LibC(QObject *parent) + : QObject(parent) +{ + +} + +int LibC::foo() +{ + return b.foo(); +} diff --git a/Tests/QtAutogen/libC.h b/Tests/QtAutogen/libC.h new file mode 100644 index 0000000..4fb4a2c --- /dev/null +++ b/Tests/QtAutogen/libC.h @@ -0,0 +1,22 @@ + +#ifndef LIBC_H +#define LIBC_H + +#include "libc_export.h" + +#include +#include "libB.h" + +class LIBC_EXPORT LibC : public QObject +{ + Q_OBJECT +public: + explicit LibC(QObject *parent = 0); + + + int foo(); +private: + LibB b; +}; + +#endif diff --git a/Tests/QtAutogen/main.cpp b/Tests/QtAutogen/main.cpp new file mode 100644 index 0000000..bd80180 --- /dev/null +++ b/Tests/QtAutogen/main.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** + ** + ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the examples of the Qt Toolkit. + ** + ** $QT_BEGIN_LICENSE:BSD$ + ** You may use this file under the terms of the BSD license as follows: + ** + ** "Redistribution and use in source and binary forms, with or without + ** modification, are permitted provided that the following conditions are + ** met: + ** * Redistributions of source code must retain the above copyright + ** notice, this list of conditions and the following disclaimer. + ** * Redistributions in binary form must reproduce the above copyright + ** notice, this list of conditions and the following disclaimer in + ** the documentation and/or other materials provided with the + ** distribution. + ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + ** the names of its contributors may be used to endorse or promote + ** products derived from this software without specific prior written + ** permission. + ** + ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ + +#include + +#include "codeeditor.h" +#include "calwidget.h" +#include "foo.h" +#include "blub.h" +#include "sub/bar.h" +#include "abc.h" +#include "xyz.h" +#include "yaf.h" +#include "libC.h" + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + CodeEditor editor; + editor.setWindowTitle(QObject::tr("Code Editor Example")); + editor.show(); + + Window w; + w.show(); + + Foo foo; + foo.doFoo(); + + Blub b; + b.blubber(); + + Bar bar; + bar.doBar(); + + Abc abc; + abc.doAbc(); + + Xyz xyz; + xyz.doXyz(); + + Yaf yaf; + yaf.doYaf(); + + LibC lc; + lc.foo(); + + return app.exec(); +} diff --git a/Tests/QtAutogen/private_slot.cpp b/Tests/QtAutogen/private_slot.cpp new file mode 100644 index 0000000..1387a70 --- /dev/null +++ b/Tests/QtAutogen/private_slot.cpp @@ -0,0 +1,21 @@ + +#include "private_slot.h" + +class PrivateSlotPrivate +{ +public: + + void privateSlot() + { + + } +}; + +PrivateSlot::PrivateSlot(QObject *parent) + : QObject(parent), + d(new PrivateSlotPrivate) +{ + +} + +#include "private_slot.moc" diff --git a/Tests/QtAutogen/private_slot.h b/Tests/QtAutogen/private_slot.h new file mode 100644 index 0000000..28e5448 --- /dev/null +++ b/Tests/QtAutogen/private_slot.h @@ -0,0 +1,20 @@ + +#ifndef PRIVATE_SLOT_H +#define PRIVATE_SLOT_H + +#include + +class PrivateSlotPrivate; + +class PrivateSlot : public QObject +{ + Q_OBJECT +public: + PrivateSlot(QObject *parent = 0); + +private: + PrivateSlotPrivate * const d; + Q_PRIVATE_SLOT(d, void privateSlot()) +}; + +#endif diff --git a/Tests/QtAutogen/sub/bar.h b/Tests/QtAutogen/sub/bar.h new file mode 100644 index 0000000..db56b8e --- /dev/null +++ b/Tests/QtAutogen/sub/bar.h @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef BAR_H +#define BAR_H + +#include + +class Bar : public QObject +{ + Q_OBJECT + public: + Bar(); + public slots: + void doBar(); +}; + +#endif diff --git a/Tests/QtAutogen/xyz.cpp b/Tests/QtAutogen/xyz.cpp new file mode 100644 index 0000000..a3562a3 --- /dev/null +++ b/Tests/QtAutogen/xyz.cpp @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + + +#include "xyz.h" + +#include + +Xyz::Xyz() +:QObject() +{ +} + + +void Xyz::doXyz() +{ + printf("This is xyz !\n"); +} diff --git a/Tests/QtAutogen/xyz.h b/Tests/QtAutogen/xyz.h new file mode 100644 index 0000000..8175d37 --- /dev/null +++ b/Tests/QtAutogen/xyz.h @@ -0,0 +1,28 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef XYZ_H +#define XYZ_H + +#include + +class Xyz : public QObject +{ + Q_OBJECT + public: + Xyz(); + public slots: + void doXyz(); +}; + +#endif diff --git a/Tests/QtAutogen/yaf.cpp b/Tests/QtAutogen/yaf.cpp new file mode 100644 index 0000000..d278ab4 --- /dev/null +++ b/Tests/QtAutogen/yaf.cpp @@ -0,0 +1,32 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + + +#include "yaf.h" +#include "yaf_p.h" + +#include + +Yaf::Yaf() +{ +} + + +void Yaf::doYaf() +{ + YafP yafP; + yafP.doYafP(); +} + +// check that including a moc file from a private header the wrong way works: +#include "yaf_p.moc" diff --git a/Tests/QtAutogen/yaf.h b/Tests/QtAutogen/yaf.h new file mode 100644 index 0000000..8689f83 --- /dev/null +++ b/Tests/QtAutogen/yaf.h @@ -0,0 +1,25 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef YAF_H +#define YAF_H + +class Yaf +{ + public: + Yaf(); + public: + void doYaf(); +}; + +#endif diff --git a/Tests/QtAutogen/yaf_p.h b/Tests/QtAutogen/yaf_p.h new file mode 100644 index 0000000..f0368ad --- /dev/null +++ b/Tests/QtAutogen/yaf_p.h @@ -0,0 +1,30 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2004-2011 Kitware, Inc. + Copyright 2011 Alexander Neundorf (neundorf@kde.org) + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ + +#ifndef YAF_P_H +#define YAF_P_H + +#include + +#include + +class YafP : public QObject +{ + Q_OBJECT + public: + YafP() {} + public slots: + void doYafP() { printf("I am yet another file !\n"); } +}; + +#endif diff --git a/Tests/QtAutomoc/Adir/CMakeLists.txt b/Tests/QtAutomoc/Adir/CMakeLists.txt deleted file mode 100644 index a1c36ff..0000000 --- a/Tests/QtAutomoc/Adir/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) - -add_library(libA SHARED libA.cpp) -target_link_libraries(libA LINK_PUBLIC ${QT_QTCORE_TARGET}) -generate_export_header(libA) diff --git a/Tests/QtAutomoc/Adir/libA.cpp b/Tests/QtAutomoc/Adir/libA.cpp deleted file mode 100644 index 3968c44..0000000 --- a/Tests/QtAutomoc/Adir/libA.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include "libA.h" - -LibA::LibA(QObject *parent) - : QObject(parent) -{ - -} - -int LibA::foo() -{ - return 0; -} diff --git a/Tests/QtAutomoc/Adir/libA.h b/Tests/QtAutomoc/Adir/libA.h deleted file mode 100644 index 03ad1e0..0000000 --- a/Tests/QtAutomoc/Adir/libA.h +++ /dev/null @@ -1,18 +0,0 @@ - -#ifndef LIBA_H -#define LIBA_H - -#include "liba_export.h" - -#include - -class LIBA_EXPORT LibA : public QObject -{ - Q_OBJECT -public: - explicit LibA(QObject *parent = 0); - - int foo(); -}; - -#endif diff --git a/Tests/QtAutomoc/Bdir/CMakeLists.txt b/Tests/QtAutomoc/Bdir/CMakeLists.txt deleted file mode 100644 index d9d4aa7..0000000 --- a/Tests/QtAutomoc/Bdir/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ - -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) - -add_library(libB SHARED libB.cpp) -generate_export_header(libB) - -# set_property(TARGET libB APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) -target_link_libraries(libB LINK_PUBLIC libA) diff --git a/Tests/QtAutomoc/Bdir/libB.cpp b/Tests/QtAutomoc/Bdir/libB.cpp deleted file mode 100644 index 72f2cfa..0000000 --- a/Tests/QtAutomoc/Bdir/libB.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include "libB.h" - -LibB::LibB(QObject *parent) - : QObject(parent) -{ - -} - -int LibB::foo() -{ - return a.foo(); -} diff --git a/Tests/QtAutomoc/Bdir/libB.h b/Tests/QtAutomoc/Bdir/libB.h deleted file mode 100644 index 510c17f..0000000 --- a/Tests/QtAutomoc/Bdir/libB.h +++ /dev/null @@ -1,21 +0,0 @@ - -#ifndef LIBB_H -#define LIBB_H - -#include "libb_export.h" - -#include -#include "libA.h" - -class LIBB_EXPORT LibB : public QObject -{ - Q_OBJECT -public: - explicit LibB(QObject *parent = 0); - - int foo(); -private: - LibA a; -}; - -#endif diff --git a/Tests/QtAutomoc/CMakeLists.txt b/Tests/QtAutomoc/CMakeLists.txt deleted file mode 100644 index 8ad693a..0000000 --- a/Tests/QtAutomoc/CMakeLists.txt +++ /dev/null @@ -1,68 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -project(QtAutomoc) - -if (QT_TEST_VERSION STREQUAL 4) - find_package(Qt4 REQUIRED) - - # Include this directory before using the UseQt4 file. - add_subdirectory(defines_test) - - include(UseQt4) - - set(QT_QTCORE_TARGET Qt4::QtCore) -else() - if (NOT QT_TEST_VERSION STREQUAL 5) - message(SEND_ERROR "Invalid Qt version specified.") - endif() - find_package(Qt5Widgets REQUIRED) - - set(QT_QTCORE_TARGET Qt5::Core) - - include_directories(${Qt5Widgets_INCLUDE_DIRS}) - set(QT_LIBRARIES Qt5::Widgets) - - if(Qt5_POSITION_INDEPENDENT_CODE) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - endif() -endif() - - -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -add_definitions(-DFOO -DSomeDefine="Barx") - -# enable relaxed mode so automoc can handle all the special cases: -set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) - -# create an executable and two library targets, each requiring automoc: -add_library(codeeditorLib STATIC codeeditor.cpp) - -add_library(privateSlot OBJECT private_slot.cpp) - -add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp - xyz.cpp yaf.cpp gadget.cpp $) - -set_target_properties(foo codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) - -include(GenerateExportHeader) -# The order is relevant here. B depends on A, and B headers depend on A -# headers both subdirectories use CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE and we -# test that CMAKE_AUTOMOC successfully reads the include directories -# for the build interface from those targets. There has previously been -# a bug where caching of the include directories happened before -# extracting the includes to pass to moc. -add_subdirectory(Bdir) -add_subdirectory(Adir) -add_library(libC SHARED libC.cpp) -set_target_properties(libC PROPERTIES AUTOMOC TRUE) -generate_export_header(libC) -target_link_libraries(libC LINK_PUBLIC libB) - -target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} libC) - -add_library(empty STATIC empty.cpp) -set_target_properties(empty PROPERTIES AUTOMOC TRUE) -target_link_libraries(empty no_link_language) -add_library(no_link_language STATIC empty.h) -set_target_properties(no_link_language PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutomoc/abc.cpp b/Tests/QtAutomoc/abc.cpp deleted file mode 100644 index 4bbc769..0000000 --- a/Tests/QtAutomoc/abc.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - - -#include "abc.h" -#include "abc_p.h" - -#include - -class PrintAbc : public QObject -{ - Q_OBJECT - public: - PrintAbc():QObject() {} - public slots: - void print() const { printf("abc\n"); } -}; - -Abc::Abc() -:QObject() -{ -} - - -void Abc::doAbc() -{ - PrintAbc pa; - pa.print(); - AbcP abcP; - abcP.doAbcP(); -} - -// check that including the moc file for the cpp file and the header works: -#include "abc.moc" -#include "moc_abc.cpp" -#include "moc_abc_p.cpp" - -// check that including a moc file from another header works: -#include "moc_xyz.cpp" diff --git a/Tests/QtAutomoc/abc.h b/Tests/QtAutomoc/abc.h deleted file mode 100644 index d1924b0..0000000 --- a/Tests/QtAutomoc/abc.h +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef ABC_H -#define ABC_H - -#include - -class Abc : public QObject -{ - Q_OBJECT - public: - Abc(); - public slots: - void doAbc(); -}; - -#endif diff --git a/Tests/QtAutomoc/abc_p.h b/Tests/QtAutomoc/abc_p.h deleted file mode 100644 index 952fff3..0000000 --- a/Tests/QtAutomoc/abc_p.h +++ /dev/null @@ -1,30 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef ABC_P_H -#define ABC_P_H - -#include - -#include - -class AbcP : public QObject -{ - Q_OBJECT - public: - AbcP() {} - public slots: - void doAbcP() { printf("I am private abc !\n"); } -}; - -#endif diff --git a/Tests/QtAutomoc/bar.cpp b/Tests/QtAutomoc/bar.cpp deleted file mode 100644 index 8be4815..0000000 --- a/Tests/QtAutomoc/bar.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#include "sub/bar.h" - -#include - -Bar::Bar() -:QObject() -{ -} - -void Bar::doBar() -{ - printf("Hello bar !\n"); -} - -#include "sub/moc_bar.cpp" diff --git a/Tests/QtAutomoc/blub.cpp b/Tests/QtAutomoc/blub.cpp deleted file mode 100644 index bd53972..0000000 --- a/Tests/QtAutomoc/blub.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#include "blub.h" - -#include - -class BlubBlub : public QObject -{ - Q_OBJECT - public: - BlubBlub():QObject() {} - public slots: - int getValue() const { return 13; } -}; - -Blub::Blub() -{ -} - - -void Blub::blubber() -{ - BlubBlub bb; - printf("Blub blub %d ! \n", bb.getValue()); -} - -// test the case that the wrong moc-file is included, it should -// actually be "blub.moc" -#include "moc_blub.cpp" diff --git a/Tests/QtAutomoc/blub.h b/Tests/QtAutomoc/blub.h deleted file mode 100644 index 1967bc1..0000000 --- a/Tests/QtAutomoc/blub.h +++ /dev/null @@ -1,26 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef BLUB_H -#define BLUB_H - -#include - -class Blub -{ - public: - Blub(); - void blubber(); -}; - -#endif diff --git a/Tests/QtAutomoc/calwidget.cpp b/Tests/QtAutomoc/calwidget.cpp deleted file mode 100644 index cbfa5a8..0000000 --- a/Tests/QtAutomoc/calwidget.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor - ** the names of its contributors may be used to endorse or promote - ** products derived from this software without specific prior written - ** permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - - #include - #include - #include - #include - #include - #include - #include - #include - - #include "calwidget.h" - - Window::Window() - { - createPreviewGroupBox(); - createGeneralOptionsGroupBox(); - createDatesGroupBox(); - createTextFormatsGroupBox(); - - QGridLayout *layout = new QGridLayout; - layout->addWidget(previewGroupBox, 0, 0); - layout->addWidget(generalOptionsGroupBox, 0, 1); - layout->addWidget(datesGroupBox, 1, 0); - layout->addWidget(textFormatsGroupBox, 1, 1); - layout->setSizeConstraint(QLayout::SetFixedSize); - setLayout(layout); - - previewLayout->setRowMinimumHeight(0, calendar->sizeHint().height()); - previewLayout->setColumnMinimumWidth(0, calendar->sizeHint().width()); - - setWindowTitle(tr("Calendar Widget")); - } - - void Window::localeChanged(int index) - { - calendar->setLocale(localeCombo->itemData(index).toLocale()); - } - - void Window::firstDayChanged(int index) - { - calendar->setFirstDayOfWeek(Qt::DayOfWeek( - firstDayCombo->itemData(index).toInt())); - } - - void Window::selectionModeChanged(int index) - { - calendar->setSelectionMode(QCalendarWidget::SelectionMode( - selectionModeCombo->itemData(index).toInt())); - } - - void Window::horizontalHeaderChanged(int index) - { - calendar->setHorizontalHeaderFormat(QCalendarWidget::HorizontalHeaderFormat( - horizontalHeaderCombo->itemData(index).toInt())); - } - - void Window::verticalHeaderChanged(int index) - { - calendar->setVerticalHeaderFormat(QCalendarWidget::VerticalHeaderFormat( - verticalHeaderCombo->itemData(index).toInt())); - } - - void Window::selectedDateChanged() - { - currentDateEdit->setDate(calendar->selectedDate()); - } - - void Window::minimumDateChanged(const QDate &date) - { - calendar->setMinimumDate(date); - maximumDateEdit->setDate(calendar->maximumDate()); - } - - void Window::maximumDateChanged(const QDate &date) - { - calendar->setMaximumDate(date); - minimumDateEdit->setDate(calendar->minimumDate()); - } - - void Window::weekdayFormatChanged() - { - QTextCharFormat format; - - format.setForeground(qvariant_cast( - weekdayColorCombo->itemData(weekdayColorCombo->currentIndex()))); - calendar->setWeekdayTextFormat(Qt::Monday, format); - calendar->setWeekdayTextFormat(Qt::Tuesday, format); - calendar->setWeekdayTextFormat(Qt::Wednesday, format); - calendar->setWeekdayTextFormat(Qt::Thursday, format); - calendar->setWeekdayTextFormat(Qt::Friday, format); - } - - void Window::weekendFormatChanged() - { - QTextCharFormat format; - - format.setForeground(qvariant_cast( - weekendColorCombo->itemData(weekendColorCombo->currentIndex()))); - calendar->setWeekdayTextFormat(Qt::Saturday, format); - calendar->setWeekdayTextFormat(Qt::Sunday, format); - } - - void Window::reformatHeaders() - { - QString text = headerTextFormatCombo->currentText(); - QTextCharFormat format; - - if (text == tr("Bold")) { - format.setFontWeight(QFont::Bold); - } else if (text == tr("Italic")) { - format.setFontItalic(true); - } else if (text == tr("Green")) { - format.setForeground(Qt::green); - } - calendar->setHeaderTextFormat(format); - } - - void Window::reformatCalendarPage() - { - if (firstFridayCheckBox->isChecked()) { - QDate firstFriday(calendar->yearShown(), calendar->monthShown(), 1); - while (firstFriday.dayOfWeek() != Qt::Friday) - firstFriday = firstFriday.addDays(1); - QTextCharFormat firstFridayFormat; - firstFridayFormat.setForeground(Qt::blue); - calendar->setDateTextFormat(firstFriday, firstFridayFormat); - } - - //May First in Red takes precedence - if (mayFirstCheckBox->isChecked()) { - const QDate mayFirst(calendar->yearShown(), 5, 1); - QTextCharFormat mayFirstFormat; - mayFirstFormat.setForeground(Qt::red); - calendar->setDateTextFormat(mayFirst, mayFirstFormat); - } - } - - void Window::createPreviewGroupBox() - { - previewGroupBox = new QGroupBox(tr("Preview")); - - calendar = new QCalendarWidget; - calendar->setMinimumDate(QDate(1900, 1, 1)); - calendar->setMaximumDate(QDate(3000, 1, 1)); - calendar->setGridVisible(true); - - connect(calendar, SIGNAL(currentPageChanged(int,int)), - this, SLOT(reformatCalendarPage())); - - previewLayout = new QGridLayout; - previewLayout->addWidget(calendar, 0, 0, Qt::AlignCenter); - previewGroupBox->setLayout(previewLayout); - } - - void Window::createGeneralOptionsGroupBox() - { - generalOptionsGroupBox = new QGroupBox(tr("General Options")); - - localeCombo = new QComboBox; - int curLocaleIndex = -1; - int index = 0; - for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) { - QLocale::Language lang = static_cast(_lang); - QList countries = QLocale::countriesForLanguage(lang); - for (int i = 0; i < countries.count(); ++i) { - QLocale::Country country = countries.at(i); - QString label = QLocale::languageToString(lang); - label += QLatin1Char('/'); - label += QLocale::countryToString(country); - QLocale locale(lang, country); - if (this->locale().language() == lang && this->locale().country() == country) - curLocaleIndex = index; - localeCombo->addItem(label, locale); - ++index; - } - } - if (curLocaleIndex != -1) - localeCombo->setCurrentIndex(curLocaleIndex); - localeLabel = new QLabel(tr("&Locale")); - localeLabel->setBuddy(localeCombo); - - firstDayCombo = new QComboBox; - firstDayCombo->addItem(tr("Sunday"), Qt::Sunday); - firstDayCombo->addItem(tr("Monday"), Qt::Monday); - firstDayCombo->addItem(tr("Tuesday"), Qt::Tuesday); - firstDayCombo->addItem(tr("Wednesday"), Qt::Wednesday); - firstDayCombo->addItem(tr("Thursday"), Qt::Thursday); - firstDayCombo->addItem(tr("Friday"), Qt::Friday); - firstDayCombo->addItem(tr("Saturday"), Qt::Saturday); - - firstDayLabel = new QLabel(tr("Wee&k starts on:")); - firstDayLabel->setBuddy(firstDayCombo); - - selectionModeCombo = new QComboBox; - selectionModeCombo->addItem(tr("Single selection"), - QCalendarWidget::SingleSelection); - selectionModeCombo->addItem(tr("None"), QCalendarWidget::NoSelection); - - selectionModeLabel = new QLabel(tr("&Selection mode:")); - selectionModeLabel->setBuddy(selectionModeCombo); - - gridCheckBox = new QCheckBox(tr("&Grid")); - gridCheckBox->setChecked(calendar->isGridVisible()); - - navigationCheckBox = new QCheckBox(tr("&Navigation bar")); - navigationCheckBox->setChecked(true); - - horizontalHeaderCombo = new QComboBox; - horizontalHeaderCombo->addItem(tr("Single letter day names"), - QCalendarWidget::SingleLetterDayNames); - horizontalHeaderCombo->addItem(tr("Short day names"), - QCalendarWidget::ShortDayNames); - horizontalHeaderCombo->addItem(tr("None"), - QCalendarWidget::NoHorizontalHeader); - horizontalHeaderCombo->setCurrentIndex(1); - - horizontalHeaderLabel = new QLabel(tr("&Horizontal header:")); - horizontalHeaderLabel->setBuddy(horizontalHeaderCombo); - - verticalHeaderCombo = new QComboBox; - verticalHeaderCombo->addItem(tr("ISO week numbers"), - QCalendarWidget::ISOWeekNumbers); - verticalHeaderCombo->addItem(tr("None"), QCalendarWidget::NoVerticalHeader); - - verticalHeaderLabel = new QLabel(tr("&Vertical header:")); - verticalHeaderLabel->setBuddy(verticalHeaderCombo); - - connect(localeCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(localeChanged(int))); - connect(firstDayCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(firstDayChanged(int))); - connect(selectionModeCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(selectionModeChanged(int))); - connect(gridCheckBox, SIGNAL(toggled(bool)), - calendar, SLOT(setGridVisible(bool))); - connect(navigationCheckBox, SIGNAL(toggled(bool)), - calendar, SLOT(setNavigationBarVisible(bool))); - connect(horizontalHeaderCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(horizontalHeaderChanged(int))); - connect(verticalHeaderCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(verticalHeaderChanged(int))); - - QHBoxLayout *checkBoxLayout = new QHBoxLayout; - checkBoxLayout->addWidget(gridCheckBox); - checkBoxLayout->addStretch(); - checkBoxLayout->addWidget(navigationCheckBox); - - QGridLayout *outerLayout = new QGridLayout; - outerLayout->addWidget(localeLabel, 0, 0); - outerLayout->addWidget(localeCombo, 0, 1); - outerLayout->addWidget(firstDayLabel, 1, 0); - outerLayout->addWidget(firstDayCombo, 1, 1); - outerLayout->addWidget(selectionModeLabel, 2, 0); - outerLayout->addWidget(selectionModeCombo, 2, 1); - outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); - outerLayout->addWidget(horizontalHeaderLabel, 4, 0); - outerLayout->addWidget(horizontalHeaderCombo, 4, 1); - outerLayout->addWidget(verticalHeaderLabel, 5, 0); - outerLayout->addWidget(verticalHeaderCombo, 5, 1); - generalOptionsGroupBox->setLayout(outerLayout); - - firstDayChanged(firstDayCombo->currentIndex()); - selectionModeChanged(selectionModeCombo->currentIndex()); - horizontalHeaderChanged(horizontalHeaderCombo->currentIndex()); - verticalHeaderChanged(verticalHeaderCombo->currentIndex()); - } - - void Window::createDatesGroupBox() - { - datesGroupBox = new QGroupBox(tr("Dates")); - - minimumDateEdit = new QDateEdit; - minimumDateEdit->setDisplayFormat("MMM d yyyy"); - minimumDateEdit->setDateRange(calendar->minimumDate(), - calendar->maximumDate()); - minimumDateEdit->setDate(calendar->minimumDate()); - - minimumDateLabel = new QLabel(tr("&Minimum Date:")); - minimumDateLabel->setBuddy(minimumDateEdit); - - currentDateEdit = new QDateEdit; - currentDateEdit->setDisplayFormat("MMM d yyyy"); - currentDateEdit->setDate(calendar->selectedDate()); - currentDateEdit->setDateRange(calendar->minimumDate(), - calendar->maximumDate()); - - currentDateLabel = new QLabel(tr("&Current Date:")); - currentDateLabel->setBuddy(currentDateEdit); - - maximumDateEdit = new QDateEdit; - maximumDateEdit->setDisplayFormat("MMM d yyyy"); - maximumDateEdit->setDateRange(calendar->minimumDate(), - calendar->maximumDate()); - maximumDateEdit->setDate(calendar->maximumDate()); - - maximumDateLabel = new QLabel(tr("Ma&ximum Date:")); - maximumDateLabel->setBuddy(maximumDateEdit); - - connect(currentDateEdit, SIGNAL(dateChanged(QDate)), - calendar, SLOT(setSelectedDate(QDate))); - connect(calendar, SIGNAL(selectionChanged()), - this, SLOT(selectedDateChanged())); - connect(minimumDateEdit, SIGNAL(dateChanged(QDate)), - this, SLOT(minimumDateChanged(QDate))); - connect(maximumDateEdit, SIGNAL(dateChanged(QDate)), - this, SLOT(maximumDateChanged(QDate))); - - QGridLayout *dateBoxLayout = new QGridLayout; - dateBoxLayout->addWidget(currentDateLabel, 1, 0); - dateBoxLayout->addWidget(currentDateEdit, 1, 1); - dateBoxLayout->addWidget(minimumDateLabel, 0, 0); - dateBoxLayout->addWidget(minimumDateEdit, 0, 1); - dateBoxLayout->addWidget(maximumDateLabel, 2, 0); - dateBoxLayout->addWidget(maximumDateEdit, 2, 1); - dateBoxLayout->setRowStretch(3, 1); - - datesGroupBox->setLayout(dateBoxLayout); - } - - void Window::createTextFormatsGroupBox() - { - textFormatsGroupBox = new QGroupBox(tr("Text Formats")); - - weekdayColorCombo = createColorComboBox(); - weekdayColorCombo->setCurrentIndex( - weekdayColorCombo->findText(tr("Black"))); - - weekdayColorLabel = new QLabel(tr("&Weekday color:")); - weekdayColorLabel->setBuddy(weekdayColorCombo); - - weekendColorCombo = createColorComboBox(); - weekendColorCombo->setCurrentIndex( - weekendColorCombo->findText(tr("Red"))); - - weekendColorLabel = new QLabel(tr("Week&end color:")); - weekendColorLabel->setBuddy(weekendColorCombo); - - headerTextFormatCombo = new QComboBox; - headerTextFormatCombo->addItem(tr("Bold")); - headerTextFormatCombo->addItem(tr("Italic")); - headerTextFormatCombo->addItem(tr("Plain")); - - headerTextFormatLabel = new QLabel(tr("&Header text:")); - headerTextFormatLabel->setBuddy(headerTextFormatCombo); - - firstFridayCheckBox = new QCheckBox(tr("&First Friday in blue")); - - mayFirstCheckBox = new QCheckBox(tr("May &1 in red")); - - connect(weekdayColorCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(weekdayFormatChanged())); - connect(weekendColorCombo, SIGNAL(currentIndexChanged(int)), - this, SLOT(weekendFormatChanged())); - connect(headerTextFormatCombo, SIGNAL(currentIndexChanged(QString)), - this, SLOT(reformatHeaders())); - connect(firstFridayCheckBox, SIGNAL(toggled(bool)), - this, SLOT(reformatCalendarPage())); - connect(mayFirstCheckBox, SIGNAL(toggled(bool)), - this, SLOT(reformatCalendarPage())); - - QHBoxLayout *checkBoxLayout = new QHBoxLayout; - checkBoxLayout->addWidget(firstFridayCheckBox); - checkBoxLayout->addStretch(); - checkBoxLayout->addWidget(mayFirstCheckBox); - - QGridLayout *outerLayout = new QGridLayout; - outerLayout->addWidget(weekdayColorLabel, 0, 0); - outerLayout->addWidget(weekdayColorCombo, 0, 1); - outerLayout->addWidget(weekendColorLabel, 1, 0); - outerLayout->addWidget(weekendColorCombo, 1, 1); - outerLayout->addWidget(headerTextFormatLabel, 2, 0); - outerLayout->addWidget(headerTextFormatCombo, 2, 1); - outerLayout->addLayout(checkBoxLayout, 3, 0, 1, 2); - textFormatsGroupBox->setLayout(outerLayout); - - weekdayFormatChanged(); - weekendFormatChanged(); - reformatHeaders(); - reformatCalendarPage(); - } - -QComboBox *Window::createColorComboBox() - { - QComboBox *comboBox = new QComboBox; - comboBox->addItem(tr("Red"), QColor(Qt::red)); - comboBox->addItem(tr("Blue"), QColor(Qt::blue)); - comboBox->addItem(tr("Black"), QColor(Qt::black)); - comboBox->addItem(tr("Magenta"), QColor(Qt::magenta)); - return comboBox; - } - -//#include "moc_calwidget.cpp" diff --git a/Tests/QtAutomoc/calwidget.h b/Tests/QtAutomoc/calwidget.h deleted file mode 100644 index 8447389..0000000 --- a/Tests/QtAutomoc/calwidget.h +++ /dev/null @@ -1,121 +0,0 @@ - /**************************************************************************** - ** - ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor - ** the names of its contributors may be used to endorse or promote - ** products derived from this software without specific prior written - ** permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - -#ifndef WINDOW_H -#define WINDOW_H - -#include - - class QCalendarWidget; - class QCheckBox; - class QComboBox; - class QDate; - class QDateEdit; - class QGridLayout; - class QGroupBox; - class QLabel; - - class Window : public QWidget - { - Q_OBJECT - - public: - Window(); - - private slots: - void localeChanged(int index); - void firstDayChanged(int index); - void selectionModeChanged(int index); - void horizontalHeaderChanged(int index); - void verticalHeaderChanged(int index); - void selectedDateChanged(); - void minimumDateChanged(const QDate &date); - void maximumDateChanged(const QDate &date); - void weekdayFormatChanged(); - void weekendFormatChanged(); - void reformatHeaders(); - void reformatCalendarPage(); - - private: - void createPreviewGroupBox(); - void createGeneralOptionsGroupBox(); - void createDatesGroupBox(); - void createTextFormatsGroupBox(); - QComboBox *createColorComboBox(); - - QGroupBox *previewGroupBox; - QGridLayout *previewLayout; - QCalendarWidget *calendar; - - QGroupBox *generalOptionsGroupBox; - QLabel *localeLabel; - QLabel *firstDayLabel; - QLabel *selectionModeLabel; - QLabel *horizontalHeaderLabel; - QLabel *verticalHeaderLabel; - QComboBox *localeCombo; - QComboBox *firstDayCombo; - QComboBox *selectionModeCombo; - QCheckBox *gridCheckBox; - QCheckBox *navigationCheckBox; - QComboBox *horizontalHeaderCombo; - QComboBox *verticalHeaderCombo; - - QGroupBox *datesGroupBox; - QLabel *currentDateLabel; - QLabel *minimumDateLabel; - QLabel *maximumDateLabel; - QDateEdit *currentDateEdit; - QDateEdit *minimumDateEdit; - QDateEdit *maximumDateEdit; - - QGroupBox *textFormatsGroupBox; - QLabel *weekdayColorLabel; - QLabel *weekendColorLabel; - QLabel *headerTextFormatLabel; - QComboBox *weekdayColorCombo; - QComboBox *weekendColorCombo; - QComboBox *headerTextFormatCombo; - - QCheckBox *firstFridayCheckBox; - QCheckBox *mayFirstCheckBox; - }; - - #endif diff --git a/Tests/QtAutomoc/codeeditor.cpp b/Tests/QtAutomoc/codeeditor.cpp deleted file mode 100644 index 01da062..0000000 --- a/Tests/QtAutomoc/codeeditor.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor - ** the names of its contributors may be used to endorse or promote - ** products derived from this software without specific prior written - ** permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - - #include - - #include "codeeditor.h" - - - CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) - { - lineNumberArea = new LineNumberArea(this); - - connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); - connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); - connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); - - updateLineNumberAreaWidth(0); - highlightCurrentLine(); - } - - - - int CodeEditor::lineNumberAreaWidth() - { - int digits = 1; - int max = qMax(1, blockCount()); - while (max >= 10) { - max /= 10; - ++digits; - } - - int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; - - return space; - } - - - - void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) - { - setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); - } - - - - void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) - { - if (dy) - lineNumberArea->scroll(0, dy); - else - lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); - - if (rect.contains(viewport()->rect())) - updateLineNumberAreaWidth(0); - } - - - - void CodeEditor::resizeEvent(QResizeEvent *e) - { - QPlainTextEdit::resizeEvent(e); - - QRect cr = contentsRect(); - lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); - } - - - - void CodeEditor::highlightCurrentLine() - { - QList extraSelections; - - if (!isReadOnly()) { - QTextEdit::ExtraSelection selection; - - QColor lineColor = QColor(Qt::yellow).lighter(160); - - selection.format.setBackground(lineColor); - selection.format.setProperty(QTextFormat::FullWidthSelection, true); - selection.cursor = textCursor(); - selection.cursor.clearSelection(); - extraSelections.append(selection); - } - - setExtraSelections(extraSelections); - } - - - - void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) - { - QPainter painter(lineNumberArea); - painter.fillRect(event->rect(), Qt::lightGray); - - - QTextBlock block = firstVisibleBlock(); - int blockNumber = block.blockNumber(); - int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); - int bottom = top + (int) blockBoundingRect(block).height(); - - while (block.isValid() && top <= event->rect().bottom()) { - if (block.isVisible() && bottom >= event->rect().top()) { - QString number = QString::number(blockNumber + 1); - painter.setPen(Qt::black); - painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), - Qt::AlignRight, number); - } - - block = block.next(); - top = bottom; - bottom = top + (int) blockBoundingRect(block).height(); - ++blockNumber; - } - } - -#include "codeeditor.moc" diff --git a/Tests/QtAutomoc/codeeditor.h b/Tests/QtAutomoc/codeeditor.h deleted file mode 100644 index 56e9e792..0000000 --- a/Tests/QtAutomoc/codeeditor.h +++ /dev/null @@ -1,99 +0,0 @@ - /**************************************************************************** - ** - ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor - ** the names of its contributors may be used to endorse or promote - ** products derived from this software without specific prior written - ** permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - - #ifndef CODEEDITOR_H - #define CODEEDITOR_H - - #include - #include - - class QPaintEvent; - class QResizeEvent; - class QSize; - class QWidget; - - class LineNumberArea; - - - class CodeEditor : public QPlainTextEdit - { - Q_OBJECT - - public: - CodeEditor(QWidget *parent = 0); - - void lineNumberAreaPaintEvent(QPaintEvent *event); - int lineNumberAreaWidth(); - - protected: - void resizeEvent(QResizeEvent *event); - - private slots: - void updateLineNumberAreaWidth(int newBlockCount); - void highlightCurrentLine(); - void updateLineNumberArea(const QRect &, int); - - private: - QWidget *lineNumberArea; - }; - - - class LineNumberArea : public QWidget - { - public: - LineNumberArea(CodeEditor *editor) : QWidget(editor) { - codeEditor = editor; - } - - QSize sizeHint() const { - return QSize(codeEditor->lineNumberAreaWidth(), 0); - } - - protected: - void paintEvent(QPaintEvent *event) { - codeEditor->lineNumberAreaPaintEvent(event); - } - - private: - CodeEditor *codeEditor; - }; - - - #endif diff --git a/Tests/QtAutomoc/defines_test/CMakeLists.txt b/Tests/QtAutomoc/defines_test/CMakeLists.txt deleted file mode 100644 index ad4e684..0000000 --- a/Tests/QtAutomoc/defines_test/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -add_executable(defines_test defines_test.cpp) -set_target_properties(defines_test PROPERTIES AUTOMOC TRUE) -target_link_libraries(defines_test Qt4::QtGui) diff --git a/Tests/QtAutomoc/defines_test/defines_test.cpp b/Tests/QtAutomoc/defines_test/defines_test.cpp deleted file mode 100644 index 2836d35..0000000 --- a/Tests/QtAutomoc/defines_test/defines_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -#include - -#ifdef QT_GUI_LIB -#include - -class SomeDocument : public QTextDocument -{ - Q_OBJECT - -Q_SIGNALS: - void someSig(); -}; -#endif - -#ifdef QT_CORE_LIB -class SomeObject : public QObject -{ - Q_OBJECT - -Q_SIGNALS: - void someSig(); -}; -#endif - -int main(int argc, char **argv) -{ -#ifdef QT_CORE_LIB - QMetaObject sosmo = SomeObject::staticMetaObject; -#endif -#ifdef QT_GUI_LIB - QMetaObject sdsmo = SomeDocument::staticMetaObject; -#endif - - return 0; -} - -#include "defines_test.moc" diff --git a/Tests/QtAutomoc/empty.cpp b/Tests/QtAutomoc/empty.cpp deleted file mode 100644 index ab32cf6..0000000 --- a/Tests/QtAutomoc/empty.cpp +++ /dev/null @@ -1 +0,0 @@ -// No content diff --git a/Tests/QtAutomoc/empty.h b/Tests/QtAutomoc/empty.h deleted file mode 100644 index 4566142..0000000 --- a/Tests/QtAutomoc/empty.h +++ /dev/null @@ -1,9 +0,0 @@ - -#include - -class Empty : public QObject -{ - Q_OBJECT -public: - explicit Empty(QObject *parent = 0) {} -}; diff --git a/Tests/QtAutomoc/foo.cpp b/Tests/QtAutomoc/foo.cpp deleted file mode 100644 index 699ba09..0000000 --- a/Tests/QtAutomoc/foo.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#include "foo.h" - -#include - -class FooFoo : public QObject -{ - Q_OBJECT - public: - FooFoo():QObject() {} - public slots: - int getValue() const { return 12; } -}; - -Foo::Foo() -:QObject() -{ -} - - -void Foo::doFoo() -{ - FooFoo ff; - printf("Hello automoc: %d\n", ff.getValue()); -} - -#include "foo.moc" diff --git a/Tests/QtAutomoc/foo.h b/Tests/QtAutomoc/foo.h deleted file mode 100644 index 32d4c8d..0000000 --- a/Tests/QtAutomoc/foo.h +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef FOO_H -#define FOO_H - -#include - -class Foo : public QObject -{ - Q_OBJECT - public: - Foo(); - public slots: - void doFoo(); -}; - -#endif diff --git a/Tests/QtAutomoc/gadget.cpp b/Tests/QtAutomoc/gadget.cpp deleted file mode 100644 index 23d95fa..0000000 --- a/Tests/QtAutomoc/gadget.cpp +++ /dev/null @@ -1,4 +0,0 @@ - -#include "gadget.h" - -#include "moc_gadget.cpp" diff --git a/Tests/QtAutomoc/gadget.h b/Tests/QtAutomoc/gadget.h deleted file mode 100644 index 7c688ee..0000000 --- a/Tests/QtAutomoc/gadget.h +++ /dev/null @@ -1,18 +0,0 @@ - -#ifndef GADGET_H -#define GADGET_H - -#include - -class Gadget -{ - Q_GADGET - Q_ENUMS(Type) -public: - enum Type { - Type0, - Type1 - }; -}; - -#endif diff --git a/Tests/QtAutomoc/libC.cpp b/Tests/QtAutomoc/libC.cpp deleted file mode 100644 index 8d61cb1..0000000 --- a/Tests/QtAutomoc/libC.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -#include "libC.h" - -LibC::LibC(QObject *parent) - : QObject(parent) -{ - -} - -int LibC::foo() -{ - return b.foo(); -} diff --git a/Tests/QtAutomoc/libC.h b/Tests/QtAutomoc/libC.h deleted file mode 100644 index 4fb4a2c..0000000 --- a/Tests/QtAutomoc/libC.h +++ /dev/null @@ -1,22 +0,0 @@ - -#ifndef LIBC_H -#define LIBC_H - -#include "libc_export.h" - -#include -#include "libB.h" - -class LIBC_EXPORT LibC : public QObject -{ - Q_OBJECT -public: - explicit LibC(QObject *parent = 0); - - - int foo(); -private: - LibB b; -}; - -#endif diff --git a/Tests/QtAutomoc/main.cpp b/Tests/QtAutomoc/main.cpp deleted file mode 100644 index bd80180..0000000 --- a/Tests/QtAutomoc/main.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** - ** - ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - ** All rights reserved. - ** Contact: Nokia Corporation (qt-info@nokia.com) - ** - ** This file is part of the examples of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:BSD$ - ** You may use this file under the terms of the BSD license as follows: - ** - ** "Redistribution and use in source and binary forms, with or without - ** modification, are permitted provided that the following conditions are - ** met: - ** * Redistributions of source code must retain the above copyright - ** notice, this list of conditions and the following disclaimer. - ** * Redistributions in binary form must reproduce the above copyright - ** notice, this list of conditions and the following disclaimer in - ** the documentation and/or other materials provided with the - ** distribution. - ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor - ** the names of its contributors may be used to endorse or promote - ** products derived from this software without specific prior written - ** permission. - ** - ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ - -#include - -#include "codeeditor.h" -#include "calwidget.h" -#include "foo.h" -#include "blub.h" -#include "sub/bar.h" -#include "abc.h" -#include "xyz.h" -#include "yaf.h" -#include "libC.h" - -int main(int argv, char **args) -{ - QApplication app(argv, args); - - CodeEditor editor; - editor.setWindowTitle(QObject::tr("Code Editor Example")); - editor.show(); - - Window w; - w.show(); - - Foo foo; - foo.doFoo(); - - Blub b; - b.blubber(); - - Bar bar; - bar.doBar(); - - Abc abc; - abc.doAbc(); - - Xyz xyz; - xyz.doXyz(); - - Yaf yaf; - yaf.doYaf(); - - LibC lc; - lc.foo(); - - return app.exec(); -} diff --git a/Tests/QtAutomoc/private_slot.cpp b/Tests/QtAutomoc/private_slot.cpp deleted file mode 100644 index 1387a70..0000000 --- a/Tests/QtAutomoc/private_slot.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -#include "private_slot.h" - -class PrivateSlotPrivate -{ -public: - - void privateSlot() - { - - } -}; - -PrivateSlot::PrivateSlot(QObject *parent) - : QObject(parent), - d(new PrivateSlotPrivate) -{ - -} - -#include "private_slot.moc" diff --git a/Tests/QtAutomoc/private_slot.h b/Tests/QtAutomoc/private_slot.h deleted file mode 100644 index 28e5448..0000000 --- a/Tests/QtAutomoc/private_slot.h +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef PRIVATE_SLOT_H -#define PRIVATE_SLOT_H - -#include - -class PrivateSlotPrivate; - -class PrivateSlot : public QObject -{ - Q_OBJECT -public: - PrivateSlot(QObject *parent = 0); - -private: - PrivateSlotPrivate * const d; - Q_PRIVATE_SLOT(d, void privateSlot()) -}; - -#endif diff --git a/Tests/QtAutomoc/sub/bar.h b/Tests/QtAutomoc/sub/bar.h deleted file mode 100644 index db56b8e..0000000 --- a/Tests/QtAutomoc/sub/bar.h +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef BAR_H -#define BAR_H - -#include - -class Bar : public QObject -{ - Q_OBJECT - public: - Bar(); - public slots: - void doBar(); -}; - -#endif diff --git a/Tests/QtAutomoc/xyz.cpp b/Tests/QtAutomoc/xyz.cpp deleted file mode 100644 index a3562a3..0000000 --- a/Tests/QtAutomoc/xyz.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - - -#include "xyz.h" - -#include - -Xyz::Xyz() -:QObject() -{ -} - - -void Xyz::doXyz() -{ - printf("This is xyz !\n"); -} diff --git a/Tests/QtAutomoc/xyz.h b/Tests/QtAutomoc/xyz.h deleted file mode 100644 index 8175d37..0000000 --- a/Tests/QtAutomoc/xyz.h +++ /dev/null @@ -1,28 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef XYZ_H -#define XYZ_H - -#include - -class Xyz : public QObject -{ - Q_OBJECT - public: - Xyz(); - public slots: - void doXyz(); -}; - -#endif diff --git a/Tests/QtAutomoc/yaf.cpp b/Tests/QtAutomoc/yaf.cpp deleted file mode 100644 index d278ab4..0000000 --- a/Tests/QtAutomoc/yaf.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - - -#include "yaf.h" -#include "yaf_p.h" - -#include - -Yaf::Yaf() -{ -} - - -void Yaf::doYaf() -{ - YafP yafP; - yafP.doYafP(); -} - -// check that including a moc file from a private header the wrong way works: -#include "yaf_p.moc" diff --git a/Tests/QtAutomoc/yaf.h b/Tests/QtAutomoc/yaf.h deleted file mode 100644 index 8689f83..0000000 --- a/Tests/QtAutomoc/yaf.h +++ /dev/null @@ -1,25 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef YAF_H -#define YAF_H - -class Yaf -{ - public: - Yaf(); - public: - void doYaf(); -}; - -#endif diff --git a/Tests/QtAutomoc/yaf_p.h b/Tests/QtAutomoc/yaf_p.h deleted file mode 100644 index f0368ad..0000000 --- a/Tests/QtAutomoc/yaf_p.h +++ /dev/null @@ -1,30 +0,0 @@ -/*============================================================================ - CMake - Cross Platform Makefile Generator - Copyright 2004-2011 Kitware, Inc. - Copyright 2011 Alexander Neundorf (neundorf@kde.org) - - Distributed under the OSI-approved BSD License (the "License"); - see accompanying file Copyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even the - implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the License for more information. -============================================================================*/ - -#ifndef YAF_P_H -#define YAF_P_H - -#include - -#include - -class YafP : public QObject -{ - Q_OBJECT - public: - YafP() {} - public slots: - void doYafP() { printf("I am yet another file !\n"); } -}; - -#endif -- cgit v0.12 From 18fb7588df5b380340423eb36a90a7aefc1fa6ca Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 20:16:43 +0200 Subject: Run the main executable created in the autogen tests. Don't try to show the windows, which would require a gui capable test machine, and that's not guaranteed. Automatically link to qtmain.a on Windows to avoid a policy warning. Set policy CMP0020 to NEW by increasing the required version. Don't attempt to run the test when using Windows. --- Tests/CMakeLists.txt | 13 +++++++++++-- Tests/QtAutogen/CMakeLists.txt | 8 ++++---- Tests/QtAutogen/main.cpp | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 38b2a0c..cf98a41 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1029,6 +1029,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/QtAutomocNoQt") + # On Windows there is no RPATH, so while Qt might be available for building, + # the required dlls may not be in the PATH, so we can't run the executables + # on that platform. + if(WIN32) + set(run_autogen_test ${CMAKE_CTEST_COMMAND} -V) + else() + set(run_autogen_test QtAutogen) + endif() + find_package(Qt5Widgets QUIET NO_MODULE) if(Qt5Widgets_FOUND) add_test(Qt5Autogen ${CMAKE_CTEST_COMMAND} @@ -1040,7 +1049,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt5Autogen" --force-new-ctest-process --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=5 - --test-command ${CMAKE_CTEST_COMMAND} -V + --test-command ${run_autogen_test} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt5Autogen") endif() @@ -1054,7 +1063,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4Autogen" --force-new-ctest-process --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DQT_TEST_VERSION=4 - --test-command ${CMAKE_CTEST_COMMAND} -V + --test-command ${run_autogen_test} ) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Autogen") diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index a7f553f..39c1ae9 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.11) project(QtAutogen) @@ -40,10 +40,10 @@ add_library(codeeditorLib STATIC codeeditor.cpp) add_library(privateSlot OBJECT private_slot.cpp) -add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp +add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp xyz.cpp yaf.cpp gadget.cpp $) -set_target_properties(foo codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) +set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) include(GenerateExportHeader) # The order is relevant here. B depends on A, and B headers depend on A @@ -59,7 +59,7 @@ set_target_properties(libC PROPERTIES AUTOMOC TRUE) generate_export_header(libC) target_link_libraries(libC LINK_PUBLIC libB) -target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} libC) +target_link_libraries(QtAutogen codeeditorLib ${QT_LIBRARIES} libC) add_library(empty STATIC empty.cpp) set_target_properties(empty PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutogen/main.cpp b/Tests/QtAutogen/main.cpp index bd80180..39597ba 100644 --- a/Tests/QtAutogen/main.cpp +++ b/Tests/QtAutogen/main.cpp @@ -56,10 +56,9 @@ int main(int argv, char **args) CodeEditor editor; editor.setWindowTitle(QObject::tr("Code Editor Example")); - editor.show(); Window w; - w.show(); + w.setWindowTitle(QObject::tr("Window Example")); Foo foo; foo.doFoo(); -- cgit v0.12 From 94a0ca604ca6ba3699b6d309938e881b2a3984a0 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Fri, 11 Oct 2013 15:04:15 +0200 Subject: Record which files are skipped by automoc. They may not be skipped by autouic. --- Modules/AutogenInfo.cmake.in | 1 + Source/cmQtAutoGenerators.cxx | 38 ++++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 9cff735..19663ff 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -1,4 +1,5 @@ set(AM_SOURCES @_moc_files@ ) +set(AM_SKIP_MOC @_skip_moc@ ) set(AM_HEADERS @_moc_headers@ ) set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) set(AM_MOC_INCLUDES @_moc_incs@) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 656bb0c..7f8d283 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -379,6 +379,9 @@ void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target, const std::vector& srcFiles = target->GetSourceFiles(); + std::string skip_moc; + const char *sep = ""; + for(std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) @@ -389,22 +392,31 @@ void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target, bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOMOC")); bool generated = cmSystemTools::IsOn(sf->GetPropertyForUser("GENERATED")); - if ((skip==false) && (generated == false)) + if (!generated) { - std::string ext = sf->GetExtension(); - cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat( - ext.c_str()); - if (fileType == cmSystemTools::CXX_FILE_FORMAT) + if (skip) { - _moc_files += sepFiles; - _moc_files += absFile; - sepFiles = ";"; + skip_moc += sep; + skip_moc += absFile; + sep = ";"; } - else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) + else { - _moc_headers += sepHeaders; - _moc_headers += absFile; - sepHeaders = ";"; + std::string ext = sf->GetExtension(); + cmSystemTools::FileFormat fileType = cmSystemTools::GetFileFormat( + ext.c_str()); + if (fileType == cmSystemTools::CXX_FILE_FORMAT) + { + _moc_files += sepFiles; + _moc_files += absFile; + sepFiles = ";"; + } + else if (fileType == cmSystemTools::HEADER_FILE_FORMAT) + { + _moc_headers += sepHeaders; + _moc_headers += absFile; + sepHeaders = ";"; + } } } } @@ -415,6 +427,8 @@ void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target, cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); makefile->AddDefinition("_moc_files", cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str()); + makefile->AddDefinition("_skip_moc", + cmLocalGenerator::EscapeForCMake(skip_moc.c_str()).c_str()); makefile->AddDefinition("_moc_headers", cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); bool relaxedMode = makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE"); -- cgit v0.12 From 84218e1870ab075c9e2be1f2947358702c849fed Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 25 Jul 2013 09:24:53 +0200 Subject: Add automatic uic invocation for Qt. The source files are already processed by cmQtAutomoc to look for moc includes, so extend that to also look for ui_ includes and find corresponding .ui files to process. This replaces the need to invoke qt4_wrap_ui(). As the ui files are not likely to be part of the SOURCES of the target, store the options associated with them separately in the cmMakefile for querying during the autogen run. --- Help/manual/cmake-properties.7.rst | 3 + Help/manual/cmake-variables.7.rst | 2 + Help/prop_sf/AUTOUIC_OPTIONS.rst | 14 ++ Help/prop_tgt/AUTOUIC.rst | 22 ++ Help/prop_tgt/AUTOUIC_OPTIONS.rst | 17 ++ Help/variable/CMAKE_AUTOUIC.rst | 7 + Help/variable/CMAKE_AUTOUIC_OPTIONS.rst | 7 + Modules/AutogenInfo.cmake.in | 5 + Source/cmGlobalGenerator.cxx | 4 +- Source/cmMakefile.cxx | 12 + Source/cmMakefile.h | 5 + Source/cmQtAutoGenerators.cxx | 391 +++++++++++++++++++++++++++++++- Source/cmQtAutoGenerators.h | 27 ++- Source/cmSourceFile.cxx | 11 + Source/cmTarget.cxx | 2 + Tests/QtAutogen/CMakeLists.txt | 2 + Tests/QtAutogen/calwidget.cpp | 3 + Tests/QtAutogen/calwidget.h | 7 + Tests/QtAutogen/calwidget.ui | 32 +++ 19 files changed, 559 insertions(+), 14 deletions(-) create mode 100644 Help/prop_sf/AUTOUIC_OPTIONS.rst create mode 100644 Help/prop_tgt/AUTOUIC.rst create mode 100644 Help/prop_tgt/AUTOUIC_OPTIONS.rst create mode 100644 Help/variable/CMAKE_AUTOUIC.rst create mode 100644 Help/variable/CMAKE_AUTOUIC_OPTIONS.rst create mode 100644 Tests/QtAutogen/calwidget.ui diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index c248085..ddf24d4 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -73,6 +73,8 @@ Properties on Targets /prop_tgt/ARCHIVE_OUTPUT_NAME /prop_tgt/AUTOMOC_MOC_OPTIONS /prop_tgt/AUTOMOC + /prop_tgt/AUTOUIC + /prop_tgt/AUTOUIC_OPTIONS /prop_tgt/BUILD_WITH_INSTALL_RPATH /prop_tgt/BUNDLE_EXTENSION /prop_tgt/BUNDLE @@ -234,6 +236,7 @@ Properties on Source Files .. toctree:: /prop_sf/ABSTRACT + /prop_sf/AUTOUIC_OPTIONS /prop_sf/COMPILE_DEFINITIONS_CONFIG /prop_sf/COMPILE_DEFINITIONS /prop_sf/COMPILE_FLAGS diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 2311ac8..9a5f254 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -155,6 +155,8 @@ Variables that Control the Build /variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY /variable/CMAKE_AUTOMOC_MOC_OPTIONS /variable/CMAKE_AUTOMOC + /variable/CMAKE_AUTOUIC + /variable/CMAKE_AUTOUIC_OPTIONS /variable/CMAKE_BUILD_WITH_INSTALL_RPATH /variable/CMAKE_CONFIG_POSTFIX /variable/CMAKE_DEBUG_POSTFIX diff --git a/Help/prop_sf/AUTOUIC_OPTIONS.rst b/Help/prop_sf/AUTOUIC_OPTIONS.rst new file mode 100644 index 0000000..a38b2f8 --- /dev/null +++ b/Help/prop_sf/AUTOUIC_OPTIONS.rst @@ -0,0 +1,14 @@ +AUTOUIC_OPTIONS +--------------- + +Additional options for uic when using autouic (see the :prop_tgt:`AUTOUIC` target property) + +This property holds additional command line options +which will be used when uic is executed during the build via autouic, +i.e. it is equivalent to the optional OPTIONS argument of the +qt4_wrap_ui() macro. + +By default it is empty. + +The options set on the .ui source file may override :prop_tgt:`AUTOUIC_OPTIONS` set +on the target. diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst new file mode 100644 index 0000000..548c259 --- /dev/null +++ b/Help/prop_tgt/AUTOUIC.rst @@ -0,0 +1,22 @@ +AUTOUIC +------- + +Should the target be processed with autouic (for Qt projects). + +AUTOUIC is a boolean specifying whether CMake will handle +the Qt uic code generator automatically, i.e. without having to use +the QT4_WRAP_UI() or QT5_WRAP_UI() macro. Currently Qt4 and Qt5 are +supported. + +When this property is set to TRUE, CMake will scan the source files +at build time and invoke uic accordingly. +If an #include statement like #include "ui_foo.h" is found in +foo.cpp, a foo.ui file is expected next to foo.cpp, and uic is +run on the foo.ui file. +This property is initialized by the value of the :variable:`CMAKE_AUTOUIC` +variable if it is set when a target is created. + +Additional command line options for uic can be set via the +:prop_sf:`AUTOUIC_OPTIONS` source file property on the foo.ui file. +The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the +autouic targets together in an IDE, e.g. in MSVS. diff --git a/Help/prop_tgt/AUTOUIC_OPTIONS.rst b/Help/prop_tgt/AUTOUIC_OPTIONS.rst new file mode 100644 index 0000000..c6cf885 --- /dev/null +++ b/Help/prop_tgt/AUTOUIC_OPTIONS.rst @@ -0,0 +1,17 @@ +AUTOUIC_OPTIONS +--------------- + +Additional options for uic when using autouic (see the :prop_tgt:`AUTOUIC` target property) + +This property holds additional command line options +which will be used when uic is executed during the build via autouic, +i.e. it is equivalent to the optional OPTIONS argument of the +qt4_wrap_ui() macro. + +By default it is empty. + +This property is initialized by the value of the variable +:variable:`CMAKE_AUTOUIC` if it is set when a target is created. + +The options set on the target may be overridden by :prop_sf:`AUTOUIC_OPTIONS` set +on the .ui source file. diff --git a/Help/variable/CMAKE_AUTOUIC.rst b/Help/variable/CMAKE_AUTOUIC.rst new file mode 100644 index 0000000..3b016b0 --- /dev/null +++ b/Help/variable/CMAKE_AUTOUIC.rst @@ -0,0 +1,7 @@ +CMAKE_AUTOUIC +------------- + +Whether to handle uic automatically for Qt targets. + +This variable is used to initialize the :prop_tgt:`AUTOUIC` property on all the targets. +See that target property for additional information. diff --git a/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst new file mode 100644 index 0000000..6a88669 --- /dev/null +++ b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst @@ -0,0 +1,7 @@ +CMAKE_AUTOUIC_OPTIONS +--------------------- + +Whether to handle uic automatically for Qt targets. + +This variable is used to initialize the :prop_tgt:`AUTOUIC_OPTIONS` property on +all the targets. See that target property for additional information. diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index 19663ff..d2fb807 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -1,5 +1,6 @@ set(AM_SOURCES @_moc_files@ ) set(AM_SKIP_MOC @_skip_moc@ ) +set(AM_SKIP_UIC @_skip_uic@ ) set(AM_HEADERS @_moc_headers@ ) set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) set(AM_MOC_INCLUDES @_moc_incs@) @@ -8,8 +9,12 @@ set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJ set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@") +set(AM_QT_UIC_EXECUTABLE "@_qt_uic_executable@") set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/") set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") set(AM_QT_VERSION_MAJOR "@_target_qt_version@") set(AM_TARGET_NAME @_moc_target_name@) set(AM_RELAXED_MODE "@_moc_relaxed_mode@") +set(AM_UIC_TARGET_OPTIONS @_uic_target_options@) +set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@) +set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 386af6d..3fb6848 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1225,7 +1225,9 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() target.GetType() == cmTarget::MODULE_LIBRARY || target.GetType() == cmTarget::OBJECT_LIBRARY) { - if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported()) + if((target.GetPropertyAsBool("AUTOMOC") + || target.GetPropertyAsBool("AUTOUIC")) + && !target.IsImported()) { cmQtAutoGenerators autogen; if(autogen.InitializeMocSourceFile(&target)) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 13c43fa..df64ca6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4240,6 +4240,18 @@ bool cmMakefile::EnforceUniqueDir(const char* srcPath, const char* binPath) } //---------------------------------------------------------------------------- +void cmMakefile::AddQtUiFileWithOptions(cmSourceFile *sf) +{ + this->QtUiFilesWithOptions.push_back(sf); +} + +//---------------------------------------------------------------------------- +std::vector cmMakefile::GetQtUiFilesWithOptions() const +{ + return this->QtUiFilesWithOptions; +} + +//---------------------------------------------------------------------------- cmPolicies::PolicyStatus cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index ca82336..794873a 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -884,6 +884,9 @@ public: bool IsGeneratingBuildSystem(){ return this->GeneratingBuildSystem; } void SetGeneratingBuildSystem(){ this->GeneratingBuildSystem = true; } + void AddQtUiFileWithOptions(cmSourceFile *sf); + std::vector GetQtUiFilesWithOptions() const; + std::set const & GetSystemIncludeDirectories() const { return this->SystemIncludeDirectories; } @@ -1061,6 +1064,8 @@ private: cmSourceFile* source); void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source); + + std::vector QtUiFilesWithOptions; }; //---------------------------------------------------------------------------- diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 7f8d283..30211f2 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -23,6 +23,7 @@ #include #include +#include #include #if defined(__APPLE__) @@ -117,6 +118,7 @@ cmQtAutoGenerators::cmQtAutoGenerators() :Verbose(cmsys::SystemTools::GetEnv("VERBOSE") != 0) ,ColorOutput(true) ,RunMocFailed(false) +,RunUicFailed(false) ,GenerateAll(false) { @@ -255,7 +257,22 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) "", makefile->GetCurrentOutputDirectory()); std::vector depends; - std::string tools = "moc"; + std::vector toolNames; + if (target->GetPropertyAsBool("AUTOMOC")) + { + toolNames.push_back("moc"); + } + if (target->GetPropertyAsBool("AUTOUIC")) + { + toolNames.push_back("uic"); + } + + std::string tools = toolNames[0]; + toolNames.erase(toolNames.begin()); + if (toolNames.size() == 1) + { + tools += " and " + toolNames[0]; + } std::string autogenComment = "Automatic " + tools + " for target "; autogenComment += targetName; @@ -322,6 +339,10 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) this->SetupAutoMocTarget(target, autogenTargetName, configIncludes, configDefines); } + if (target->GetPropertyAsBool("AUTOUIC")) + { + this->SetupAutoUicTarget(target); + } const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); std::string inputFile = cmakeRoot; @@ -499,6 +520,156 @@ void cmQtAutoGenerators::SetupAutoMocTarget(cmTarget* target, } } +void cmQtAutoGenerators::MergeUicOptions(std::vector &opts, + const std::vector &fileOpts, + bool isQt5) +{ + static const char* valueOptions[] = { + "tr", + "translate", + "postfix", + "generator", + "g" + }; + std::vector extraOpts; + for(std::vector::const_iterator it = fileOpts.begin(); + it != fileOpts.end(); ++it) + { + std::vector::iterator existingIt + = std::find(opts.begin(), opts.end(), *it); + if (existingIt != opts.end()) + { + const char *o = it->c_str(); + if (*o == '-') + { + ++o; + } + if (isQt5 && *o == '-') + { + ++o; + } + if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions), + cmStrCmp(o)) != cmArrayEnd(valueOptions)) + { + assert(existingIt + 1 != opts.end()); + *(existingIt + 1) = *(it + 1); + ++it; + } + } + else + { + extraOpts.push_back(*it); + } + } + opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); +} + +void cmQtAutoGenerators::SetupAutoUicTarget(cmTarget* target) +{ + cmMakefile *makefile = target->GetMakefile(); + + const char *qtUic = makefile->GetSafeDefinition("QT_UIC_EXECUTABLE"); + makefile->AddDefinition("_qt_uic_executable", qtUic); + + const std::vector& srcFiles = target->GetSourceFiles(); + + std::string skip_uic; + const char *sep = ""; + + bool skip = target->GetPropertyAsBool("SKIP_AUTOUIC"); + + std::set skipped; + + for(std::vector::const_iterator fileIt = srcFiles.begin(); + fileIt != srcFiles.end(); + ++fileIt) + { + cmSourceFile* sf = *fileIt; + std::string absFile = cmsys::SystemTools::GetRealPath( + sf->GetFullPath().c_str()); + if (!skip) + { + skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTOUIC")); + } + + if (skip) + { + skip_uic += sep; + skip_uic += absFile; + sep = ";"; + skipped.insert(absFile); + } + } + + makefile->AddDefinition("_skip_uic", + cmLocalGenerator::EscapeForCMake(skip_uic.c_str()).c_str()); + + std::vector uiFilesWithOptions + = makefile->GetQtUiFilesWithOptions(); + + std::string uiFileFiles; + std::string uiFileOptions; + sep = ""; + + const char *qtVersion = makefile->GetDefinition("_target_qt_version"); + + if (const char* opts = target->GetProperty("AUTOUIC_OPTIONS")) + { + makefile->AddDefinition("_uic_target_options", + cmLocalGenerator::EscapeForCMake(opts).c_str()); + } + + for(std::vector::const_iterator fileIt = + uiFilesWithOptions.begin(); + fileIt != uiFilesWithOptions.end(); + ++fileIt) + { + cmSourceFile* sf = *fileIt; + std::string absFile = cmsys::SystemTools::GetRealPath( + sf->GetFullPath().c_str()); + + if (!skipped.insert(absFile).second) + { + continue; + } + uiFileFiles += sep; + uiFileFiles += absFile; + uiFileOptions += sep; + std::string opts = sf->GetProperty("AUTOUIC_OPTIONS"); + cmSystemTools::ReplaceString(opts, ";", "@list_sep@"); + uiFileOptions += opts; + sep = ";"; + } + + makefile->AddDefinition("_qt_uic_options_files", + cmLocalGenerator::EscapeForCMake(uiFileFiles.c_str()).c_str()); + makefile->AddDefinition("_qt_uic_options_options", + cmLocalGenerator::EscapeForCMake(uiFileOptions.c_str()).c_str()); + + const char* targetName = target->GetName(); + if (strcmp(qtVersion, "5") == 0) + { + cmTarget *qt5Uic = makefile->FindTargetToUse("Qt5::uic"); + if (!qt5Uic) + { + // Project does not use Qt5Widgets, but has AUTOUIC ON anyway + makefile->RemoveDefinition("_qt_uic_executable"); + } + else + { + makefile->AddDefinition("_qt_uic_executable", qt5Uic->GetLocation(0)); + } + } + else + { + if (strcmp(qtVersion, "4") != 0) + { + cmSystemTools::Error("The CMAKE_AUTOUIC feature supports only Qt 4 and " + "Qt 5 ", targetName); + } + } +} + bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) { bool success = true; @@ -563,12 +734,15 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, "AM_Qt5Core_VERSION_MAJOR"); } this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); + this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC"); + this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC"); this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); this->IncludeProjectDirsBefore = makefile->IsOn( "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); + this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE"); std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS"; std::string compileDefsProp = compileDefsPropOrig; if(config) @@ -594,6 +768,31 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); + { + const char *uicOptionsFiles + = makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"); + const char *uicTargetOptions + = makefile->GetSafeDefinition("AM_UIC_TARGET_OPTIONS"); + cmSystemTools::ExpandListArgument(uicTargetOptions, this->UicTargetOptions); + const char *uicOptionsOptions + = makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS"); + std::vector uicFilesVec; + cmSystemTools::ExpandListArgument(uicOptionsFiles, uicFilesVec); + std::vector uicOptionsVec; + cmSystemTools::ExpandListArgument(uicOptionsOptions, uicOptionsVec); + if (uicFilesVec.size() != uicOptionsVec.size()) + { + return false; + } + for (std::vector::iterator fileIt = uicFilesVec.begin(), + optionIt = uicOptionsVec.begin(); + fileIt != uicFilesVec.end(); + ++fileIt, ++optionIt) + { + cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";"); + this->UicOptions[*fileIt] = *optionIt; + } + } this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE"); @@ -767,10 +966,18 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) const std::vector& headerExtensions = makefile->GetHeaderExtensions(); + std::vector includedUis; + std::vector skippedUis; + std::vector uicSkipped; + cmSystemTools::ExpandListArgument(this->SkipUic, uicSkipped); + for (std::vector::const_iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { + const bool skipUic = std::find(uicSkipped.begin(), uicSkipped.end(), *it) + != uicSkipped.end(); + std::vector& uiFiles = skipUic ? skippedUis : includedUis; const std::string &absFilename = *it; if (this->Verbose) { @@ -778,15 +985,37 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) } if (this->RelaxedMode) { - this->ParseCppFile(absFilename, headerExtensions, includedMocs); + this->ParseCppFile(absFilename, headerExtensions, includedMocs, + uiFiles); } else { - this->StrictParseCppFile(absFilename, headerExtensions, includedMocs); + this->StrictParseCppFile(absFilename, headerExtensions, includedMocs, + uiFiles); } this->SearchHeadersForCppFile(absFilename, headerExtensions, headerFiles); } + { + std::vector mocSkipped; + cmSystemTools::ExpandListArgument(this->SkipMoc, mocSkipped); + for (std::vector::const_iterator it = mocSkipped.begin(); + it != mocSkipped.end(); + ++it) + { + if (std::find(uicSkipped.begin(), uicSkipped.end(), *it) + != uicSkipped.end()) + { + const std::string &absFilename = *it; + if (this->Verbose) + { + std::cout << "AUTOGEN: Checking " << absFilename << std::endl; + } + this->ParseForUic(absFilename, includedUis); + } + } + } + std::vector headerFilesVec; cmSystemTools::ExpandListArgument(this->Headers, headerFilesVec); for (std::vector::const_iterator it = headerFilesVec.begin(); @@ -798,7 +1027,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) // key = moc source filepath, value = moc output filename std::map notIncludedMocs; - this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs); + this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis); // run moc on all the moc's that are #included in source files for(std::map::const_iterator @@ -808,6 +1037,12 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) { this->GenerateMoc(it->first, it->second); } + for(std::vector::const_iterator it = includedUis.begin(); + it != includedUis.end(); + ++it) + { + this->GenerateUi(*it); + } cmsys_ios::stringstream outStream; outStream << "/* This file is autogenerated, do not edit*/\n"; @@ -840,6 +1075,12 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) std::cerr << "moc failed..."<< std::endl; return false; } + + if (this->RunUicFailed) + { + std::cerr << "uic failed..."<< std::endl; + return false; + } outStream.flush(); std::string automocSource = outStream.str(); if (!automocCppChanged) @@ -866,7 +1107,8 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, - std::map& includedMocs) + std::map& includedMocs, + std::vector &includedUis) { cmsys::RegularExpression mocIncludeRegExp( "[\n][ \t]*#[ \t]*include[ \t]+" @@ -1007,6 +1249,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, matchOffset += mocIncludeRegExp.end(); } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); } + this->ParseForUic(absFilename, contentsString, includedUis); // In this case, check whether the scanned file itself contains a Q_OBJECT. // If this is the case, the moc_foo.cpp should probably be generated from @@ -1047,7 +1290,8 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename, void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, - std::map& includedMocs) + std::map& includedMocs, + std::vector& includedUis) { cmsys::RegularExpression mocIncludeRegExp( "[\n][ \t]*#[ \t]*include[ \t]+" @@ -1138,6 +1382,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, matchOffset += mocIncludeRegExp.end(); } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); } + this->ParseForUic(absFilename, contentsString, includedUis); // In this case, check whether the scanned file itself contains a Q_OBJECT. // If this is the case, the moc_foo.cpp should probably be generated from @@ -1158,6 +1403,61 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename, } +void cmQtAutoGenerators::ParseForUic(const std::string& absFilename, + std::vector& includedUis) +{ + if (this->UicExecutable.empty()) + { + return; + } + const std::string contentsString = this->ReadAll(absFilename); + if (contentsString.empty()) + { + std::cerr << "AUTOGEN: warning: " << absFilename << ": file is empty\n" + << std::endl; + return; + } + this->ParseForUic(absFilename, contentsString, includedUis); +} + + +void cmQtAutoGenerators::ParseForUic(const std::string&, + const std::string& contentsString, + std::vector& includedUis) +{ + if (this->UicExecutable.empty()) + { + return; + } + cmsys::RegularExpression uiIncludeRegExp( + "[\n][ \t]*#[ \t]*include[ \t]+" + "[\"<](([^ \">]+/)?ui_[^ \">/]+\\.h)[\">]"); + + std::string::size_type matchOffset = 0; + + matchOffset = 0; + if ((strstr(contentsString.c_str(), "ui_") != NULL) + && (uiIncludeRegExp.find(contentsString))) + { + do + { + const std::string currentUi = uiIncludeRegExp.match(1); + + std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(currentUi); + + // basename should be the part of the ui filename used for + // finding the correct header, so we need to remove the ui_ part + basename = basename.substr(3); + + includedUis.push_back(basename); + + matchOffset += uiIncludeRegExp.end(); + } while(uiIncludeRegExp.find(contentsString.c_str() + matchOffset)); + } +} + + void cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename, const std::vector& headerExtensions, @@ -1197,13 +1497,15 @@ cmQtAutoGenerators::SearchHeadersForCppFile(const std::string& absFilename, void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, const std::map& includedMocs, - std::map& notIncludedMocs) + std::map& notIncludedMocs, + std::vector& includedUis) { for(std::set::const_iterator hIt=absHeaders.begin(); hIt!=absHeaders.end(); ++hIt) { const std::string& headerName = *hIt; + const std::string contents = this->ReadAll(headerName); if (includedMocs.find(headerName) == includedMocs.end()) { @@ -1216,7 +1518,6 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, GetFilenameWithoutLastExtension(headerName); const std::string currentMoc = "moc_" + basename + ".cpp"; - const std::string contents = this->ReadAll(headerName); std::string macroName; if (requiresMocing(contents, macroName)) { @@ -1224,11 +1525,10 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, notIncludedMocs[headerName] = currentMoc; } } + this->ParseForUic(headerName, contents, includedUis); } - } - bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, const std::string& mocFileName) { @@ -1305,6 +1605,77 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, return false; } +bool cmQtAutoGenerators::GenerateUi(const std::string& uiFileName) +{ + if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false)) + { + cmsys::SystemTools::MakeDirectory(this->Builddir.c_str()); + } + + std::string ui_output_file = "ui_" + uiFileName + ".h"; + std::string ui_input_file = this->Srcdir + uiFileName + ".ui"; + + int sourceNewerThanUi = 0; + bool success = cmsys::SystemTools::FileTimeCompare(ui_input_file.c_str(), + (this->Builddir + ui_output_file).c_str(), + &sourceNewerThanUi); + if (this->GenerateAll || !success || sourceNewerThanUi >= 0) + { + std::string msg = "Generating "; + msg += ui_output_file; + cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue + |cmsysTerminal_Color_ForegroundBold, + msg.c_str(), true, this->ColorOutput); + + std::vector command; + command.push_back(this->UicExecutable); + + std::string options; + std::vector opts = this->UicTargetOptions; + std::map::const_iterator optionIt + = this->UicOptions.find(ui_input_file); + if (optionIt != this->UicOptions.end()) + { + std::vector fileOpts; + cmSystemTools::ExpandListArgument(optionIt->second, fileOpts); + this->MergeUicOptions(opts, fileOpts, this->QtMajorVersion == "5"); + } + for(std::vector::const_iterator optIt = opts.begin(); + optIt != opts.end(); + ++optIt) + { + command.push_back(*optIt); + } + + command.push_back("-o"); + command.push_back(this->Builddir + ui_output_file); + command.push_back(ui_input_file); + + if (this->Verbose) + { + for(std::vector::const_iterator cmdIt = command.begin(); + cmdIt != command.end(); + ++cmdIt) + { + std::cout << *cmdIt << " "; + } + std::cout << std::endl; + } + std::string output; + int retVal = 0; + bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal); + if (!result || retVal) + { + std::cerr << "AUTOUIC: error: process for " << ui_output_file << + " failed:\n" << output << std::endl; + this->RunUicFailed = true; + cmSystemTools::RemoveFile(ui_output_file.c_str()); + return false; + } + return true; + } + return false; +} std::string cmQtAutoGenerators::Join(const std::vector& lst, char separator) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index fe38b05..37b6154 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -31,6 +31,7 @@ private: const std::string &autogenTargetName, std::map &configIncludes, std::map &configDefines); + void SetupAutoUicTarget(cmTarget* target); cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, const char* targetDirectory); @@ -47,19 +48,30 @@ private: bool RunAutogen(cmMakefile* makefile); bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); + bool GenerateUi(const std::string& uiFileName); void ParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, - std::map& includedMocs); + std::map& includedMocs, + std::vector& includedUis); void StrictParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, - std::map& includedMocs); + std::map& includedMocs, + std::vector& includedUis); void SearchHeadersForCppFile(const std::string& absFilename, const std::vector& headerExtensions, std::set& absHeaders); void ParseHeaders(const std::set& absHeaders, const std::map& includedMocs, - std::map& notIncludedMocs); + std::map& notIncludedMocs, + std::vector& includedUis); + + void ParseForUic(const std::string& fileName, + const std::string& contentsString, + std::vector& includedUis); + + void ParseForUic(const std::string& fileName, + std::vector& includedUis); void Init(); @@ -68,13 +80,19 @@ private: bool StartsWith(const std::string& str, const std::string& with); std::string ReadAll(const std::string& filename); + void MergeUicOptions(std::vector &opts, + const std::vector &fileOpts, bool isQt5); + std::string QtMajorVersion; std::string Sources; + std::string SkipMoc; + std::string SkipUic; std::string Headers; bool IncludeProjectDirsBefore; std::string Srcdir; std::string Builddir; std::string MocExecutable; + std::string UicExecutable; std::string MocCompileDefinitionsStr; std::string MocIncludesStr; std::string MocOptionsStr; @@ -89,10 +107,13 @@ private: std::list MocIncludes; std::list MocDefinitions; std::vector MocOptions; + std::vector UicTargetOptions; + std::map UicOptions; bool Verbose; bool ColorOutput; bool RunMocFailed; + bool RunUicFailed; bool GenerateAll; bool RelaxedMode; diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index d747309..ec98c2c 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -287,6 +287,17 @@ void cmSourceFile::SetProperty(const char* prop, const char* value) } this->Properties.SetProperty(prop, value, cmProperty::SOURCE_FILE); + + std::string ext = + cmSystemTools::GetFilenameLastExtension(this->Location.GetName()); + if (ext == ".ui") + { + cmMakefile* mf = this->Location.GetMakefile(); + if (strcmp(prop, "AUTOUIC_OPTIONS") == 0) + { + mf->AddQtUiFileWithOptions(this); + } + } } //---------------------------------------------------------------------------- diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ad4ae0c..5b77c27 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -274,7 +274,9 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("GNUtoMS", 0); this->SetPropertyDefault("OSX_ARCHITECTURES", 0); this->SetPropertyDefault("AUTOMOC", 0); + this->SetPropertyDefault("AUTOUIC", 0); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0); + this->SetPropertyDefault("AUTOUIC_OPTIONS", 0); this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0); this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0); this->SetPropertyDefault("WIN32_EXECUTABLE", 0); diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index 39c1ae9..e194b94 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -35,6 +35,8 @@ add_definitions(-DFOO -DSomeDefine="Barx") # enable relaxed mode so automoc can handle all the special cases: set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) +set(CMAKE_AUTOUIC ON) + # create an executable and two library targets, each requiring automoc: add_library(codeeditorLib STATIC codeeditor.cpp) diff --git a/Tests/QtAutogen/calwidget.cpp b/Tests/QtAutogen/calwidget.cpp index cbfa5a8..defde20 100644 --- a/Tests/QtAutogen/calwidget.cpp +++ b/Tests/QtAutogen/calwidget.cpp @@ -49,7 +49,10 @@ #include "calwidget.h" + #include "ui_calwidget.h" + Window::Window() + : ui(new Ui::Window) { createPreviewGroupBox(); createGeneralOptionsGroupBox(); diff --git a/Tests/QtAutogen/calwidget.h b/Tests/QtAutogen/calwidget.h index 8447389..d21a473 100644 --- a/Tests/QtAutogen/calwidget.h +++ b/Tests/QtAutogen/calwidget.h @@ -52,6 +52,11 @@ class QGroupBox; class QLabel; + namespace Ui + { + class Window; + } + class Window : public QWidget { Q_OBJECT @@ -116,6 +121,8 @@ QCheckBox *firstFridayCheckBox; QCheckBox *mayFirstCheckBox; + + Ui::Window *ui; }; #endif diff --git a/Tests/QtAutogen/calwidget.ui b/Tests/QtAutogen/calwidget.ui new file mode 100644 index 0000000..1c245ca --- /dev/null +++ b/Tests/QtAutogen/calwidget.ui @@ -0,0 +1,32 @@ + + + Window + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 90 + 180 + 94 + 24 + + + + PushButton + + + + + + -- cgit v0.12 From 9c87d9cc3e7a046f79ff62eda81203ef424e4a14 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 15 Sep 2013 14:41:07 +0200 Subject: Add automatic rcc invocation for Qt. This replaces the need to invoke qt4_add_resources by allowing adding the source .qrc file directly to the target sources. --- Help/manual/cmake-properties.7.rst | 3 + Help/manual/cmake-variables.7.rst | 2 + Help/prop_sf/AUTORCC_OPTIONS.rst | 14 ++ Help/prop_tgt/AUTORCC.rst | 21 +++ Help/prop_tgt/AUTORCC_OPTIONS.rst | 17 ++ Help/variable/CMAKE_AUTORCC.rst | 7 + Help/variable/CMAKE_AUTORCC_OPTIONS.rst | 7 + Modules/AutogenInfo.cmake.in | 4 + Source/cmGlobalGenerator.cxx | 3 +- Source/cmQtAutoGenerators.cxx | 283 ++++++++++++++++++++++++++++++++ Source/cmQtAutoGenerators.h | 9 + Source/cmTarget.cxx | 2 + Tests/QtAutogen/CMakeLists.txt | 5 +- Tests/QtAutogen/main.cpp | 16 +- Tests/QtAutogen/resourcetester.cpp | 21 +++ Tests/QtAutogen/resourcetester.h | 17 ++ Tests/QtAutogen/test.qrc | 5 + 17 files changed, 426 insertions(+), 10 deletions(-) create mode 100644 Help/prop_sf/AUTORCC_OPTIONS.rst create mode 100644 Help/prop_tgt/AUTORCC.rst create mode 100644 Help/prop_tgt/AUTORCC_OPTIONS.rst create mode 100644 Help/variable/CMAKE_AUTORCC.rst create mode 100644 Help/variable/CMAKE_AUTORCC_OPTIONS.rst create mode 100644 Tests/QtAutogen/resourcetester.cpp create mode 100644 Tests/QtAutogen/resourcetester.h create mode 100644 Tests/QtAutogen/test.qrc diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index ddf24d4..34a549c 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -75,6 +75,8 @@ Properties on Targets /prop_tgt/AUTOMOC /prop_tgt/AUTOUIC /prop_tgt/AUTOUIC_OPTIONS + /prop_tgt/AUTORCC + /prop_tgt/AUTORCC_OPTIONS /prop_tgt/BUILD_WITH_INSTALL_RPATH /prop_tgt/BUNDLE_EXTENSION /prop_tgt/BUNDLE @@ -237,6 +239,7 @@ Properties on Source Files .. toctree:: /prop_sf/ABSTRACT /prop_sf/AUTOUIC_OPTIONS + /prop_sf/AUTORCC_OPTIONS /prop_sf/COMPILE_DEFINITIONS_CONFIG /prop_sf/COMPILE_DEFINITIONS /prop_sf/COMPILE_FLAGS diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 9a5f254..22a1c4d 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -155,6 +155,8 @@ Variables that Control the Build /variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY /variable/CMAKE_AUTOMOC_MOC_OPTIONS /variable/CMAKE_AUTOMOC + /variable/CMAKE_AUTORCC + /variable/CMAKE_AUTORCC_OPTIONS /variable/CMAKE_AUTOUIC /variable/CMAKE_AUTOUIC_OPTIONS /variable/CMAKE_BUILD_WITH_INSTALL_RPATH diff --git a/Help/prop_sf/AUTORCC_OPTIONS.rst b/Help/prop_sf/AUTORCC_OPTIONS.rst new file mode 100644 index 0000000..4b6bb10 --- /dev/null +++ b/Help/prop_sf/AUTORCC_OPTIONS.rst @@ -0,0 +1,14 @@ +AUTORCC_OPTIONS +--------------- + +Additional options for rcc when using autorcc (see the :prop_tgt:`AUTORCC` target +property) + +This property holds additional command line options which will be used when +rcc is executed during the build via autorcc, i.e. it is equivalent to the +optional OPTIONS argument of the qt4_add_resources() macro. + +By default it is empty. + +The options set on the .qrc source file may override :prop_tgt:`AUTORCC_OPTIONS` set +on the target. diff --git a/Help/prop_tgt/AUTORCC.rst b/Help/prop_tgt/AUTORCC.rst new file mode 100644 index 0000000..ef2c9c8 --- /dev/null +++ b/Help/prop_tgt/AUTORCC.rst @@ -0,0 +1,21 @@ + +AUTORCC +------- + +Should the target be processed with autorcc (for Qt projects). + +AUTORCC is a boolean specifying whether CMake will handle +the Qt rcc code generator automatically, i.e. without having to use +the QT4_ADD_RESOURCES() or QT5_ADD_RESOURCES() macro. Currently Qt4 and Qt5 are +supported. + +When this property is set to TRUE, CMake will handle .qrc files added +as target sources at build time and invoke rcc accordingly. +This property is initialized by the value of the :variable:`CMAKE_AUTORCC` +variable if it is set when a target is created. + +Additional command line options for rcc can be set via the +:prop_sf:`AUTORCC_OPTIONS` source file property on the .qrc file. + +The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the +autouic targets together in an IDE, e.g. in MSVS. diff --git a/Help/prop_tgt/AUTORCC_OPTIONS.rst b/Help/prop_tgt/AUTORCC_OPTIONS.rst new file mode 100644 index 0000000..489e277 --- /dev/null +++ b/Help/prop_tgt/AUTORCC_OPTIONS.rst @@ -0,0 +1,17 @@ +AUTORCC_OPTIONS +--------------- + +Additional options for rcc when using autorcc (see the :prop_tgt:`AUTORCC` target property) + +This property holds additional command line options +which will be used when rcc is executed during the build via autorcc, +i.e. it is equivalent to the optional OPTIONS argument of the +qt4_add_resources() macro. + +By default it is empty. + +This property is initialized by the value of the variable +:variable:`CMAKE_AUTORCC` if it is set when a target is created. + +The options set on the target may be overridden by :prop_sf:`AUTORCC_OPTIONS` set +on the .qrc source file. diff --git a/Help/variable/CMAKE_AUTORCC.rst b/Help/variable/CMAKE_AUTORCC.rst new file mode 100644 index 0000000..d213993 --- /dev/null +++ b/Help/variable/CMAKE_AUTORCC.rst @@ -0,0 +1,7 @@ +CMAKE_AUTORCC +------------- + +Whether to handle rcc automatically for Qt targets. + +This variable is used to initialize the :prop_tgt:`AUTORCC` property on all the targets. +See that target property for additional information. diff --git a/Help/variable/CMAKE_AUTORCC_OPTIONS.rst b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst new file mode 100644 index 0000000..5efbfa3 --- /dev/null +++ b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst @@ -0,0 +1,7 @@ +CMAKE_AUTORCC_OPTIONS +--------------------- + +Whether to handle rcc automatically for Qt targets. + +This variable is used to initialize the :prop_tgt:`AUTORCC_OPTIONS` property on +all the targets. See that target property for additional information. diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index d2fb807..7554213 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -1,4 +1,5 @@ set(AM_SOURCES @_moc_files@ ) +set(AM_RCC_SOURCES @_rcc_files@ ) set(AM_SKIP_MOC @_skip_moc@ ) set(AM_SKIP_UIC @_skip_uic@ ) set(AM_HEADERS @_moc_headers@ ) @@ -10,6 +11,7 @@ set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") set(AM_QT_MOC_EXECUTABLE "@_qt_moc_executable@") set(AM_QT_UIC_EXECUTABLE "@_qt_uic_executable@") +set(AM_QT_RCC_EXECUTABLE "@_qt_rcc_executable@") set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/") set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") set(AM_QT_VERSION_MAJOR "@_target_qt_version@") @@ -18,3 +20,5 @@ set(AM_RELAXED_MODE "@_moc_relaxed_mode@") set(AM_UIC_TARGET_OPTIONS @_uic_target_options@) set(AM_UIC_OPTIONS_FILES @_qt_uic_options_files@) set(AM_UIC_OPTIONS_OPTIONS @_qt_uic_options_options@) +set(AM_RCC_OPTIONS_FILES @_qt_rcc_options_files@) +set(AM_RCC_OPTIONS_OPTIONS @_qt_rcc_options_options@) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 3fb6848..a8bb3fc 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1226,7 +1226,8 @@ void cmGlobalGenerator::CreateQtAutoGeneratorsTargets() target.GetType() == cmTarget::OBJECT_LIBRARY) { if((target.GetPropertyAsBool("AUTOMOC") - || target.GetPropertyAsBool("AUTOUIC")) + || target.GetPropertyAsBool("AUTOUIC") + || target.GetPropertyAsBool("AUTORCC")) && !target.IsImported()) { cmQtAutoGenerators autogen; diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 30211f2..5f7a26f 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -119,6 +119,7 @@ cmQtAutoGenerators::cmQtAutoGenerators() ,ColorOutput(true) ,RunMocFailed(false) ,RunUicFailed(false) +,RunRccFailed(false) ,GenerateAll(false) { @@ -266,9 +267,18 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) { toolNames.push_back("uic"); } + if (target->GetPropertyAsBool("AUTORCC")) + { + toolNames.push_back("rcc"); + } std::string tools = toolNames[0]; toolNames.erase(toolNames.begin()); + while (toolNames.size() > 1) + { + tools += ", " + toolNames[0]; + toolNames.erase(toolNames.begin()); + } if (toolNames.size() == 1) { tools += " and " + toolNames[0]; @@ -343,6 +353,10 @@ void cmQtAutoGenerators::SetupAutoGenerateTarget(cmTarget* target) { this->SetupAutoUicTarget(target); } + if (target->GetPropertyAsBool("AUTORCC")) + { + this->SetupAutoRccTarget(target); + } const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); std::string inputFile = cmakeRoot; @@ -670,6 +684,168 @@ void cmQtAutoGenerators::SetupAutoUicTarget(cmTarget* target) } } +void cmQtAutoGenerators::MergeRccOptions(std::vector &opts, + const std::vector &fileOpts, + bool isQt5) +{ + static const char* valueOptions[] = { + "name", + "root", + "compress", + "threshold" + }; + std::vector extraOpts; + for(std::vector::const_iterator it = fileOpts.begin(); + it != fileOpts.end(); ++it) + { + std::vector::iterator existingIt + = std::find(opts.begin(), opts.end(), *it); + if (existingIt != opts.end()) + { + const char *o = it->c_str(); + if (*o == '-') + { + ++o; + } + if (isQt5 && *o == '-') + { + ++o; + } + if (std::find_if(cmArrayBegin(valueOptions), cmArrayEnd(valueOptions), + cmStrCmp(o)) != cmArrayEnd(valueOptions)) + { + assert(existingIt + 1 != opts.end()); + *(existingIt + 1) = *(it + 1); + ++it; + } + } + else + { + extraOpts.push_back(*it); + } + } + opts.insert(opts.end(), extraOpts.begin(), extraOpts.end()); +} + +void cmQtAutoGenerators::SetupAutoRccTarget(cmTarget* target) +{ + std::string _rcc_files; + const char* sepRccFiles = ""; + cmMakefile *makefile = target->GetMakefile(); + + std::vector newFiles; + + const std::vector& srcFiles = target->GetSourceFiles(); + + std::string rccFileFiles; + std::string rccFileOptions; + const char *sep = ""; + + const char *qtVersion = makefile->GetDefinition("_target_qt_version"); + + std::vector rccOptions; + if (const char* opts = target->GetProperty("AUTORCC_OPTIONS")) + { + cmSystemTools::ExpandListArgument(opts, rccOptions); + } + + for(std::vector::const_iterator fileIt = srcFiles.begin(); + fileIt != srcFiles.end(); + ++fileIt) + { + cmSourceFile* sf = *fileIt; + std::string ext = sf->GetExtension(); + if (ext == "qrc") + { + std::string absFile = cmsys::SystemTools::GetRealPath( + sf->GetFullPath().c_str()); + bool skip = cmSystemTools::IsOn(sf->GetPropertyForUser("SKIP_AUTORCC")); + + if (!skip) + { + _rcc_files += sepRccFiles; + _rcc_files += absFile; + sepRccFiles = ";"; + + std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(absFile); + + std::string rcc_output_file = makefile->GetCurrentOutputDirectory(); + rcc_output_file += "/qrc_" + basename + ".cpp"; + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", + rcc_output_file.c_str(), false); + cmSourceFile* rccCppSource + = makefile->GetOrCreateSource(rcc_output_file.c_str(), true); + newFiles.push_back(rccCppSource); + + if (const char *prop = sf->GetProperty("AUTORCC_OPTIONS")) + { + std::vector optsVec; + cmSystemTools::ExpandListArgument(prop, optsVec); + this->MergeRccOptions(rccOptions, optsVec, + strcmp(qtVersion, "5") == 0); + } + + if (!rccOptions.empty()) + { + rccFileFiles += sep; + rccFileFiles += absFile; + rccFileOptions += sep; + } + const char *listSep = ""; + for(std::vector::const_iterator it = rccOptions.begin(); + it != rccOptions.end(); + ++it) + { + rccFileOptions += listSep; + rccFileOptions += *it; + listSep = "@list_sep@"; + } + sep = ";"; + } + } + } + + for(std::vector::const_iterator fileIt = newFiles.begin(); + fileIt != newFiles.end(); + ++fileIt) + { + target->AddSourceFile(*fileIt); + } + + makefile->AddDefinition("_rcc_files", + cmLocalGenerator::EscapeForCMake(_rcc_files.c_str()).c_str()); + + makefile->AddDefinition("_qt_rcc_options_files", + cmLocalGenerator::EscapeForCMake(rccFileFiles.c_str()).c_str()); + makefile->AddDefinition("_qt_rcc_options_options", + cmLocalGenerator::EscapeForCMake(rccFileOptions.c_str()).c_str()); + + const char *qtRcc = makefile->GetSafeDefinition("QT_RCC_EXECUTABLE"); + makefile->AddDefinition("_qt_rcc_executable", qtRcc); + + const char* targetName = target->GetName(); + if (strcmp(qtVersion, "5") == 0) + { + cmTarget *qt5Rcc = makefile->FindTargetToUse("Qt5::rcc"); + if (!qt5Rcc) + { + cmSystemTools::Error("Qt5::rcc target not found ", + targetName); + return; + } + makefile->AddDefinition("_qt_rcc_executable", qt5Rcc->GetLocation(0)); + } + else + { + if (strcmp(qtVersion, "4") != 0) + { + cmSystemTools::Error("The CMAKE_AUTORCC feature supports only Qt 4 and " + "Qt 5 ", targetName); + } + } +} + bool cmQtAutoGenerators::Run(const char* targetDirectory, const char *config) { bool success = true; @@ -734,6 +910,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, "AM_Qt5Core_VERSION_MAJOR"); } this->Sources = makefile->GetSafeDefinition("AM_SOURCES"); + this->RccSources = makefile->GetSafeDefinition("AM_RCC_SOURCES"); this->SkipMoc = makefile->GetSafeDefinition("AM_SKIP_MOC"); this->SkipUic = makefile->GetSafeDefinition("AM_SKIP_UIC"); this->Headers = makefile->GetSafeDefinition("AM_HEADERS"); @@ -743,6 +920,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE"); + this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE"); std::string compileDefsPropOrig = "AM_MOC_COMPILE_DEFINITIONS"; std::string compileDefsProp = compileDefsPropOrig; if(config) @@ -793,6 +971,28 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(cmMakefile* makefile, this->UicOptions[*fileIt] = *optionIt; } } + { + const char *rccOptionsFiles + = makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES"); + const char *rccOptionsOptions + = makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS"); + std::vector rccFilesVec; + cmSystemTools::ExpandListArgument(rccOptionsFiles, rccFilesVec); + std::vector rccOptionsVec; + cmSystemTools::ExpandListArgument(rccOptionsOptions, rccOptionsVec); + if (rccFilesVec.size() != rccOptionsVec.size()) + { + return false; + } + for (std::vector::iterator fileIt = rccFilesVec.begin(), + optionIt = rccOptionsVec.begin(); + fileIt != rccFilesVec.end(); + ++fileIt, ++optionIt) + { + cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";"); + this->RccOptions[*fileIt] = *optionIt; + } + } this->CurrentCompileSettingsStr = this->MakeCompileSettingsString(makefile); this->RelaxedMode = makefile->IsOn("AM_RELAXED_MODE"); @@ -1044,6 +1244,11 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) this->GenerateUi(*it); } + if(!this->RccExecutable.empty()) + { + this->GenerateQrc(); + } + cmsys_ios::stringstream outStream; outStream << "/* This file is autogenerated, do not edit*/\n"; @@ -1081,6 +1286,11 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) std::cerr << "uic failed..."<< std::endl; return false; } + if (this->RunRccFailed) + { + std::cerr << "rcc failed..."<< std::endl; + return false; + } outStream.flush(); std::string automocSource = outStream.str(); if (!automocCppChanged) @@ -1677,6 +1887,79 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& uiFileName) return false; } +bool cmQtAutoGenerators::GenerateQrc() +{ + std::vector sourceFiles; + cmSystemTools::ExpandListArgument(this->RccSources, sourceFiles); + + for(std::vector::const_iterator si = sourceFiles.begin(); + si != sourceFiles.end(); ++si) + { + std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si); + + if (ext != ".qrc") + { + continue; + } + std::vector command; + command.push_back(this->RccExecutable); + + std::string basename = cmsys::SystemTools:: + GetFilenameWithoutLastExtension(*si); + + std::string rcc_output_file = this->Builddir + "qrc_" + basename + ".cpp"; + + int sourceNewerThanQrc = 0; + bool success = cmsys::SystemTools::FileTimeCompare(si->c_str(), + rcc_output_file.c_str(), + &sourceNewerThanQrc); + if (this->GenerateAll || !success || sourceNewerThanQrc >= 0) + { + std::string options; + std::map::const_iterator optionIt + = this->RccOptions.find(*si); + if (optionIt != this->RccOptions.end()) + { + std::vector opts; + cmSystemTools::ExpandListArgument(optionIt->second, opts); + for(std::vector::const_iterator optIt = opts.begin(); + optIt != opts.end(); + ++optIt) + { + command.push_back(*optIt); + } + } + + command.push_back("-o"); + command.push_back(rcc_output_file); + command.push_back(*si); + + if (this->Verbose) + { + for(std::vector::const_iterator cmdIt = command.begin(); + cmdIt != command.end(); + ++cmdIt) + { + std::cout << *cmdIt << " "; + } + std::cout << std::endl; + } + std::string output; + int retVal = 0; + bool result = cmSystemTools::RunSingleCommand(command, &output, &retVal); + if (!result || retVal) + { + std::cerr << "AUTORCC: error: process for " << rcc_output_file << + " failed:\n" << output << std::endl; + this->RunRccFailed = true; + cmSystemTools::RemoveFile(rcc_output_file.c_str()); + return false; + } + } + } + return true; +} + std::string cmQtAutoGenerators::Join(const std::vector& lst, char separator) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 37b6154..696abc8 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -32,6 +32,7 @@ private: std::map &configIncludes, std::map &configDefines); void SetupAutoUicTarget(cmTarget* target); + void SetupAutoRccTarget(cmTarget* target); cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, const char* targetDirectory); @@ -49,6 +50,7 @@ private: bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); bool GenerateUi(const std::string& uiFileName); + bool GenerateQrc(); void ParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, @@ -83,8 +85,12 @@ private: void MergeUicOptions(std::vector &opts, const std::vector &fileOpts, bool isQt5); + void MergeRccOptions(std::vector &opts, + const std::vector &fileOpts, bool isQt5); + std::string QtMajorVersion; std::string Sources; + std::string RccSources; std::string SkipMoc; std::string SkipUic; std::string Headers; @@ -93,6 +99,7 @@ private: std::string Builddir; std::string MocExecutable; std::string UicExecutable; + std::string RccExecutable; std::string MocCompileDefinitionsStr; std::string MocIncludesStr; std::string MocOptionsStr; @@ -109,11 +116,13 @@ private: std::vector MocOptions; std::vector UicTargetOptions; std::map UicOptions; + std::map RccOptions; bool Verbose; bool ColorOutput; bool RunMocFailed; bool RunUicFailed; + bool RunRccFailed; bool GenerateAll; bool RelaxedMode; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 5b77c27..98e615d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -275,8 +275,10 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("OSX_ARCHITECTURES", 0); this->SetPropertyDefault("AUTOMOC", 0); this->SetPropertyDefault("AUTOUIC", 0); + this->SetPropertyDefault("AUTORCC", 0); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0); this->SetPropertyDefault("AUTOUIC_OPTIONS", 0); + this->SetPropertyDefault("AUTORCC_OPTIONS", 0); this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0); this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0); this->SetPropertyDefault("WIN32_EXECUTABLE", 0); diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index e194b94..7991c4e 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -36,6 +36,7 @@ add_definitions(-DFOO -DSomeDefine="Barx") set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) # create an executable and two library targets, each requiring automoc: add_library(codeeditorLib STATIC codeeditor.cpp) @@ -43,7 +44,9 @@ add_library(codeeditorLib STATIC codeeditor.cpp) add_library(privateSlot OBJECT private_slot.cpp) add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp - xyz.cpp yaf.cpp gadget.cpp $) + xyz.cpp yaf.cpp gadget.cpp $ + test.qrc resourcetester.cpp +) set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE) diff --git a/Tests/QtAutogen/main.cpp b/Tests/QtAutogen/main.cpp index 39597ba..c8a036e 100644 --- a/Tests/QtAutogen/main.cpp +++ b/Tests/QtAutogen/main.cpp @@ -38,7 +38,8 @@ ** ****************************************************************************/ -#include +#include +#include #include "codeeditor.h" #include "calwidget.h" @@ -49,16 +50,11 @@ #include "xyz.h" #include "yaf.h" #include "libC.h" +#include "resourcetester.h" int main(int argv, char **args) { - QApplication app(argv, args); - - CodeEditor editor; - editor.setWindowTitle(QObject::tr("Code Editor Example")); - - Window w; - w.setWindowTitle(QObject::tr("Window Example")); + QCoreApplication app(argv, args); Foo foo; foo.doFoo(); @@ -81,5 +77,9 @@ int main(int argv, char **args) LibC lc; lc.foo(); + ResourceTester rt; + + QTimer::singleShot(0, &rt, SLOT(doTest())); + return app.exec(); } diff --git a/Tests/QtAutogen/resourcetester.cpp b/Tests/QtAutogen/resourcetester.cpp new file mode 100644 index 0000000..43314e1 --- /dev/null +++ b/Tests/QtAutogen/resourcetester.cpp @@ -0,0 +1,21 @@ + +#include "resourcetester.h" + +#include +#include +#include +#include + +ResourceTester::ResourceTester(QObject *parent) + : QObject(parent) +{ + +} + +void ResourceTester::doTest() +{ + if (!QFile::exists(":/CMakeLists.txt")) + qApp->exit(EXIT_FAILURE); + + QTimer::singleShot(0, qApp, SLOT(quit())); +} diff --git a/Tests/QtAutogen/resourcetester.h b/Tests/QtAutogen/resourcetester.h new file mode 100644 index 0000000..b02cb4e --- /dev/null +++ b/Tests/QtAutogen/resourcetester.h @@ -0,0 +1,17 @@ + +#ifndef RESOURCE_TESTER_H +#define RESOURCE_TESTER_H + +#include + +class ResourceTester : public QObject +{ + Q_OBJECT +public: + explicit ResourceTester(QObject *parent = 0); + +private slots: + void doTest(); +}; + +#endif diff --git a/Tests/QtAutogen/test.qrc b/Tests/QtAutogen/test.qrc new file mode 100644 index 0000000..c3d4e3c --- /dev/null +++ b/Tests/QtAutogen/test.qrc @@ -0,0 +1,5 @@ + + + CMakeLists.txt + + -- cgit v0.12