diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-10-11 12:26:56 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-10-24 09:50:58 (GMT) |
commit | 85b3d6e73d1d5620229c7fc67a705fd50c8bcff0 (patch) | |
tree | fe8938859b9d1ea0c465db587e664e3908e9eb8e | |
parent | ca124a15150b5f88a9dcd9edfc4f61cf473efc64 (diff) | |
download | CMake-85b3d6e73d1d5620229c7fc67a705fd50c8bcff0.zip CMake-85b3d6e73d1d5620229c7fc67a705fd50c8bcff0.tar.gz CMake-85b3d6e73d1d5620229c7fc67a705fd50c8bcff0.tar.bz2 |
Extract an SetupAutoMocTarget method.
This class will soon gain methods for autouic and autorcc.
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 104 | ||||
-rw-r--r-- | 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<std::string, std::string> configIncludes; + std::map<std::string, std::string> 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<std::string, std::string>::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<std::string, std::string>::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<std::string, std::string> &configIncludes, + std::map<std::string, std::string> &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<std::string, std::string> configIncludes; - std::map<std::string, std::string> configDefines; - for (std::vector<std::string>::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<std::string, std::string>::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<std::string, std::string>::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<std::string, std::string> &configIncludes, + std::map<std::string, std::string> &configDefines); + cmGlobalGenerator* CreateGlobalGenerator(cmake* cm, const char* targetDirectory); |