From db431ecfe33dbfa9eb43e4edd72ebc35b2c7c563 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 23 Feb 2017 19:44:29 +0100 Subject: Autogen: Merge FindInIncludeDirectories into FindIncludeFile --- Source/cmQtAutoGenerators.cxx | 46 +++++++++++++++++++------------------------ Source/cmQtAutoGenerators.h | 5 ++--- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index e7e456a..902e872 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -733,9 +733,8 @@ void cmQtAutoGenerators::MocFindDepends( const std::string match = filter.regExp.match(1); if (!match.empty()) { // Find the dependency file - const std::string incFile = - this->FindIncludedFile(absFilename, match); - if (!incFile.empty()) { + std::string incFile; + if (this->FindIncludedFile(incFile, absFilename, match)) { mocDepends[absFilename].insert(incFile); if (this->Verbose) { this->LogInfo("AutoMoc: Found dependency:\n " + @@ -1780,40 +1779,35 @@ std::string cmQtAutoGenerators::FindMocHeader(const std::string& basePath, return header; } -std::string cmQtAutoGenerators::FindIncludedFile( - const std::string& sourceFile, const std::string& includeString) const +bool cmQtAutoGenerators::FindIncludedFile( + std::string& absFile, const std::string& sourceFile, + const std::string& includeString) const { + bool success = false; // Search in vicinity of the source { std::string testPath = cmSystemTools::GetFilenamePath(sourceFile); testPath += '/'; testPath += includeString; if (cmsys::SystemTools::FileExists(testPath.c_str())) { - return cmsys::SystemTools::GetRealPath(testPath); + absFile = cmsys::SystemTools::GetRealPath(testPath); + success = true; } } - // Search globally - return FindInIncludeDirectories(includeString); -} - -/** - * @brief Tries to find a file in the include directories - * @return True on success - */ -std::string cmQtAutoGenerators::FindInIncludeDirectories( - const std::string& includeString) const -{ - std::string res; - for (std::vector::const_iterator iit = - this->MocIncludePaths.begin(); - iit != this->MocIncludePaths.end(); ++iit) { - const std::string fullPath = ((*iit) + '/' + includeString); - if (cmsys::SystemTools::FileExists(fullPath.c_str())) { - res = cmsys::SystemTools::GetRealPath(fullPath); - break; + // Search in include directories + if (!success) { + for (std::vector::const_iterator iit = + this->MocIncludePaths.begin(); + iit != this->MocIncludePaths.end(); ++iit) { + const std::string fullPath = ((*iit) + '/' + includeString); + if (cmsys::SystemTools::FileExists(fullPath.c_str())) { + absFile = cmsys::SystemTools::GetRealPath(fullPath); + success = true; + break; + } } } - return res; + return success; } /** diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index e4b7f60..b83edf7 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -147,9 +147,8 @@ private: std::string FindMocHeader(const std::string& basePath, const std::string& baseName, const std::string& subDir) const; - std::string FindIncludedFile(const std::string& sourceFile, - const std::string& includeString) const; - std::string FindInIncludeDirectories(const std::string& includeString) const; + bool FindIncludedFile(std::string& absFile, const std::string& sourceFile, + const std::string& includeString) const; // - Target names std::string OriginTargetName; -- cgit v0.12 From 110c1bf475e2d1df27189936a1e7b66b48afb5a9 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 24 Feb 2017 11:41:50 +0100 Subject: Autogen: Add subDirPrefix function --- Source/cmQtAutoGenerators.cxx | 28 +++++++++++++++------------- Source/cmQtAutoGenerators.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 902e872..ea7fe0f 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -94,6 +94,15 @@ static void SettingWrite(std::ostream& ostr, const char* key, } } +std::string subDirPrefix(const std::string& fileName) +{ + std::string res(cmsys::SystemTools::GetFilenamePath(fileName)); + if (!res.empty()) { + res += '/'; + } + return res; +} + static bool FileNameIsUnique(const std::string& filePath, const std::map& fileMap) { @@ -845,8 +854,7 @@ bool cmQtAutoGenerators::MocParseSourceContent( this->LogInfo("AutoMoc: Checking " + absFilename); } - const std::string scannedFileAbsPath = - cmsys::SystemTools::GetFilenamePath(absFilename) + '/'; + const std::string scannedFileAbsPath = subDirPrefix(absFilename); const std::string scannedFileBasename = cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); @@ -865,13 +873,9 @@ bool cmQtAutoGenerators::MocParseSourceContent( while (this->RegExpMocInclude.find(contentChars)) { const std::string incString = this->RegExpMocInclude.match(1); // Basename of the moc include + const std::string incSubDir(subDirPrefix(incString)); const std::string incBasename = cmsys::SystemTools::GetFilenameWithoutLastExtension(incString); - std::string incSubDir; - if (incString.find_first_of('/') != std::string::npos) { - incSubDir = cmsys::SystemTools::GetFilenamePath(incString); - incSubDir += '/'; - } // If the moc include is of the moc_foo.cpp style we expect // the Q_OBJECT class declaration in a header file. @@ -1055,8 +1059,7 @@ void cmQtAutoGenerators::SearchHeadersForSourceFile( { std::string basepaths[2]; { - std::string bpath = cmsys::SystemTools::GetFilenamePath(absFilename); - bpath += '/'; + std::string bpath = subDirPrefix(absFilename); bpath += cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename); // search for default header files and private header files basepaths[0] = bpath; @@ -1234,14 +1237,14 @@ bool cmQtAutoGenerators::MocGenerateAll( */ bool cmQtAutoGenerators::MocGenerateFile( const std::string& sourceFile, const std::string& mocFileName, - const std::string& subDirPrefix, + const std::string& subDir, const std::map >& mocDepends) { bool mocGenerated = false; bool generateMoc = this->GenerateAllMoc; const std::string mocFileRel = - this->AutogenBuildSubDir + subDirPrefix + mocFileName; + this->AutogenBuildSubDir + subDir + mocFileName; const std::string mocFileAbs = this->CurrentBinaryDir + mocFileRel; if (!generateMoc) { @@ -1786,8 +1789,7 @@ bool cmQtAutoGenerators::FindIncludedFile( bool success = false; // Search in vicinity of the source { - std::string testPath = cmSystemTools::GetFilenamePath(sourceFile); - testPath += '/'; + std::string testPath = subDirPrefix(sourceFile); testPath += includeString; if (cmsys::SystemTools::FileExists(testPath.c_str())) { absFile = cmsys::SystemTools::GetRealPath(testPath); diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index b83edf7..f9b9083 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -107,7 +107,7 @@ private: const std::map >& mocDepends); bool MocGenerateFile( const std::string& sourceFile, const std::string& mocFileName, - const std::string& subDirPrefix, + const std::string& subDir, const std::map >& mocDepends); // - Uic file generation -- cgit v0.12 From 1cdf7c1be24f87e2854204aa5bc7de4dc22af1a3 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 23 Feb 2017 19:35:48 +0100 Subject: Autogen: Add AUTOUIC_SEARCH_PATHS support Closes #15227 --- Modules/AutogenInfo.cmake.in | 1 + Source/cmQtAutoGeneratorInitializer.cxx | 13 +++ Source/cmQtAutoGenerators.cxx | 138 ++++++++++++++++++++------------ Source/cmQtAutoGenerators.h | 3 + Source/cmTarget.cxx | 1 + 5 files changed, 107 insertions(+), 49 deletions(-) diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index fc5024f..f8ffe91 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -26,6 +26,7 @@ set(AM_UIC_SKIP @_uic_skip@) 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_UIC_SEARCH_PATHS @_uic_search_paths@) # RCC settings set(AM_RCC_SOURCES @_rcc_files@ ) set(AM_RCC_INPUTS @_rcc_inputs@) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index de18265..5460f73 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -306,6 +306,19 @@ static void UicSetupAutoTarget( AddDefinitionEscaped(makefile, "_uic_skip", uicSkipList); + // Uic search paths + { + std::vector uicSearchPaths; + cmSystemTools::ExpandListArgument( + GetSafeProperty(target, "AUTOUIC_SEARCH_PATHS"), uicSearchPaths); + const std::string srcDir = makefile->GetCurrentSourceDirectory(); + for (std::vector::iterator it = uicSearchPaths.begin(); + it != uicSearchPaths.end(); ++it) { + *it = cmSystemTools::CollapseFullPath(*it, srcDir); + } + AddDefinitionEscaped(makefile, "_uic_search_paths", uicSearchPaths); + } + // Uic target options { std::string _uic_opts; diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ea7fe0f..d9e95ff 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -412,19 +412,23 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"), uicFilesVec); cmSystemTools::ExpandListArgument( makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS"), uicOptionsVec); - if (uicFilesVec.size() != uicOptionsVec.size()) { + // Compare list sizes + if (uicFilesVec.size() == uicOptionsVec.size()) { + for (std::vector::iterator fileIt = uicFilesVec.begin(), + optionIt = uicOptionsVec.begin(); + fileIt != uicFilesVec.end(); ++fileIt, ++optionIt) { + cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";"); + this->UicOptions[*fileIt] = *optionIt; + } + } else { this->LogError( "AutoGen: Error: Uic files/options lists size missmatch in: " + filename); 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; - } } + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_UIC_SEARCH_PATHS"), this->UicSearchPaths); // - Rcc cmSystemTools::ExpandListArgument( @@ -831,12 +835,7 @@ void cmQtAutoGenerators::UicParseContent( const char* contentChars = contentText.c_str(); if (strstr(contentChars, "ui_") != CM_NULLPTR) { while (this->RegExpUicInclude.find(contentChars)) { - const std::string currentUi = this->RegExpUicInclude.match(1); - const 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 - uisIncluded[absFilename].push_back(basename.substr(3)); + uisIncluded[absFilename].push_back(this->RegExpUicInclude.match(1)); contentChars += this->RegExpUicInclude.end(); } } @@ -1325,6 +1324,36 @@ bool cmQtAutoGenerators::MocGenerateFile( return mocGenerated; } +bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, + const std::string& sourceFile, + const std::string& includeString) +{ + bool success = false; + // Search in vicinity of the source + { + std::string testPath = subDirPrefix(sourceFile); + testPath += includeString; + if (cmsys::SystemTools::FileExists(testPath.c_str())) { + absFile = cmsys::SystemTools::GetRealPath(testPath); + success = true; + } + } + // Search in include directories + if (!success) { + for (std::vector::const_iterator iit = + this->UicSearchPaths.begin(); + iit != this->UicSearchPaths.end(); ++iit) { + const std::string fullPath = ((*iit) + '/' + includeString); + if (cmsys::SystemTools::FileExists(fullPath.c_str())) { + absFile = cmsys::SystemTools::GetRealPath(fullPath); + success = true; + break; + } + } + } + return success; +} + bool cmQtAutoGenerators::UicGenerateAll( const std::map >& uisIncluded) { @@ -1333,46 +1362,57 @@ bool cmQtAutoGenerators::UicGenerateAll( } // single map with input / output names - std::map > uiGenMap; - std::map testMap; - for (std::map >::const_iterator it = - uisIncluded.begin(); - it != uisIncluded.end(); ++it) { - // source file path - std::string sourcePath = cmsys::SystemTools::GetFilenamePath(it->first); - sourcePath += '/'; - // insert new map for source file an use new reference - uiGenMap[it->first] = std::map(); - std::map& sourceMap = uiGenMap[it->first]; - for (std::vector::const_iterator sit = it->second.begin(); - sit != it->second.end(); ++sit) { - const std::string& uiFileName = *sit; - const std::string uiInputFile = sourcePath + uiFileName + ".ui"; - const std::string uiOutputFile = "ui_" + uiFileName + ".h"; - sourceMap[uiInputFile] = uiOutputFile; - testMap[uiInputFile] = uiOutputFile; - } - } - - // look for name collisions + std::map > sourceGenMap; { - std::multimap collisions; - if (this->NameCollisionTest(testMap, collisions)) { - std::ostringstream ost; - ost << "AutoUic: Error: The same ui_NAME.h file will be generated " - "from different sources.\n" - "To avoid this error rename the source files.\n"; - this->LogErrorNameCollision(ost.str(), collisions); - return false; + // Collision lookup map + std::map testMap; + // Compile maps + for (std::map >::const_iterator sit = + uisIncluded.begin(); + sit != uisIncluded.end(); ++sit) { + const std::string& source(sit->first); + const std::vector& sourceIncs(sit->second); + // insert new source/destination map + std::map& uiGenMap = sourceGenMap[source]; + for (std::vector::const_iterator uit = sourceIncs.begin(); + uit != sourceIncs.end(); ++uit) { + // Remove ui_ from the begin filename by substr() + const std::string uiBasePath = subDirPrefix(*uit); + const std::string uiBaseName = + cmsys::SystemTools::GetFilenameWithoutLastExtension(*uit).substr(3); + const std::string searchFileName = uiBasePath + uiBaseName + ".ui"; + std::string uiInputFile; + if (UicFindIncludedFile(uiInputFile, source, searchFileName)) { + std::string uiOutputFile = uiBasePath + "ui_" + uiBaseName + ".h"; + cmSystemTools::ReplaceString(uiOutputFile, "..", "__"); + uiGenMap[uiInputFile] = uiOutputFile; + testMap[uiInputFile] = uiOutputFile; + } else { + this->LogError("AutoUic: Error: " + Quoted(sit->first) + + "\nCould not find " + Quoted(searchFileName)); + return false; + } + } + } + // look for name collisions + { + std::multimap collisions; + if (this->NameCollisionTest(testMap, collisions)) { + std::ostringstream ost; + ost << "AutoUic: Error: The same ui_NAME.h file will be generated " + "from different sources.\n" + "To avoid this error rename the source files.\n"; + this->LogErrorNameCollision(ost.str(), collisions); + return false; + } } } - testMap.clear(); // generate ui files for (std::map >::const_iterator it = - uiGenMap.begin(); - it != uiGenMap.end(); ++it) { + sourceGenMap.begin(); + it != sourceGenMap.end(); ++it) { for (std::map::const_iterator sit = it->second.begin(); sit != it->second.end(); ++sit) { @@ -1415,15 +1455,15 @@ bool cmQtAutoGenerators::UicGenerateFile(const std::string& realName, std::vector cmd; cmd.push_back(this->UicExecutable); { - std::vector opts = this->UicTargetOptions; + std::vector allOpts = this->UicTargetOptions; std::map::const_iterator optionIt = this->UicOptions.find(uiInputFile); if (optionIt != this->UicOptions.end()) { std::vector fileOpts; cmSystemTools::ExpandListArgument(optionIt->second, fileOpts); - UicMergeOptions(opts, fileOpts, (this->QtMajorVersion == "5")); + UicMergeOptions(allOpts, fileOpts, (this->QtMajorVersion == "5")); } - cmd.insert(cmd.end(), opts.begin(), opts.end()); + cmd.insert(cmd.end(), allOpts.begin(), allOpts.end()); } cmd.push_back("-o"); cmd.push_back(uicFileAbs); diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index f9b9083..46c86ff 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -111,6 +111,8 @@ private: const std::map >& mocDepends); // - Uic file generation + bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, + const std::string& includeString); bool UicGenerateAll( const std::map >& includedUis); bool UicGenerateFile(const std::string& realName, @@ -184,6 +186,7 @@ private: std::vector UicSkipList; std::vector UicTargetOptions; std::map UicOptions; + std::vector UicSearchPaths; // - Rcc std::vector RccSources; std::map RccOptions; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0f3d91b..c360c19 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -248,6 +248,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", CM_NULLPTR); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR); this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR); + this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", CM_NULLPTR); this->SetPropertyDefault("AUTORCC_OPTIONS", CM_NULLPTR); this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", CM_NULLPTR); this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", CM_NULLPTR); -- cgit v0.12 From 6d7c02db34a3a8ca9cf14fa936b5835014c46739 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Thu, 23 Feb 2017 21:36:10 +0100 Subject: Autogen: Add AUTOUIC_SEARCH_PATHS test --- Tests/QtAutogen/CMakeLists.txt | 4 ++++ Tests/QtAutogen/uicInclude/CMakeLists.txt | 8 ++++++++ Tests/QtAutogen/uicInclude/PageC.ui | 24 ++++++++++++++++++++++++ Tests/QtAutogen/uicInclude/dirA/PageA.ui | 24 ++++++++++++++++++++++++ Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui | 24 ++++++++++++++++++++++++ Tests/QtAutogen/uicInclude/main.cpp | 10 ++++++++++ Tests/QtAutogen/uicInclude/main.hpp | 6 ++++++ 7 files changed, 100 insertions(+) create mode 100644 Tests/QtAutogen/uicInclude/CMakeLists.txt create mode 100644 Tests/QtAutogen/uicInclude/PageC.ui create mode 100644 Tests/QtAutogen/uicInclude/dirA/PageA.ui create mode 100644 Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui create mode 100644 Tests/QtAutogen/uicInclude/main.cpp create mode 100644 Tests/QtAutogen/uicInclude/main.hpp diff --git a/Tests/QtAutogen/CMakeLists.txt b/Tests/QtAutogen/CMakeLists.txt index dc631c6..4960472 100644 --- a/Tests/QtAutogen/CMakeLists.txt +++ b/Tests/QtAutogen/CMakeLists.txt @@ -287,5 +287,9 @@ if (NOT QT_TEST_VERSION STREQUAL 4) endif() # -- Test +# Tests various .ui include directories +add_subdirectory(uicInclude) + +# -- Test # Complex test case add_subdirectory(complex) diff --git a/Tests/QtAutogen/uicInclude/CMakeLists.txt b/Tests/QtAutogen/uicInclude/CMakeLists.txt new file mode 100644 index 0000000..f62ebb0 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/CMakeLists.txt @@ -0,0 +1,8 @@ +# Test moc include patterns + +set(CMAKE_AUTOUIC_SEARCH_PATHS "dirA") + +add_executable(uicInclude main.cpp) +target_link_libraries(uicInclude ${QT_LIBRARIES}) +set_target_properties(uicInclude PROPERTIES AUTOUIC ON) +set_property(TARGET uicInclude APPEND PROPERTY AUTOUIC_SEARCH_PATHS "dirB") diff --git a/Tests/QtAutogen/uicInclude/PageC.ui b/Tests/QtAutogen/uicInclude/PageC.ui new file mode 100644 index 0000000..bb2fb5e --- /dev/null +++ b/Tests/QtAutogen/uicInclude/PageC.ui @@ -0,0 +1,24 @@ + + + PageC + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/dirA/PageA.ui b/Tests/QtAutogen/uicInclude/dirA/PageA.ui new file mode 100644 index 0000000..dd81802 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirA/PageA.ui @@ -0,0 +1,24 @@ + + + PageA + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui b/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui new file mode 100644 index 0000000..fa6dfa6 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui @@ -0,0 +1,24 @@ + + + PageB + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/main.cpp b/Tests/QtAutogen/uicInclude/main.cpp new file mode 100644 index 0000000..4ca66a7 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/main.cpp @@ -0,0 +1,10 @@ + +#include "main.hpp" + +int main(int argv, char** args) +{ + return 0; +} + +#include "sub/ui_PageB.h" +#include "ui_PageC.h" diff --git a/Tests/QtAutogen/uicInclude/main.hpp b/Tests/QtAutogen/uicInclude/main.hpp new file mode 100644 index 0000000..58ddc26 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/main.hpp @@ -0,0 +1,6 @@ +#ifndef MAIN_HPP +#define MAIN_HPP + +#include "ui_PageA.h" + +#endif -- cgit v0.12 From 36fa535d922f891deed4333b30ddbf429291ca06 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 24 Feb 2017 23:13:39 +0100 Subject: Autogen: Add AUTOUIC_SEARCH_PATHS documentation --- Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-qt.7.rst | 4 +++- Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/AUTOUIC.rst | 9 +++++++-- Help/prop_tgt/AUTOUIC_OPTIONS.rst | 2 +- Help/prop_tgt/AUTOUIC_SEARCH_PATHS.rst | 12 ++++++++++++ Help/variable/CMAKE_AUTOUIC_SEARCH_PATHS.rst | 11 +++++++++++ 7 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 Help/prop_tgt/AUTOUIC_SEARCH_PATHS.rst create mode 100644 Help/variable/CMAKE_AUTOUIC_SEARCH_PATHS.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index f31b0f8..3db2e41 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -121,6 +121,7 @@ Properties on Targets /prop_tgt/AUTOMOC /prop_tgt/AUTOUIC /prop_tgt/AUTOUIC_OPTIONS + /prop_tgt/AUTOUIC_SEARCH_PATHS /prop_tgt/AUTORCC /prop_tgt/AUTORCC_OPTIONS /prop_tgt/BINARY_DIR diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst index 3b9931e..3b95b05 100644 --- a/Help/manual/cmake-qt.7.rst +++ b/Help/manual/cmake-qt.7.rst @@ -104,7 +104,9 @@ be run, and to create rules to execute ``uic`` at the appropriate time. If a preprocessor ``#include`` directive is found which matches ``ui_.h``, and a ``.ui`` file exists, then ``uic`` will -be executed to generate the appropriate file. +be executed to generate the appropriate file. The ``.ui`` file is +searched for first in the vicinity of including file and afterwards in the +optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target. The generated generated ``ui_*.h`` files are placed in the ``/_autogen/include`` directory which is diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 259d87b..73fd73c 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -263,6 +263,7 @@ Variables that Control the Build /variable/CMAKE_AUTORCC_OPTIONS /variable/CMAKE_AUTOUIC /variable/CMAKE_AUTOUIC_OPTIONS + /variable/CMAKE_AUTOUIC_SEARCH_PATHS /variable/CMAKE_BUILD_RPATH /variable/CMAKE_BUILD_WITH_INSTALL_NAME_DIR /variable/CMAKE_BUILD_WITH_INSTALL_RPATH diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst index fbf24c3..91d95e5 100644 --- a/Help/prop_tgt/AUTOUIC.rst +++ b/Help/prop_tgt/AUTOUIC.rst @@ -10,8 +10,13 @@ Qt4 and Qt5 are supported. When this property is ``ON``, 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. +``#include "ui_foo.h"`` is found in ``source.cpp``, a ``foo.ui`` file is +searched for first in the vicinity of ``source.cpp`` and afterwards in the +optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target. +``uic`` is run on the ``foo.ui`` file to generate ``ui_foo.h`` in the directory +``/_autogen/include``, +which is added to the target's :prop_tgt:`INCLUDE_DIRECTORIES` automatically. + This property is initialized by the value of the :variable:`CMAKE_AUTOUIC` variable if it is set when a target is created. diff --git a/Help/prop_tgt/AUTOUIC_OPTIONS.rst b/Help/prop_tgt/AUTOUIC_OPTIONS.rst index dc3bee5..9fb042e 100644 --- a/Help/prop_tgt/AUTOUIC_OPTIONS.rst +++ b/Help/prop_tgt/AUTOUIC_OPTIONS.rst @@ -1,7 +1,7 @@ AUTOUIC_OPTIONS --------------- -Additional options for uic when using :prop_tgt:`AUTOUIC` +Additional options for ``uic`` when using :prop_tgt:`AUTOUIC` This property holds additional command line options which will be used when ``uic`` is executed during the build via :prop_tgt:`AUTOUIC`, i.e. it is diff --git a/Help/prop_tgt/AUTOUIC_SEARCH_PATHS.rst b/Help/prop_tgt/AUTOUIC_SEARCH_PATHS.rst new file mode 100644 index 0000000..96d9f89 --- /dev/null +++ b/Help/prop_tgt/AUTOUIC_SEARCH_PATHS.rst @@ -0,0 +1,12 @@ +AUTOUIC_SEARCH_PATHS +-------------------- + +Search path list used by :prop_tgt:`AUTOUIC` to find included +``.ui`` files. + +This property is initialized by the value of the +:variable:`CMAKE_AUTOUIC_SEARCH_PATHS` variable if it is set +when a target is created. Otherwise it is empty. + +See the :manual:`cmake-qt(7)` manual for more information on using CMake +with Qt. diff --git a/Help/variable/CMAKE_AUTOUIC_SEARCH_PATHS.rst b/Help/variable/CMAKE_AUTOUIC_SEARCH_PATHS.rst new file mode 100644 index 0000000..aa132bf --- /dev/null +++ b/Help/variable/CMAKE_AUTOUIC_SEARCH_PATHS.rst @@ -0,0 +1,11 @@ +CMAKE_AUTOUIC_SEARCH_PATHS +-------------------------- + +Search path list used by :variable:`CMAKE_AUTOUIC` to find included +``.ui`` files. + +This variable is used to initialize the :prop_tgt:`AUTOUIC_SEARCH_PATHS` +property on all the targets. See that target property for additional +information. + +By default it is empty. -- cgit v0.12 From 5adf22bbd23185808dc3295766b25b4aa15e1612 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Sat, 25 Feb 2017 14:37:09 +0100 Subject: Autogen: Add AUTOUIC_SEARCH_PATHS release notes --- Help/release/dev/Autogen_uic_paths.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Help/release/dev/Autogen_uic_paths.rst diff --git a/Help/release/dev/Autogen_uic_paths.rst b/Help/release/dev/Autogen_uic_paths.rst new file mode 100644 index 0000000..0893194 --- /dev/null +++ b/Help/release/dev/Autogen_uic_paths.rst @@ -0,0 +1,10 @@ +AutoGen uic paths +----------------- + +* Variable :variable:`CMAKE_AUTOUIC_SEARCH_PATHS` was introduced to + allow :variable:`CMAKE_AUTOUIC` to search for ``foo.ui`` in more + places than the vicinity of the ``ui_foo.h`` including file. + +* The new target property :prop_tgt:`AUTOUIC_SEARCH_PATHS` was introduced to + allow :prop_tgt:`AUTOUIC` to search for ``foo.ui`` in more + places than the vicinity of the ``ui_foo.h`` including file. -- cgit v0.12 From 662ad240db50792361aa042c60559c1c48042a6b Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 24 Feb 2017 12:11:55 +0100 Subject: Autogen: Rename and merge moc related methods --- Source/cmQtAutoGenerators.cxx | 52 +++++++++++++++---------------------------- Source/cmQtAutoGenerators.h | 12 +++++----- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index d9e95ff..c4ae318 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -740,6 +740,7 @@ void cmQtAutoGenerators::MocFindDepends( // regular expression check if (contentText.find(filter.key) != std::string::npos) { // Run regular expression check loop + const std::string sourcePath = subDirPrefix(absFilename); const char* contentChars = contentText.c_str(); while (filter.regExp.find(contentChars)) { // Evaluate match @@ -747,7 +748,7 @@ void cmQtAutoGenerators::MocFindDepends( if (!match.empty()) { // Find the dependency file std::string incFile; - if (this->FindIncludedFile(incFile, absFilename, match)) { + if (this->MocFindIncludedFile(incFile, sourcePath, match)) { mocDepends[absFilename].insert(incFile); if (this->Verbose) { this->LogInfo("AutoMoc: Found dependency:\n " + @@ -886,7 +887,7 @@ bool cmQtAutoGenerators::MocParseSourceContent( // Remove the moc_ part const std::string incRealBasename = incBasename.substr(4); const std::string headerToMoc = - this->FindMocHeader(scannedFileAbsPath, incRealBasename, incSubDir); + this->MocFindHeader(scannedFileAbsPath, incSubDir + incRealBasename); if (!headerToMoc.empty()) { // Register moc job mocsIncluded[headerToMoc] = incString; @@ -919,7 +920,7 @@ bool cmQtAutoGenerators::MocParseSourceContent( } else { // In relaxed mode try to find a header instead but issue a warning const std::string headerToMoc = - this->FindMocHeader(scannedFileAbsPath, incBasename, incSubDir); + this->MocFindHeader(scannedFileAbsPath, incSubDir + incBasename); if (!headerToMoc.empty()) { // This is for KDE4 compatibility: fileToMoc = headerToMoc; @@ -1782,39 +1783,22 @@ bool cmQtAutoGenerators::FindHeader(std::string& header, return false; } -bool cmQtAutoGenerators::FindHeaderGlobal( - std::string& header, const std::string& testBasePath) const -{ - for (std::vector::const_iterator iit = - this->MocIncludePaths.begin(); - iit != this->MocIncludePaths.end(); ++iit) { - const std::string fullPath = ((*iit) + '/' + testBasePath); - if (FindHeader(header, fullPath)) { - return true; - } - } - return false; -} - -std::string cmQtAutoGenerators::FindMocHeader(const std::string& basePath, - const std::string& baseName, - const std::string& subDir) const +std::string cmQtAutoGenerators::MocFindHeader( + const std::string& sourcePath, const std::string& includeBase) const { std::string header; - do { - if (!subDir.empty()) { - if (this->FindHeader(header, basePath + subDir + baseName)) { + // Search in vicinity of the source + if (!this->FindHeader(header, sourcePath + includeBase)) { + // Search in include directories + for (std::vector::const_iterator iit = + this->MocIncludePaths.begin(); + iit != this->MocIncludePaths.end(); ++iit) { + const std::string fullPath = ((*iit) + '/' + includeBase); + if (FindHeader(header, fullPath)) { break; } } - if (this->FindHeader(header, basePath + baseName)) { - break; - } - // Try include directories - if (this->FindHeaderGlobal(header, subDir + baseName)) { - break; - } - } while (false); + } // Sanitize if (!header.empty()) { header = cmsys::SystemTools::GetRealPath(header); @@ -1822,14 +1806,14 @@ std::string cmQtAutoGenerators::FindMocHeader(const std::string& basePath, return header; } -bool cmQtAutoGenerators::FindIncludedFile( - std::string& absFile, const std::string& sourceFile, +bool cmQtAutoGenerators::MocFindIncludedFile( + std::string& absFile, const std::string& sourcePath, const std::string& includeString) const { bool success = false; // Search in vicinity of the source { - std::string testPath = subDirPrefix(sourceFile); + std::string testPath = sourcePath; testPath += includeString; if (cmsys::SystemTools::FileExists(testPath.c_str())) { absFile = cmsys::SystemTools::GetRealPath(testPath); diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 46c86ff..3bff2b2 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -144,13 +144,11 @@ private: bool MakeParentDirectory(const std::string& filename) const; bool FindHeader(std::string& header, const std::string& testBasePath) const; - bool FindHeaderGlobal(std::string& header, - const std::string& testBasePath) const; - std::string FindMocHeader(const std::string& basePath, - const std::string& baseName, - const std::string& subDir) const; - bool FindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString) const; + + std::string MocFindHeader(const std::string& sourcePath, + const std::string& includeBase) const; + bool MocFindIncludedFile(std::string& absFile, const std::string& sourceFile, + const std::string& includeString) const; // - Target names std::string OriginTargetName; -- cgit v0.12 From ac77fa35c0250f2f7593fd2fc499b27bf395e5a6 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Fri, 24 Feb 2017 12:21:31 +0100 Subject: Autogen: Add missing return on error --- Source/cmQtAutoGenerators.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c4ae318..2fa5359 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -396,6 +396,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( } else { this->LogError("AutoMoc: Error: AUTOMOC_DEPEND_FILTERS list size is not " "a multiple of 2"); + return false; } } -- cgit v0.12 From 154d8339f77e5cd31466e5a4258c27a8aa31ff1c Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 27 Feb 2017 13:48:08 +0100 Subject: Autogen: Parse enabled feature configuration only --- Source/cmQtAutoGenerators.cxx | 225 ++++++++++++++++++++++-------------------- 1 file changed, 117 insertions(+), 108 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 2fa5359..dfaaa6a 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -332,7 +332,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME"); this->AutogenTargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); - // - Directories + // - Files and directories this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); this->CurrentSourceDir = @@ -340,6 +340,13 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( this->CurrentBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); + cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_SOURCES"), + this->Sources); + cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_HEADERS"), + this->Headers); + this->IncludeProjectDirsBefore = + makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); + // - Qt environment this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR"); if (this->QtMajorVersion == "") { @@ -352,138 +359,140 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( Quoted(this->QtMajorVersion)); return false; } - + // Qt executables this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE"); this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE"); - // - File Lists - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_SOURCES"), - this->Sources); - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_HEADERS"), - this->Headers); - // - Moc - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_MOC_SKIP"), - this->MocSkipList); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_MOC_COMPILE_DEFINITIONS", config), - this->MocDefinitions); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_MOC_INCLUDES", config), - this->MocIncludePaths); - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_MOC_OPTIONS"), this->MocOptions); - { - std::vector mocDependFilters; + if (this->MocEnabled()) { cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_MOC_DEPEND_FILTERS"), mocDependFilters); - // Insert Q_PLUGIN_METADATA dependency filter - if (this->QtMajorVersion != "4") { - this->MocDependFilterPush("Q_PLUGIN_METADATA", - "[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\(" - "[^\\)]*FILE[ \t]*\"([^\"]+)\""); - } - // Insert user defined dependency filters - if ((mocDependFilters.size() % 2) == 0) { - for (std::vector::const_iterator dit = - mocDependFilters.begin(); - dit != mocDependFilters.end(); dit += 2) { - if (!this->MocDependFilterPush(*dit, *(dit + 1))) { - return false; + makefile->GetSafeDefinition("AM_MOC_SKIP"), this->MocSkipList); + cmSystemTools::ExpandListArgument( + GetConfigDefinition(makefile, "AM_MOC_COMPILE_DEFINITIONS", config), + this->MocDefinitions); + cmSystemTools::ExpandListArgument( + GetConfigDefinition(makefile, "AM_MOC_INCLUDES", config), + this->MocIncludePaths); + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_MOC_OPTIONS"), this->MocOptions); + { + std::vector mocDependFilters; + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_MOC_DEPEND_FILTERS"), + mocDependFilters); + // Insert Q_PLUGIN_METADATA dependency filter + if (this->QtMajorVersion != "4") { + this->MocDependFilterPush("Q_PLUGIN_METADATA", + "[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\(" + "[^\\)]*FILE[ \t]*\"([^\"]+)\""); + } + // Insert user defined dependency filters + if ((mocDependFilters.size() % 2) == 0) { + for (std::vector::const_iterator dit = + mocDependFilters.begin(); + dit != mocDependFilters.end(); dit += 2) { + if (!this->MocDependFilterPush(*dit, *(dit + 1))) { + return false; + } } + } else { + this->LogError( + "AutoMoc: Error: AUTOMOC_DEPEND_FILTERS list size is not " + "a multiple of 2"); + return false; } - } else { - this->LogError("AutoMoc: Error: AUTOMOC_DEPEND_FILTERS list size is not " - "a multiple of 2"); - return false; } + + this->MocRelaxedMode = makefile->IsOn("AM_MOC_RELAXED_MODE"); } // - Uic - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_UIC_SKIP"), - this->UicSkipList); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_UIC_TARGET_OPTIONS", config), - this->UicTargetOptions); - { - std::vector uicFilesVec; - std::vector uicOptionsVec; + if (this->UicEnabled()) { cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"), uicFilesVec); + makefile->GetSafeDefinition("AM_UIC_SKIP"), this->UicSkipList); cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS"), uicOptionsVec); - // Compare list sizes - if (uicFilesVec.size() == uicOptionsVec.size()) { - for (std::vector::iterator fileIt = uicFilesVec.begin(), - optionIt = uicOptionsVec.begin(); - fileIt != uicFilesVec.end(); ++fileIt, ++optionIt) { - cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";"); - this->UicOptions[*fileIt] = *optionIt; + GetConfigDefinition(makefile, "AM_UIC_TARGET_OPTIONS", config), + this->UicTargetOptions); + { + std::vector uicFilesVec; + std::vector uicOptionsVec; + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"), uicFilesVec); + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS"), uicOptionsVec); + // Compare list sizes + if (uicFilesVec.size() == uicOptionsVec.size()) { + for (std::vector::iterator + fileIt = uicFilesVec.begin(), + optionIt = uicOptionsVec.begin(); + fileIt != uicFilesVec.end(); ++fileIt, ++optionIt) { + cmSystemTools::ReplaceString(*optionIt, "@list_sep@", ";"); + this->UicOptions[*fileIt] = *optionIt; + } + } else { + this->LogError( + "AutoGen: Error: Uic files/options lists size missmatch in: " + + filename); + return false; } - } else { - this->LogError( - "AutoGen: Error: Uic files/options lists size missmatch in: " + - filename); - return false; } + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_UIC_SEARCH_PATHS"), + this->UicSearchPaths); } - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_SEARCH_PATHS"), this->UicSearchPaths); // - Rcc - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_SOURCES"), this->RccSources); - { - std::vector rccFilesVec; - std::vector rccOptionsVec; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES"), rccFilesVec); + if (this->RccEnabled()) { cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS"), rccOptionsVec); - if (rccFilesVec.size() != rccOptionsVec.size()) { - this->LogError( - "AutoGen: Error: RCC files/options lists size missmatch in: " + - filename); - 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; + makefile->GetSafeDefinition("AM_RCC_SOURCES"), this->RccSources); + { + std::vector rccFilesVec; + std::vector rccOptionsVec; + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES"), rccFilesVec); + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS"), rccOptionsVec); + if (rccFilesVec.size() != rccOptionsVec.size()) { + this->LogError( + "AutoGen: Error: RCC files/options lists size missmatch in: " + + filename); + 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; + } } - } - { - std::vector rccInputLists; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_INPUTS"), rccInputLists); + { + std::vector rccInputLists; + cmSystemTools::ExpandListArgument( + makefile->GetSafeDefinition("AM_RCC_INPUTS"), rccInputLists); - // qrc files in the end of the list may have been empty - if (rccInputLists.size() < this->RccSources.size()) { - rccInputLists.resize(this->RccSources.size()); - } - if (this->RccSources.size() != rccInputLists.size()) { - this->LogError( - "AutoGen: Error: RCC sources/inputs lists size missmatch in: " + - filename); - return false; - } - for (std::vector::iterator fileIt = this->RccSources.begin(), - inputIt = rccInputLists.begin(); - fileIt != this->RccSources.end(); ++fileIt, ++inputIt) { - cmSystemTools::ReplaceString(*inputIt, "@list_sep@", ";"); - std::vector rccInputFiles; - cmSystemTools::ExpandListArgument(*inputIt, rccInputFiles); - this->RccInputs[*fileIt] = rccInputFiles; + // qrc files in the end of the list may have been empty + if (rccInputLists.size() < this->RccSources.size()) { + rccInputLists.resize(this->RccSources.size()); + } + if (this->RccSources.size() != rccInputLists.size()) { + this->LogError( + "AutoGen: Error: RCC sources/inputs lists size missmatch in: " + + filename); + return false; + } + for (std::vector::iterator + fileIt = this->RccSources.begin(), + inputIt = rccInputLists.begin(); + fileIt != this->RccSources.end(); ++fileIt, ++inputIt) { + cmSystemTools::ReplaceString(*inputIt, "@list_sep@", ";"); + std::vector rccInputFiles; + cmSystemTools::ExpandListArgument(*inputIt, rccInputFiles); + this->RccInputs[*fileIt] = rccInputFiles; + } } } - // - Flags - this->IncludeProjectDirsBefore = - makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); - this->MocRelaxedMode = makefile->IsOn("AM_MOC_RELAXED_MODE"); - return true; } -- cgit v0.12 From 3bf28f5ed057b2fe4d90c601065188055bb052a1 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 27 Feb 2017 14:22:07 +0100 Subject: Autogen: New short InfoGet functions --- Modules/AutogenInfo.cmake.in | 2 +- Source/cmQtAutoGeneratorInitializer.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 130 +++++++++++++++----------------- 3 files changed, 62 insertions(+), 72 deletions(-) diff --git a/Modules/AutogenInfo.cmake.in b/Modules/AutogenInfo.cmake.in index f8ffe91..fcecb6c 100644 --- a/Modules/AutogenInfo.cmake.in +++ b/Modules/AutogenInfo.cmake.in @@ -16,7 +16,7 @@ set(AM_QT_UIC_EXECUTABLE @_qt_uic_executable@) set(AM_QT_RCC_EXECUTABLE @_qt_rcc_executable@) # MOC settings set(AM_MOC_SKIP @_moc_skip@) -set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) +set(AM_MOC_DEFINITIONS @_moc_compile_defs@) set(AM_MOC_INCLUDES @_moc_incs@) set(AM_MOC_OPTIONS @_moc_options@) set(AM_MOC_RELAXED_MODE @_moc_relaxed_mode@) diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index 5460f73..a45b3d5 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -972,7 +972,7 @@ void cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget( it = configMocDefines.begin(), end = configMocDefines.end(); it != end; ++it) { - infoFile << "set(AM_MOC_COMPILE_DEFINITIONS_" << it->first << " " + infoFile << "set(AM_MOC_DEFINITIONS_" << it->first << " " << it->second << ")\n"; } } diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index dfaaa6a..c83f9a9 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -55,20 +55,38 @@ static std::string Quoted(const std::string& text) return res; } -static std::string GetConfigDefinition(cmMakefile* makefile, - const std::string& key, - const std::string& config) +static void InfoGet(cmMakefile* makefile, const char* key, std::string& value) { - std::string keyConf = key; - if (!config.empty()) { - keyConf += "_"; - keyConf += config; + value = makefile->GetSafeDefinition(key); +} + +static void InfoGet(cmMakefile* makefile, const char* key, bool& value) +{ + value = makefile->IsOn(key); +} + +static void InfoGet(cmMakefile* makefile, const char* key, + std::vector& list) +{ + cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition(key), list); +} + +static void InfoGet(cmMakefile* makefile, const char* key, + const std::string& config, std::vector& list) +{ + const char* valueConf = CM_NULLPTR; + { + std::string keyConf = key; + if (!config.empty()) { + keyConf += "_"; + keyConf += config; + } + valueConf = makefile->GetDefinition(keyConf); } - const char* valueConf = makefile->GetDefinition(keyConf); - if (valueConf != CM_NULLPTR) { - return valueConf; + if (valueConf == CM_NULLPTR) { + valueConf = makefile->GetSafeDefinition(key); } - return makefile->GetSafeDefinition(key); + cmSystemTools::ExpandListArgument(valueConf, list); } static std::string SettingsFile(const std::string& targetDirectory) @@ -328,59 +346,44 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( } // - Target names - this->OriginTargetName = - makefile->GetSafeDefinition("AM_ORIGIN_TARGET_NAME"); - this->AutogenTargetName = makefile->GetSafeDefinition("AM_TARGET_NAME"); + InfoGet(makefile, "AM_TARGET_NAME", this->AutogenTargetName); + InfoGet(makefile, "AM_ORIGIN_TARGET_NAME", this->OriginTargetName); // - Files and directories - this->ProjectSourceDir = makefile->GetSafeDefinition("AM_CMAKE_SOURCE_DIR"); - this->ProjectBinaryDir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR"); - this->CurrentSourceDir = - makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR"); - this->CurrentBinaryDir = - makefile->GetSafeDefinition("AM_CMAKE_CURRENT_BINARY_DIR"); - - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_SOURCES"), - this->Sources); - cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_HEADERS"), - this->Headers); - this->IncludeProjectDirsBefore = - makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE"); + InfoGet(makefile, "AM_CMAKE_SOURCE_DIR", this->ProjectSourceDir); + InfoGet(makefile, "AM_CMAKE_BINARY_DIR", this->ProjectBinaryDir); + InfoGet(makefile, "AM_CMAKE_CURRENT_SOURCE_DIR", this->CurrentSourceDir); + InfoGet(makefile, "AM_CMAKE_CURRENT_BINARY_DIR", this->CurrentBinaryDir); + InfoGet(makefile, "AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE", + this->IncludeProjectDirsBefore); + InfoGet(makefile, "AM_SOURCES", this->Sources); + InfoGet(makefile, "AM_HEADERS", this->Headers); // - Qt environment - this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR"); - if (this->QtMajorVersion == "") { - this->QtMajorVersion = - makefile->GetSafeDefinition("AM_Qt5Core_VERSION_MAJOR"); + InfoGet(makefile, "AM_QT_VERSION_MAJOR", this->QtMajorVersion); + if (this->QtMajorVersion.empty()) { + InfoGet(makefile, "AM_Qt5Core_VERSION_MAJOR", this->QtMajorVersion); } + InfoGet(makefile, "AM_QT_MOC_EXECUTABLE", this->MocExecutable); + InfoGet(makefile, "AM_QT_UIC_EXECUTABLE", this->UicExecutable); + InfoGet(makefile, "AM_QT_RCC_EXECUTABLE", this->RccExecutable); // Check Qt version if ((this->QtMajorVersion != "4") && (this->QtMajorVersion != "5")) { this->LogError("AutoGen: Error: Unsupported Qt version: " + Quoted(this->QtMajorVersion)); return false; } - // Qt executables - this->MocExecutable = makefile->GetSafeDefinition("AM_QT_MOC_EXECUTABLE"); - this->UicExecutable = makefile->GetSafeDefinition("AM_QT_UIC_EXECUTABLE"); - this->RccExecutable = makefile->GetSafeDefinition("AM_QT_RCC_EXECUTABLE"); // - Moc if (this->MocEnabled()) { - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_MOC_SKIP"), this->MocSkipList); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_MOC_COMPILE_DEFINITIONS", config), - this->MocDefinitions); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_MOC_INCLUDES", config), - this->MocIncludePaths); - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_MOC_OPTIONS"), this->MocOptions); + InfoGet(makefile, "AM_MOC_SKIP", this->MocSkipList); + InfoGet(makefile, "AM_MOC_DEFINITIONS", config, this->MocDefinitions); + InfoGet(makefile, "AM_MOC_INCLUDES", config, this->MocIncludePaths); + InfoGet(makefile, "AM_MOC_OPTIONS", this->MocOptions); + InfoGet(makefile, "AM_MOC_RELAXED_MODE", this->MocRelaxedMode); { std::vector mocDependFilters; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_MOC_DEPEND_FILTERS"), - mocDependFilters); + InfoGet(makefile, "AM_MOC_DEPEND_FILTERS", mocDependFilters); // Insert Q_PLUGIN_METADATA dependency filter if (this->QtMajorVersion != "4") { this->MocDependFilterPush("Q_PLUGIN_METADATA", @@ -403,24 +406,18 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( return false; } } - - this->MocRelaxedMode = makefile->IsOn("AM_MOC_RELAXED_MODE"); } // - Uic if (this->UicEnabled()) { - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_SKIP"), this->UicSkipList); - cmSystemTools::ExpandListArgument( - GetConfigDefinition(makefile, "AM_UIC_TARGET_OPTIONS", config), - this->UicTargetOptions); + InfoGet(makefile, "AM_UIC_SKIP", this->UicSkipList); + InfoGet(makefile, "AM_UIC_SEARCH_PATHS", this->UicSearchPaths); + InfoGet(makefile, "AM_UIC_TARGET_OPTIONS", config, this->UicTargetOptions); { std::vector uicFilesVec; std::vector uicOptionsVec; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_OPTIONS_FILES"), uicFilesVec); - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_OPTIONS_OPTIONS"), uicOptionsVec); + InfoGet(makefile, "AM_UIC_OPTIONS_FILES", uicFilesVec); + InfoGet(makefile, "AM_UIC_OPTIONS_OPTIONS", uicOptionsVec); // Compare list sizes if (uicFilesVec.size() == uicOptionsVec.size()) { for (std::vector::iterator @@ -437,22 +434,16 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( return false; } } - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_UIC_SEARCH_PATHS"), - this->UicSearchPaths); } // - Rcc if (this->RccEnabled()) { - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_SOURCES"), this->RccSources); + InfoGet(makefile, "AM_RCC_SOURCES", this->RccSources); { std::vector rccFilesVec; std::vector rccOptionsVec; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_OPTIONS_FILES"), rccFilesVec); - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_OPTIONS_OPTIONS"), rccOptionsVec); + InfoGet(makefile, "AM_RCC_OPTIONS_FILES", rccFilesVec); + InfoGet(makefile, "AM_RCC_OPTIONS_OPTIONS", rccOptionsVec); if (rccFilesVec.size() != rccOptionsVec.size()) { this->LogError( "AutoGen: Error: RCC files/options lists size missmatch in: " + @@ -468,8 +459,7 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile( } { std::vector rccInputLists; - cmSystemTools::ExpandListArgument( - makefile->GetSafeDefinition("AM_RCC_INPUTS"), rccInputLists); + InfoGet(makefile, "AM_RCC_INPUTS", rccInputLists); // qrc files in the end of the list may have been empty if (rccInputLists.size() < this->RccSources.size()) { -- cgit v0.12