diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Source/cmAddExecutableCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmAddLibraryCommand.cxx | 33 | ||||
-rw-r--r-- | Source/cmDocumentVariables.cxx | 9 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 64 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio7Generator.cxx | 12 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio7Generator.h | 3 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 2 | ||||
-rw-r--r-- | Source/cmLocalUnixMakefileGenerator3.cxx | 2 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 44 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.h | 1 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 22 | ||||
-rw-r--r-- | Source/cmMakefile.h | 2 | ||||
-rw-r--r-- | Source/cmQtAutomoc.cxx | 782 | ||||
-rw-r--r-- | Source/cmQtAutomoc.h | 66 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 25 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmake.cxx | 149 | ||||
-rw-r--r-- | Source/cmake.h | 32 | ||||
-rw-r--r-- | Source/cmakemain.cxx | 17 | ||||
-rw-r--r-- | Source/kwsys/kwsysDateStamp.cmake | 2 |
23 files changed, 1176 insertions, 102 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 1c942ba..96b3ea0 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -228,6 +228,8 @@ SET(SRCS cmPropertyDefinitionMap.h cmPropertyMap.cxx cmPropertyMap.h + cmQtAutomoc.cxx + cmQtAutomoc.h cmScriptGenerator.h cmScriptGenerator.cxx cmSourceFile.cxx diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index a625c47..bac2430 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -58,7 +58,8 @@ bool cmAddExecutableCommand } // Special modifiers are not allowed with IMPORTED signature. - if(importTarget && (use_win32 || use_macbundle || excludeFromAll)) + if(importTarget + && (use_win32 || use_macbundle || excludeFromAll)) { if(use_win32) { diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index f522cee..efa29e6 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -31,13 +31,13 @@ bool cmAddLibraryCommand } bool excludeFromAll = false; bool importTarget = false; - + std::vector<std::string>::const_iterator s = args.begin(); std::string libName = *s; ++s; - + // If the second argument is "SHARED" or "STATIC", then it controls // the type of library. Otherwise, it is treated as a source or // source list name. There may be two keyword arguments, check for them @@ -85,11 +85,11 @@ bool cmAddLibraryCommand } } - /* ideally we should check whether for the linker language of the target + /* ideally we should check whether for the linker language of the target CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to - STATIC. But at this point we know only the name of the target, but not + STATIC. But at this point we know only the name of the target, but not yet its linker language. */ - if ((type != cmTarget::STATIC_LIBRARY) && + if ((type != cmTarget::STATIC_LIBRARY) && (this->Makefile->GetCMakeInstance()->GetPropertyAsBool( "TARGET_SUPPORTS_SHARED_LIBS") == false)) { @@ -103,16 +103,16 @@ bool cmAddLibraryCommand type = cmTarget::STATIC_LIBRARY; } - // The IMPORTED signature requires a type to be specified explicitly. - if(importTarget && !haveSpecifiedType) - { - this->SetError("called with IMPORTED argument but no library type."); - return false; - } - // Handle imported target creation. if(importTarget) { + // The IMPORTED signature requires a type to be specified explicitly. + if (!haveSpecifiedType) + { + this->SetError("called with IMPORTED argument but no library type."); + return false; + } + // Make sure the target does not already exist. if(this->Makefile->FindTargetToUse(libName.c_str())) { @@ -158,15 +158,14 @@ bool cmAddLibraryCommand } std::vector<std::string> srclists; - while (s != args.end()) + while (s != args.end()) { - srclists.push_back(*s); + srclists.push_back(*s); ++s; } - this->Makefile->AddLibrary(libName.c_str(), type, srclists, - excludeFromAll); - + this->Makefile->AddLibrary(libName.c_str(), type, srclists, excludeFromAll); + return true; } diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index ebe2988..26125d9 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -1085,6 +1085,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "Variables that Control the Build"); cm->DefineProperty + ("CMAKE_AUTOMOC", cmProperty::VARIABLE, + "Whether to handle moc automatically for Qt targets.", + "This variable is used to initialize the " + "AUTOMOC property on all the targets. " + "See that target property for additional information.", + false, + "Variables that Control the Build"); + + cm->DefineProperty ("CMAKE_DEBUG_POSTFIX", cmProperty::VARIABLE, "See variable CMAKE_<CONFIG>_POSTFIX.", "This variable is a special case of the more-general " diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2eae01e..d62fb44 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -18,6 +18,7 @@ #include "cmExternalMakefileProjectGenerator.h" #include "cmake.h" #include "cmMakefile.h" +#include "cmQtAutomoc.h" #include "cmSourceFile.h" #include "cmVersion.h" #include "cmExportInstallFileGenerator.h" @@ -269,7 +270,7 @@ cmGlobalGenerator::EnableLanguage(std::vector<std::string>const& languages, cmOStringStream windowsVersionString; windowsVersionString << osvi.dwMajorVersion << "." << osvi.dwMinorVersion; windowsVersionString.str(); - mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", + mf->AddDefinition("CMAKE_HOST_SYSTEM_VERSION", windowsVersionString.str().c_str()); #endif // Read the DetermineSystem file @@ -618,8 +619,8 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const char* l, cmMakefile* mf) if (sscanf(linkerPref, "%d", &preference)!=1) { // backward compatibility: before 2.6 LINKER_PREFERENCE - // was either "None" or "Prefered", and only the first character was - // tested. So if there is a custom language out there and it is + // was either "None" or "Prefered", and only the first character was + // tested. So if there is a custom language out there and it is // "Prefered", set its preference high if (linkerPref[0]=='P') { @@ -782,7 +783,7 @@ void cmGlobalGenerator::Configure() // so create the map from project name to vector of local generators this->FillProjectMap(); - if ( !this->CMakeInstance->GetScriptMode() ) + if ( this->CMakeInstance->GetWorkingMode() == cmake::NORMAL_MODE) { const char* msg = "Configuring done"; if(cmSystemTools::GetErrorOccuredFlag()) @@ -832,6 +833,10 @@ void cmGlobalGenerator::Generate() return; } + // Iterate through all targets and set up automoc for those which have + // the AUTOMOC property set + this->CreateAutomocTargets(); + // For each existing cmLocalGenerator unsigned int i; @@ -950,6 +955,35 @@ bool cmGlobalGenerator::CheckTargets() return true; } +//---------------------------------------------------------------------------- +void cmGlobalGenerator::CreateAutomocTargets() +{ +#ifdef CMAKE_BUILD_WITH_CMAKE + for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) + { + cmTargets& targets = + this->LocalGenerators[i]->GetMakefile()->GetTargets(); + for(cmTargets::iterator ti = targets.begin(); + ti != targets.end(); ++ti) + { + cmTarget& target = ti->second; + if(target.GetType() == cmTarget::EXECUTABLE || + target.GetType() == cmTarget::STATIC_LIBRARY || + target.GetType() == cmTarget::SHARED_LIBRARY || + target.GetType() == cmTarget::MODULE_LIBRARY) + { + if(target.GetPropertyAsBool("AUTOMOC") && !target.IsImported()) + { + cmQtAutomoc automoc; + automoc.SetupAutomocTarget(&target); + } + } + } + } +#endif +} + + void cmGlobalGenerator::CheckLocalGenerators() { std::map<cmStdString, cmStdString> notFoundMap; @@ -1019,9 +1053,9 @@ void cmGlobalGenerator::CheckLocalGenerators() if(notFoundMap.size()) { std::string notFoundVars; - for(std::map<cmStdString, cmStdString>::const_iterator + for(std::map<cmStdString, cmStdString>::const_iterator ii = notFoundMap.begin(); - ii != notFoundMap.end(); + ii != notFoundMap.end(); ++ii) { notFoundVars += ii->first; @@ -1057,7 +1091,7 @@ int cmGlobalGenerator::TryCompile(const char *srcdir, const char *bindir, { this->FirstTimeProgress = 0.95f; } - this->CMakeInstance->UpdateProgress("Configuring", + this->CMakeInstance->UpdateProgress("Configuring", this->FirstTimeProgress); } @@ -1161,7 +1195,7 @@ int cmGlobalGenerator::Build( { outputPtr = &outputBuffer; } - + // should we do a clean first? if (clean) { @@ -1199,7 +1233,7 @@ int cmGlobalGenerator::Build( // now build std::string makeCommand = this->GenerateBuildCommand(makeCommandCSTR, projectName, - extraOptions, target, + extraOptions, target, config, false, fast); if(output) { @@ -1272,8 +1306,8 @@ void cmGlobalGenerator::AddLocalGenerator(cmLocalGenerator *lg) if(this->FirstTimeProgress > 0.95f) { this->FirstTimeProgress = 0.95f; - } - this->CMakeInstance->UpdateProgress("Configuring", + } + this->CMakeInstance->UpdateProgress("Configuring", this->FirstTimeProgress); return; } @@ -1296,8 +1330,8 @@ void cmGlobalGenerator::AddInstallComponent(const char* component) } } -void cmGlobalGenerator::AddTargetToExports(const char* exportSetName, - cmTarget* target, +void cmGlobalGenerator::AddTargetToExports(const char* exportSetName, + cmTarget* target, cmInstallTargetGenerator* archive, cmInstallTargetGenerator* runTime, cmInstallTargetGenerator* library, @@ -1331,7 +1365,7 @@ void cmGlobalGenerator::ClearExportSets() const std::vector<cmTargetExport*>* cmGlobalGenerator::GetExportSet( const char* name) const { - std::map<cmStdString, std::vector<cmTargetExport*> >::const_iterator + std::map<cmStdString, std::vector<cmTargetExport*> >::const_iterator exportSetIt = this->ExportSets.find(name); if (exportSetIt != this->ExportSets.end()) { @@ -1443,7 +1477,7 @@ void cmGlobalGenerator::GetEnabledLanguages(std::vector<std::string>& lang) int cmGlobalGenerator::GetLinkerPreference(const char* lang) { - std::map<cmStdString, int>::const_iterator it = + std::map<cmStdString, int>::const_iterator it = this->LanguageToLinkerPreference.find(lang); if (it != this->LanguageToLinkerPreference.end()) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index b7b1bff..88eb8b6 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -282,6 +282,8 @@ protected: virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS(); bool CheckTargets(); + void CreateAutomocTargets(); + // Fill the ProjectMap, this must be called after LocalGenerators // has been populated. diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 51b8918..84e7f1b 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -739,18 +739,6 @@ void cmGlobalVisualStudio7Generator entry.Full = ""; } -// make sure "special" targets have GUID's -void cmGlobalVisualStudio7Generator::Configure() -{ - cmGlobalGenerator::Configure(); - this->CreateGUID("ALL_BUILD"); - this->CreateGUID("INSTALL"); - this->CreateGUID("RUN_TESTS"); - this->CreateGUID("EDIT_CACHE"); - this->CreateGUID("REBUILD_CACHE"); - this->CreateGUID("PACKAGE"); -} - //---------------------------------------------------------------------------- void cmGlobalVisualStudio7Generator diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index b6c84e8..7f19d83 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -80,9 +80,6 @@ public: void CreateGUID(const char* name); std::string GetGUID(const char* name); - ///! do configure step - virtual void Configure(); - /** Append the subdirectory for the given configuration. */ virtual void AppendDirectoryForConfig(const char* prefix, const char* config, diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index cde02b7..f67b029 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1780,7 +1780,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, default: break; } - if(this->XcodeVersion >= 22) + if(this->XcodeVersion >= 22 && this->XcodeVersion < 40) { buildSettings->AddAttribute("PREBINDING", this->CreateString("NO")); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index aebf9f3..a204a73 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -307,7 +307,6 @@ public: std::string const& dir_max, bool* hasSourceExtension = 0); -protected: /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ void GetTargetFlags(std::string& linkLibs, @@ -315,6 +314,7 @@ protected: std::string& linkFlags, cmTarget&target); +protected: ///! put all the libraries for a target on into the given stream virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 6ab5c2a..2eae9d0 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1276,6 +1276,7 @@ cmLocalUnixMakefileGenerator3 // and there are no "." charactors in the string, then return the // unmodified combination. if((!this->MakefileVariableSize && unmodified.find('.') == s.npos) + && (!this->MakefileVariableSize && unmodified.find('+') == s.npos) && (!this->MakefileVariableSize && unmodified.find('-') == s.npos)) { return unmodified; @@ -1297,6 +1298,7 @@ cmLocalUnixMakefileGenerator3 { cmSystemTools::ReplaceString(ret, ".", "_"); cmSystemTools::ReplaceString(ret, "-", "__"); + cmSystemTools::ReplaceString(ret, "+", "___"); int ni = 0; char buffer[5]; // make sure the _ version is not already used, if diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 2991a3a..1f99cba 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -68,6 +68,27 @@ void cmLocalVisualStudio7Generator::AddHelperCommands() lang.insert("DEF"); lang.insert("Fortran"); this->CreateCustomTargetsAndCommands(lang); + + // Now create GUIDs for targets + cmTargets &tgts = this->Makefile->GetTargets(); + + cmGlobalVisualStudio7Generator* gg = + static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); + for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) + { + const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT"); + if(path) + { + this->ReadAndStoreExternalGUID( + l->second.GetName(), path); + } + else + { + gg->CreateGUID(l->first.c_str()); + } + } + + this->FixGlobalTargets(); } @@ -2032,29 +2053,6 @@ void cmLocalVisualStudio7Generator::ReadAndStoreExternalGUID( } -void cmLocalVisualStudio7Generator::ConfigureFinalPass() -{ - cmLocalGenerator::ConfigureFinalPass(); - cmTargets &tgts = this->Makefile->GetTargets(); - - cmGlobalVisualStudio7Generator* gg = - static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) - { - const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT"); - if(path) - { - this->ReadAndStoreExternalGUID( - l->second.GetName(), path); - } - else - { - gg->CreateGUID(l->first.c_str()); - } - } - -} - //---------------------------------------------------------------------------- std::string cmLocalVisualStudio7Generator ::GetTargetDirectory(cmTarget const& target) const diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 35f659f..cdd714e 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -57,7 +57,6 @@ public: void SetVersion8() {this->Version = 8;} void SetVersion9() {this->Version = 9;} void SetPlatformName(const char* n) { this->PlatformName = n;} - virtual void ConfigureFinalPass(); void GetTargetObjectFileDirectories(cmTarget* target, std::vector<std::string>& dirs); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a5cdee4..e5b5443 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -384,7 +384,9 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, // Decide whether to invoke the command. if(pcmd->GetEnabled() && !cmSystemTools::GetFatalErrorOccured() && - (!this->GetCMakeInstance()->GetScriptMode() || pcmd->IsScriptable())) + (this->GetCMakeInstance()->GetWorkingMode() != cmake::SCRIPT_MODE + || pcmd->IsScriptable())) + { // if trace is one, print out invoke information if(this->GetCMakeInstance()->GetTrace()) @@ -411,7 +413,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, this->IssueMessage(cmake::FATAL_ERROR, pcmd->GetError()); } result = false; - if ( this->GetCMakeInstance()->GetScriptMode() ) + if ( this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) { cmSystemTools::SetFatalErrorOccured(); } @@ -422,7 +424,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, this->UsedCommands.push_back(pcmd.release()); } } - else if ( this->GetCMakeInstance()->GetScriptMode() + else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE && !pcmd->IsScriptable() ) { std::string error = "Command "; @@ -1886,7 +1888,7 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target) } -void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, +cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll) { @@ -1909,6 +1911,7 @@ void cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, } target->AddSources(srcs); this->AddGlobalLinkInformation(lname, *target); + return target; } cmTarget* cmMakefile::AddExecutable(const char *exeName, @@ -3024,8 +3027,15 @@ cmCacheManager *cmMakefile::GetCacheManager() const void cmMakefile::DisplayStatus(const char* message, float s) { - this->GetLocalGenerator()->GetGlobalGenerator() - ->GetCMakeInstance()->UpdateProgress(message, s); + cmake* cm = this->GetLocalGenerator()->GetGlobalGenerator() + ->GetCMakeInstance(); + if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) + { + // don't output any STATUS message in FIND_PACKAGE_MODE, since they will + // directly be fed to the compiler, which will be confused. + return; + } + cm->UpdateProgress(message, s); } std::string cmMakefile::GetModulesFile(const char* filename) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c01bb5d..618f4f3 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -325,7 +325,7 @@ public: /** * Set the name of the library. */ - void AddLibrary(const char *libname, cmTarget::TargetType type, + cmTarget* AddLibrary(const char *libname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll = false); diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx new file mode 100644 index 0000000..ff96e5b --- /dev/null +++ b/Source/cmQtAutomoc.cxx @@ -0,0 +1,782 @@ +#include "cmGlobalGenerator.h" +#include "cmLocalGenerator.h" +#include "cmMakefile.h" +#include "cmSourceFile.h" +#include "cmSystemTools.h" + +# include <cmsys/Terminal.h> + +#include "cmQtAutomoc.h" + + +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; + } + } +} + + +void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) +{ + cmMakefile* makefile = target->GetMakefile(); + const char* targetName = target->GetName(); + // don't do anything if there is no Qt4: + std::string qtMajorVersion = makefile->GetSafeDefinition("QT_VERSION_MAJOR"); + if (qtMajorVersion != "4") + { + return; + } + + // 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->GetCMakeInstance()->GetCMakeCommand()); + currentLine.push_back("-E"); + currentLine.push_back("cmake_automoc"); + currentLine.push_back(targetDir); + + cmCustomCommandLines commandLines; + commandLines.push_back(currentLine); + + std::string workingDirectory = cmSystemTools::CollapseFullPath( + "", makefile->GetCurrentOutputDirectory()); + + std::vector<std::string> depends; + std::string automocComment = "Automoc for target "; + automocComment += targetName; + + makefile->AddUtilityCommand(automocTargetName.c_str(), true, + workingDirectory.c_str(), depends, + commandLines, false, automocComment.c_str()); + 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<cmSourceFile*>& srcFiles = target->GetSourceFiles(); + + for(std::vector<cmSourceFile*>::const_iterator fileIt = srcFiles.begin(); + fileIt != srcFiles.end(); + ++fileIt) + { + cmSourceFile* sf = *fileIt; + std::string absFile = sf->GetFullPath(); + 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 = ";"; + } + } + } + + std::string _moc_incs = makefile->GetProperty("INCLUDE_DIRECTORIES"); + std::string _moc_defs = makefile->GetProperty("DEFINITIONS"); + std::string _moc_compile_defs = makefile->GetProperty("COMPILE_DEFINITIONS"); + // forget the variables added here afterwards again: + cmMakefile::ScopePushPop varScope(makefile); + static_cast<void>(varScope); + + makefile->AddDefinition("_moc_target_name", automocTargetName.c_str()); + makefile->AddDefinition("_moc_incs", _moc_incs.c_str()); + makefile->AddDefinition("_moc_defs", _moc_defs.c_str()); + makefile->AddDefinition("_moc_compile_defs", _moc_compile_defs.c_str()); + makefile->AddDefinition("_moc_files", _moc_files.c_str()); + makefile->AddDefinition("_moc_headers", _moc_headers.c_str()); + + const char* cmakeRoot = makefile->GetDefinition("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); + + std::string mocCppFile = makefile->GetCurrentOutputDirectory(); + mocCppFile += "/"; + mocCppFile += automocTargetName; + mocCppFile += ".cpp"; + cmSourceFile* mocCppSource = makefile->GetOrCreateSource(mocCppFile.c_str(), + true); + target->AddSourceFile(mocCppSource); + + makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", + mocCppFile.c_str(), false); +} + + +bool cmQtAutomoc::Run(const char* targetDirectory) +{ + cmake cm; + cmGlobalGenerator* gg = this->CreateGlobalGenerator(&cm, targetDirectory); + cmMakefile* makefile = gg->GetCurrentLocalGenerator()->GetMakefile(); + + this->ReadAutomocInfoFile(makefile, targetDirectory); + this->ReadOldMocDefinitionsFile(makefile, targetDirectory); + + this->Init(); + + if (this->QtMajorVersion == "4") + { + this->RunAutomocQt4(); + } + + this->WriteOldMocDefinitionsFile(targetDirectory); + + delete gg; + gg = NULL; + makefile = NULL; + return true; +} + + +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) +{ + 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"); + 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_BINARY_DIR"); + this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); + this->MocCompileDefinitionsStr = makefile->GetSafeDefinition( + "AM_MOC_COMPILE_DEFINITIONS"); + this->MocDefinitionsStr = makefile->GetSafeDefinition("AM_MOC_DEFINITIONS"); + this->MocIncludesStr = makefile->GetSafeDefinition("AM_MOC_INCLUDES"); + this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); + this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); + this->TargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); + + return true; +} + + +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->OldMocDefinitionsStr = + makefile->GetSafeDefinition("AM_OLD_MOC_DEFINITIONS"); + } + 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_MOC_DEFINITIONS \"" + << this->Join(this->MocDefinitions, ' ') << "\")\n"; + + outfile.close(); +} + + +void cmQtAutomoc::Init() +{ + this->OutMocCppFilename = this->Builddir; + this->OutMocCppFilename += this->TargetName; + this->OutMocCppFilename += ".cpp"; + + std::vector<std::string> cdefList; + cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); + if (!cdefList.empty()) + { + for(std::vector<std::string>::const_iterator it = cdefList.begin(); + it != cdefList.end(); + ++it) + { + this->MocDefinitions.push_back("-D" + (*it)); + } + } + else + { + std::string tmpMocDefs = this->MocDefinitionsStr; + cmSystemTools::ReplaceString(tmpMocDefs, " ", ";"); + + std::vector<std::string> defList; + cmSystemTools::ExpandListArgument(tmpMocDefs, defList); + + for(std::vector<std::string>::const_iterator it = defList.begin(); + it != defList.end(); + ++it) + { + if (this->StartsWith(*it, "-D")) + { + this->MocDefinitions.push_back(*it); + } + } + } + + std::vector<std::string> incPaths; + cmSystemTools::ExpandListArgument(this->MocIncludesStr, incPaths); + + std::set<std::string> frameworkPaths; + for(std::vector<std::string>::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<std::string> 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<std::string>::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<std::string> sortedMocIncludes; + std::list<std::string>::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::RunAutomocQt4() +{ + if (!cmsys::SystemTools::FileExists(this->OutMocCppFilename.c_str()) + || (this->OldMocDefinitionsStr != this->Join(this->MocDefinitions, ' '))) + { + 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_<filename>.cpp file is created and included in + // the _automoc.cpp file. + + // key = moc source filepath, value = moc output filepath + std::map<std::string, std::string> includedMocs; + // key = moc source filepath, value = moc output filename + std::map<std::string, std::string> notIncludedMocs; + + + std::vector<std::string> sourceFiles; + cmSystemTools::ExpandListArgument(this->Sources, sourceFiles); + + for (std::vector<std::string>::const_iterator it = sourceFiles.begin(); + it != sourceFiles.end(); + ++it) + { + const std::string &absFilename = *it; + if (this->Verbose) + { + std::cout << "AUTOMOC: Checking " << absFilename << std::endl; + } + this->ParseCppFile(absFilename, includedMocs, notIncludedMocs); + } + + std::vector<std::string> headerFiles; + cmSystemTools::ExpandListArgument(this->Headers, headerFiles); + for (std::vector<std::string>::const_iterator it = headerFiles.begin(); + it != headerFiles.end(); + ++it) + { + const std::string &absFilename = *it; + if (this->Verbose) + { + std::cout << "AUTOMOC: Checking " << absFilename << std::endl; + } + if (includedMocs.find(absFilename) == includedMocs.end() + && notIncludedMocs.find(absFilename) == notIncludedMocs.end()) + { + // if this header is not getting processed yet and is explicitly + // mentioned for the automoc the moc is run unconditionally on the + // header and the resulting file is included in the _automoc.cpp file + // (unless there's a .cpp file later on that includes the moc from + // this header) + const std::string currentMoc = "moc_" + cmsys::SystemTools:: + GetFilenameWithoutLastExtension(absFilename) + ".cpp"; + notIncludedMocs[absFilename] = currentMoc; + } + } + + // run moc on all the moc's that are #included in source files + for(std::map<std::string, std::string>::const_iterator + it = includedMocs.begin(); + it != includedMocs.end(); + ++it) + { + this->GenerateMoc(it->first, it->second); + } + + std::stringstream outStream(std::stringstream::out); + 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<std::string, std::string>::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 << "returning 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, + std::map<std::string, std::string>& includedMocs, + std::map<std::string, std::string>& notIncludedMocs) +{ + cmsys::RegularExpression mocIncludeRegExp( + "[\n][ \t]*#[ \t]*include[ \t]+" + "[\"<](([^ \">]+/)?moc_[^ \">/]+\\.cpp|[^ \">]+\\.moc)[\">]"); + cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]"); + std::list<std::string> headerExtensions; + headerExtensions.push_back(".h"); + headerExtensions.push_back(".hpp"); + headerExtensions.push_back(".hxx"); +#if defined(_WIN32) + // not case sensitive, don't add ".H" +#elif defined(__APPLE__) + // detect case-sensitive filesystem + long caseSensitive = pathconf(this->Srcdir.c_str(), _PC_CASE_SENSITIVE); + if (caseSensitive == 1) + { + headerExtensions.push_back(".H"); + } +#else + headerExtensions.push_back(".H"); +#endif + + const std::string contentsString = this->ReadAll(absFilename); + if (contentsString.empty()) + { + std::cerr << "AUTOMOC: empty source file: " << absFilename << std::endl; + return; + } + const std::string absPath = cmsys::SystemTools::GetFilenamePath( + cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/'; + + std::string::size_type matchOffset = 0; + if (!mocIncludeRegExp.find(contentsString.c_str())) + { + // no moc #include, look whether we need to create a moc from + // the .h nevertheless + const std::string basename = + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); + for(std::list<std::string>::const_iterator ext = headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string headername = absPath + basename + (*ext); + if (cmsys::SystemTools::FileExists(headername.c_str()) + && includedMocs.find(headername) == includedMocs.end() + && notIncludedMocs.find(headername) == notIncludedMocs.end()) + { + const std::string currentMoc = "moc_" + basename + ".cpp"; + const std::string contents = this->ReadAll(headername); + if (qObjectRegExp.find(contents)) + { + //std::cout << "header contains Q_OBJECT macro"; + notIncludedMocs[headername] = currentMoc; + } + break; + } + } + for(std::list<std::string>::const_iterator ext = headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string privateHeaderName = absPath+basename+"_p"+(*ext); + if (cmsys::SystemTools::FileExists(privateHeaderName.c_str()) + && includedMocs.find(privateHeaderName) == includedMocs.end() + && notIncludedMocs.find(privateHeaderName) == notIncludedMocs.end()) + { + const std::string currentMoc = "moc_" + basename + "_p.cpp"; + const std::string contents = this->ReadAll(privateHeaderName); + if (qObjectRegExp.find(contents)) + { + //std::cout << "header contains Q_OBJECT macro"; + notIncludedMocs[privateHeaderName] = currentMoc; + } + break; + } + } + } + else + { + // 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, else from the + // header. + // Q_OBJECT + if (moc_style || !qObjectRegExp.find(contentsString)) + { + 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); + } + + bool headerFound = false; + for(std::list<std::string>::const_iterator ext = + headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string &sourceFilePath = absPath + basename + (*ext); + if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) + { + headerFound = true; + includedMocs[sourceFilePath] = currentMoc; + notIncludedMocs.erase(sourceFilePath); + break; + } + } + if (!headerFound) + { + // the moc file is in a subdir => look for the header in the + // same subdir + if (currentMoc.find_first_of('/') != std::string::npos) + { + const std::string &filepath = absPath + + cmsys::SystemTools::GetFilenamePath(currentMoc) + + '/' + basename; + + for(std::list<std::string>::const_iterator ext = + headerExtensions.begin(); + ext != headerExtensions.end(); + ++ext) + { + const std::string &sourceFilePath = filepath + (*ext); + if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) + { + headerFound = true; + includedMocs[sourceFilePath] = currentMoc; + notIncludedMocs.erase(sourceFilePath); + break; + } + } + if (!headerFound) + { + std::cerr << "AUTOMOC: The file \"" << absFilename + << "\" includes the moc file \"" << currentMoc + << "\", but neither \"" << absPath << basename + << '{' << this->Join(headerExtensions, ',') + << "}\" nor \"" << filepath << '{' + << this->Join(headerExtensions, ',') << '}' + << "\" exist." << std::endl; + ::exit(EXIT_FAILURE); + } + } + else + { + std::cerr << "AUTOMOC: The file \"" << absFilename + << "\" includes the moc file \"" << currentMoc + << "\", but \"" << absPath << basename << '{' + << this->Join(headerExtensions, ',') << '}' + << "\" does not exist." << std::endl; + ::exit(EXIT_FAILURE); + } + } + } + else + { + includedMocs[absFilename] = currentMoc; + notIncludedMocs.erase(absFilename); + } + matchOffset += mocIncludeRegExp.end(); + } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset)); + } +} + + +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<cmStdString> command; + command.push_back(this->MocExecutable); + for (std::list<std::string>::const_iterator it = this->MocIncludes.begin(); + it != this->MocIncludes.end(); + ++it) + { + command.push_back(*it); + } + for(std::list<std::string>::const_iterator it=this->MocDefinitions.begin(); + it != this->MocDefinitions.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<cmStdString>::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: 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::list<std::string>& lst,char separator) +{ + if (lst.empty()) + { + return ""; + } + + std::string result; + for (std::list<std::string>::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()); + std::stringstream stream; + stream << file.rdbuf(); + file.close(); + return stream.str(); +} diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h new file mode 100644 index 0000000..4fd9041 --- /dev/null +++ b/Source/cmQtAutomoc.h @@ -0,0 +1,66 @@ +#ifndef cmQtAutomoc_h +#define cmQtAutomoc_h + +class cmGlobalGenerator; +class cmMakefile; + +class cmQtAutomoc +{ +public: + cmQtAutomoc(); + bool Run(const char* targetDirectory); + + void SetupAutomocTarget(cmTarget* target); + +private: + cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, + const char* targetDirectory); + + bool ReadAutomocInfoFile(cmMakefile* makefile, + const char* targetDirectory); + bool ReadOldMocDefinitionsFile(cmMakefile* makefile, + const char* targetDirectory); + void WriteOldMocDefinitionsFile(const char* targetDirectory); + + bool RunAutomocQt4(); + bool GenerateMoc(const std::string& sourceFile, + const std::string& mocFileName); + void ParseCppFile(const std::string& absFilename, + std::map<std::string, std::string>& includedMocs, + std::map<std::string, std::string>& notIncludedMocs); + + void Init(); + + std::string Join(const std::list<std::string>& 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 MocDefinitionsStr; + std::string MocIncludesStr; + std::string ProjectBinaryDir; + std::string ProjectSourceDir; + std::string TargetName; + + std::string OldMocDefinitionsStr; + + std::string OutMocCppFilename; + std::list<std::string> MocIncludes; + std::list<std::string> MocDefinitions; + + bool Verbose; + bool ColorOutput; + bool RunMocFailed; + bool GenerateAll; + +}; + +#endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 17a26cc..4969b65 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -115,6 +115,28 @@ cmTarget::cmTarget() void cmTarget::DefineProperties(cmake *cm) { cm->DefineProperty + ("AUTOMOC", cmProperty::TARGET, + "Should the target be processed with automoc (for Qt projects).", + "AUTOMOC is a boolean specifying whether CMake will handle " + "the Qt moc preprocessor automatically, i.e. without having to use " + "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. " + "When this property is set to TRUE, CMake will scan the source files " + "at build time and invoke moc accordingly. " + "If an #include statement like #include \"moc_foo.cpp\" is found, " + "the Q_OBJECT class declaration is expected in the header, and moc is " + "run on the header file. " + "If an #include statement like #include \"foo.moc\" is found, " + "then a Q_OBJECT is expected in the current source file and moc " + "is run on the file itself. " + "Additionally, all header files are parsed for Q_OBJECT macros, " + "and if found, moc is also executed on those files. The resulting " + "moc files, which are not included as shown above in any of the source " + "files are included in a generated <targetname>_automoc.cpp file, " + "which is compiled as part of the target." + "This property is initialized by the value of the variable " + "CMAKE_AUTOMOC if it is set when a target is created."); + + cm->DefineProperty ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET, "Should build tree targets have install tree rpaths.", "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link " @@ -1118,6 +1140,7 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0); this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0); this->SetPropertyDefault("OSX_ARCHITECTURES", 0); + this->SetPropertyDefault("AUTOMOC", 0); // Collect the set of configuration types. std::vector<std::string> configNames; @@ -1420,7 +1443,7 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep) // the fact that the name matched a target was just a coincidence. if(cmSystemTools::FileIsFullPath(dep.c_str())) { - if(t->GetType() >= cmTarget::EXECUTABLE && + if(t->GetType() >= cmTarget::EXECUTABLE && t->GetType() <= cmTarget::MODULE_LIBRARY) { // This is really only for compatibility so we do not need to diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 8cba84c..551b0ad 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -437,7 +437,7 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile* source, (*this->BuildFileStream ) << sep << out; sep = ";"; } - (*this->BuildFileStream ) << ";%(Outputs)</Outputs>\n"; + (*this->BuildFileStream ) << "</Outputs>\n"; } this->WriteString("</CustomBuild>\n", 2); } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 51cc9d4..2b8c718 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -20,6 +20,7 @@ #include "cmCommand.h" #include "cmFileTimeComparison.h" #include "cmGeneratedFileStream.h" +#include "cmQtAutomoc.h" #include "cmSourceFile.h" #include "cmVersion.h" #include "cmTest.h" @@ -182,7 +183,7 @@ cmake::cmake() this->GlobalGenerator = 0; this->ProgressCallback = 0; this->ProgressCallbackClientData = 0; - this->ScriptMode = false; + this->CurrentWorkingMode = NORMAL_MODE; #ifdef CMAKE_BUILD_WITH_CMAKE this->VariableWatch = new cmVariableWatch; @@ -355,6 +356,7 @@ void cmake::RemoveUnscriptableCommands() // Parse the args bool cmake::SetCacheArgs(const std::vector<std::string>& args) { + bool findPackageMode = false; for(unsigned int i=1; i < args.size(); ++i) { std::string arg = args[i]; @@ -482,7 +484,17 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) } this->ReadListFile(args, path.c_str()); } + else if (arg.find("--find-package",0) == 0) + { + findPackageMode = true; + } + } + + if (findPackageMode) + { + return this->FindPackage(args); } + return true; } @@ -513,7 +525,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args, (cmSystemTools::GetCurrentWorkingDirectory().c_str()); lg->GetMakefile()->SetStartDirectory (cmSystemTools::GetCurrentWorkingDirectory().c_str()); - if (this->GetScriptMode()) + if (this->GetWorkingMode() != NORMAL_MODE) { std::string file(cmSystemTools::CollapseFullPath(path)); cmSystemTools::ConvertToUnixSlashes(file); @@ -534,6 +546,111 @@ void cmake::ReadListFile(const std::vector<std::string>& args, } } + +bool cmake::FindPackage(const std::vector<std::string>& args) +{ + // if a generator was not yet created, temporarily create one + cmGlobalGenerator *gg = new cmGlobalGenerator; + gg->SetCMakeInstance(this); + this->SetGlobalGenerator(gg); + + // read in the list file to fill the cache + std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator()); + cmMakefile* mf = lg->GetMakefile(); + mf->SetHomeOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetHomeDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + + mf->SetArgcArgv(args); + + std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake"); + mf->ReadListFile(0, systemFile.c_str()); + + std::string language = mf->GetSafeDefinition("LANGUAGE"); + std::string mode = mf->GetSafeDefinition("MODE"); + std::string packageName = mf->GetSafeDefinition("NAME"); + bool packageFound = mf->IsOn("PACKAGE_FOUND"); + bool quiet = mf->IsOn("PACKAGE_QUIET"); + + if (!packageFound) + { + if (!quiet) + { + printf("%s not found.\n", packageName.c_str()); + } + } + else if (mode == "EXIST") + { + if (!quiet) + { + printf("%s found.\n", packageName.c_str()); + } + } + else if (mode == "COMPILE") + { + std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); + std::vector<std::string> includeDirs; + cmSystemTools::ExpandListArgument(includes, includeDirs); + for(std::vector<std::string>::const_iterator dirIt=includeDirs.begin(); + dirIt != includeDirs.end(); + ++dirIt) + { + mf->AddIncludeDirectory(dirIt->c_str(), false); + } + + std::string includeFlags = lg->GetIncludeFlags(language.c_str(), false); + std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); + printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); + } + else if (mode == "LINK") + { + const char* targetName = "dummy"; + std::vector<std::string> srcs; + cmTarget* tgt = mf->AddExecutable(targetName, srcs, true); + tgt->SetProperty("LINKER_LANGUAGE", language.c_str()); + + std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES"); + std::vector<std::string> libList; + cmSystemTools::ExpandListArgument(libs, libList); + for(std::vector<std::string>::const_iterator libIt=libList.begin(); + libIt != libList.end(); + ++libIt) + { + mf->AddLinkLibraryForTarget(targetName, libIt->c_str(), + cmTarget::GENERAL); + } + + + std::string linkLibs; + std::string flags; + std::string linkFlags; + lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt); + + printf("%s\n", linkLibs.c_str() ); + +/* if ( use_win32 ) + { + tgt->SetProperty("WIN32_EXECUTABLE", "ON"); + } + if ( use_macbundle) + { + tgt->SetProperty("MACOSX_BUNDLE", "ON"); + }*/ + } + + // free generic one if generated +// this->SetGlobalGenerator(0); // setting 0-pointer is not possible +// delete gg; // this crashes inside the cmake instance + + return packageFound; +} + + // Parse the args void cmake::SetArgs(const std::vector<std::string>& args, bool directoriesSetBefore) @@ -606,6 +723,11 @@ void cmake::SetArgs(const std::vector<std::string>& args, // skip for now i++; } + else if(arg.find("--find-package",0) == 0) + { + // skip for now + i++; + } else if(arg.find("-Wno-dev",0) == 0) { // skip for now @@ -1572,6 +1694,12 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args) { return cmake::ExecuteEchoColor(args); } + else if (args[1] == "cmake_automoc") + { + cmQtAutomoc automoc; + automoc.Run(args[2].c_str()); + return 0; + } #endif // Tar files @@ -2028,7 +2156,7 @@ int cmake::ActualConfigure() this->CleanupCommandsAndMacros(); int res = 0; - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { res = this->DoPreConfigureChecks(); } @@ -2216,7 +2344,7 @@ int cmake::ActualConfigure() this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR"); } // only save the cache if there were no fatal errors - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { this->CacheManager->SaveCache(this->GetHomeOutputDirectory()); } @@ -2282,7 +2410,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) // set the cmake command this->CMakeCommand = args[0]; - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { // load the cache if(this->LoadCache() < 0) @@ -2303,7 +2431,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) } // In script mode we terminate after running the script. - if(this->ScriptMode) + if(this->GetWorkingMode() != NORMAL_MODE) { if(cmSystemTools::GetErrorOccuredFlag()) { @@ -2349,7 +2477,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) this->SetStartDirectory(this->GetHomeDirectory()); this->SetStartOutputDirectory(this->GetHomeOutputDirectory()); int ret = this->Configure(); - if (ret || this->ScriptMode) + if (ret || this->GetWorkingMode() != NORMAL_MODE) { #if defined(CMAKE_HAVE_VS_GENERATORS) if(!this->VSSolutionFile.empty() && this->GlobalGenerator) @@ -2919,6 +3047,13 @@ const char* cmake::GetCPackCommand() return this->CPackCommand.c_str(); } + +const char* cmake::GetCMakeCommand() +{ + return this->CMakeCommand.c_str(); +} + + void cmake::MarkCliAsUsed(const std::string& variable) { this->UsedCliVariables[variable] = true; diff --git a/Source/cmake.h b/Source/cmake.h index f2a2ae3..ae56e85 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -64,6 +64,25 @@ class cmake WARNING, LOG }; + + + /** Describes the working modes of cmake. + * NORMAL_MODE: cmake runs to create project files + * SCRIPT_MODE: in script mode there is no generator and no cache. Also, + * language are not enabled, so add_executable and things do + * not do anything. Started by using -P + * FIND_PACKAGE_MODE: cmake runs in pkg-config like mode, i.e. it just + * searches for a package and prints the results to stdout. + * This is similar to SCRIPT_MODE, but commands like + * add_library() work too, since they may be used e.g. in + * exported target files. Started via --find-package + */ + enum WorkingMode + { + NORMAL_MODE, + SCRIPT_MODE, + FIND_PACKAGE_MODE + }; typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap; ///! construct an instance of cmake @@ -274,13 +293,8 @@ class cmake ///! Do all the checks before running configure int DoPreConfigureChecks(); - /** - * Set and get the script mode option. In script mode there is no - * generator and no cache. Also, language are not enabled, so - * add_executable and things do not do anything. - */ - void SetScriptMode(bool mode) { this->ScriptMode = mode; } - bool GetScriptMode() { return this->ScriptMode; } + void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; } + WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; } ///! Debug the try compile stuff by not delelting the files bool GetDebugTryCompile(){return this->DebugTryCompile;} @@ -301,6 +315,7 @@ class cmake */ const char* GetCTestCommand(); const char* GetCPackCommand(); + const char* GetCMakeCommand(); // Do we want debug output during the cmake run. bool GetDebugOutput() { return this->DebugOutput; } @@ -408,6 +423,7 @@ protected: ///! read in a cmake list file to initialize the cache void ReadListFile(const std::vector<std::string>& args, const char *path); + bool FindPackage(const std::vector<std::string>& args); ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file. /// If it is set, truncate it to 50kb @@ -461,7 +477,7 @@ private: void* ProgressCallbackClientData; bool Verbose; bool InTryCompile; - bool ScriptMode; + WorkingMode CurrentWorkingMode; bool DebugOutput; bool Trace; bool WarnUninitialized; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 1fe9e82..9f213a5 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -103,6 +103,11 @@ static const char * cmDocumentationOptions[][3] = "No configure or generate step is performed and the cache is not" " modified. If variables are defined using -D, this must be done " "before the -P argument."}, + {"--find-package", "Run in pkg-config like mode.", + "Search a package using find_package() and print the resulting flags " + "to stdout. This can be used to use cmake instead of pkg-config to find " + "installed libraries in plain Makefile-based projects or in " + "autoconf-based projects (via share/aclocal/cmake.m4)."}, {"--graphviz=[file]", "Generate graphviz of dependencies.", "Generate a graphviz input file that will contain all the library and " "executable dependencies in the project."}, @@ -434,7 +439,7 @@ int do_cmake(int ac, char** av) bool list_all_cached = false; bool list_help = false; bool view_only = false; - bool script_mode = false; + cmake::WorkingMode workingMode = cmake::NORMAL_MODE; std::vector<std::string> args; for(int i =0; i < ac; ++i) { @@ -482,12 +487,18 @@ int do_cmake(int ac, char** av) } else { - script_mode = true; + workingMode = cmake::SCRIPT_MODE; args.push_back(av[i]); i++; args.push_back(av[i]); } } + else if (!command && strncmp(av[i], "--find-package", + strlen("--find-package")) == 0) + { + workingMode = cmake::FIND_PACKAGE_MODE; + args.push_back(av[i]); + } else { args.push_back(av[i]); @@ -512,7 +523,7 @@ int do_cmake(int ac, char** av) cmake cm; cmSystemTools::SetErrorCallback(cmakemainErrorCallback, (void *)&cm); cm.SetProgressCallback(cmakemainProgressCallback, (void *)&cm); - cm.SetScriptMode(script_mode); + cm.SetWorkingMode(workingMode); int res = cm.Run(args, view_only); if ( list_cached || list_all_cached ) diff --git a/Source/kwsys/kwsysDateStamp.cmake b/Source/kwsys/kwsysDateStamp.cmake index 15abe5a..2644ba5 100644 --- a/Source/kwsys/kwsysDateStamp.cmake +++ b/Source/kwsys/kwsysDateStamp.cmake @@ -18,4 +18,4 @@ SET(KWSYS_DATE_STAMP_YEAR 2011) SET(KWSYS_DATE_STAMP_MONTH 08) # KWSys version date day component. Format is DD. -SET(KWSYS_DATE_STAMP_DAY 23) +SET(KWSYS_DATE_STAMP_DAY 25) |