From 02e6c5481396a841a80e9546c223e7edc041a668 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 15 Aug 2017 12:17:37 +0200 Subject: [PATCH 1/3] Autogen: Restore AUTOUIC lookup paths from 3.8.2 When encountering an `#include "ui_.h"` statement, search for `.ui` in - /.ui - /.ui - /.ui - /.ui In CMake 3.8.2 the lookup list was - /.ui In CMake 3.9.[01] the lookup list was - / - /.ui Closes #17168 --- Source/cmQtAutoGenerators.cxx | 73 ++++++++++++++++++++++++----------- Source/cmQtAutoGenerators.h | 3 +- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c79f66da5b..d12d96dcbb 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1446,31 +1446,62 @@ bool cmQtAutoGenerators::MocGenerateFile( bool cmQtAutoGenerators::UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString) + const std::string& searchPath, + const std::string& searchFile) { bool success = false; - // Search in vicinity of the source + std::vector testFiles; + // Collect search paths list { - std::string testPath = SubDirPrefix(sourceFile); - testPath += includeString; - if (cmsys::SystemTools::FileExists(testPath.c_str())) { - absFile = cmsys::SystemTools::GetRealPath(testPath); - success = true; + const std::string searchFileFull = searchPath + searchFile; + // Vicinity of the source + { + const std::string sourcePath = SubDirPrefix(sourceFile); + testFiles.push_back(sourcePath + searchFile); + if (!searchPath.empty()) { + testFiles.push_back(sourcePath + searchFileFull); + } } - } - // 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; + // AUTOUIC search paths + if (!this->UicSearchPaths.empty()) { + for (std::vector::const_iterator iit = + this->UicSearchPaths.begin(); + iit != this->UicSearchPaths.end(); ++iit) { + testFiles.push_back(*iit + "/" + searchFile); + } + if (!searchPath.empty()) { + for (std::vector::const_iterator iit = + this->UicSearchPaths.begin(); + iit != this->UicSearchPaths.end(); ++iit) { + testFiles.push_back(*iit + "/" + searchFileFull); + } } } } + + // Search for the .ui file! + for (std::vector::const_iterator iit = testFiles.begin(); + iit != testFiles.end(); ++iit) { + const std::string& testFile = *iit; + if (cmsys::SystemTools::FileExists(testFile.c_str())) { + absFile = cmsys::SystemTools::GetRealPath(testFile); + success = true; + break; + } + } + + // Log error + if (!success) { + std::ostringstream ost; + ost << "AutoUic: Error: " << Quoted(sourceFile) << "\n"; + ost << "Could not find " << Quoted(searchFile) << " in\n"; + for (std::vector::const_iterator iit = testFiles.begin(); + iit != testFiles.end(); ++iit) { + ost << " " << Quoted(*iit) << "\n"; + } + this->LogError(ost.str()); + } + return success; } @@ -1500,16 +1531,14 @@ bool cmQtAutoGenerators::UicGenerateAll( const std::string uiBasePath = SubDirPrefix(*uit); const std::string uiBaseName = cmsys::SystemTools::GetFilenameWithoutLastExtension(*uit).substr(3); - const std::string searchFileName = uiBasePath + uiBaseName + ".ui"; + const std::string uiFileName = uiBaseName + ".ui"; std::string uiInputFile; - if (UicFindIncludedFile(uiInputFile, source, searchFileName)) { + if (UicFindIncludedFile(uiInputFile, source, uiBasePath, uiFileName)) { 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; } } diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index b525364c07..337aa17fd7 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -112,7 +112,8 @@ private: // -- Uic file generation bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile, - const std::string& includeString); + const std::string& searchPath, + const std::string& searchFile); bool UicGenerateAll( const std::map >& includedUis); bool UicGenerateFile(const std::string& realName, From d8a99dd2eaaa43e765b6ca2061ba8c14432fb909 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 15 Aug 2017 12:57:32 +0200 Subject: [PATCH 2/3] Autogen: Update AUTOUIC documentation for search paths --- Help/manual/cmake-qt.7.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst index 00d6e6e9b0..b7f16b9eaf 100644 --- a/Help/manual/cmake-qt.7.rst +++ b/Help/manual/cmake-qt.7.rst @@ -70,8 +70,8 @@ be included by the user in the C++ implementation file with a preprocessor Included ``moc_*.cpp`` and ``*.moc`` files will be generated in the ``/include`` directory which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. -(This differs from CMake 3.7 and below; see their documentation for details.) +* This differs from CMake 3.7 and below; see their documentation for details. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. Not included ``moc_.cpp`` files will be generated in custom @@ -107,16 +107,23 @@ inspects the C++ files in the target to determine if they require ``uic`` to 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. 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. +``ui_.h``, and a ``.ui`` file exists, +then ``uic`` will be executed to generate the appropriate file. +The ``.ui`` file is searched for in the following places + +1. ``/.ui`` +2. ``/.ui`` +3. ``/.ui`` +4. ``/.ui`` + +where ```` is the directory of the C++ file and +:prop_tgt:`AUTOUIC_SEARCH_PATHS` is a list of additional search paths. The generated generated ``ui_*.h`` files are placed in the ``/include`` directory which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`. -(This differs from CMake 3.7 and below; see their documentation for details.) +* This differs from CMake 3.7 and below; see their documentation for details. * See :prop_tgt:`AUTOGEN_BUILD_DIR`. The :prop_tgt:`AUTOUIC` target property may be pre-set for all following From fb5db079a7e478c332441c552929f8bf30d55894 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 15 Aug 2017 13:22:18 +0200 Subject: [PATCH 3/3] Autogen: Extend AUTOUIC search paths test --- Tests/QtAutogen/uicInclude/PageC2.ui | 24 +++++++++++++++++++ .../uicInclude/dirB/{sub => }/PageB.ui | 0 Tests/QtAutogen/uicInclude/dirB/PageB2.ui | 24 +++++++++++++++++++ .../uicInclude/dirB/subB/PageBsub.ui | 24 +++++++++++++++++++ Tests/QtAutogen/uicInclude/main.cpp | 10 +++++++- Tests/QtAutogen/uicInclude/subC/PageCsub.ui | 24 +++++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Tests/QtAutogen/uicInclude/PageC2.ui rename Tests/QtAutogen/uicInclude/dirB/{sub => }/PageB.ui (100%) create mode 100644 Tests/QtAutogen/uicInclude/dirB/PageB2.ui create mode 100644 Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui create mode 100644 Tests/QtAutogen/uicInclude/subC/PageCsub.ui diff --git a/Tests/QtAutogen/uicInclude/PageC2.ui b/Tests/QtAutogen/uicInclude/PageC2.ui new file mode 100644 index 0000000000..daab868390 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/PageC2.ui @@ -0,0 +1,24 @@ + + + PageC2 + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui b/Tests/QtAutogen/uicInclude/dirB/PageB.ui similarity index 100% rename from Tests/QtAutogen/uicInclude/dirB/sub/PageB.ui rename to Tests/QtAutogen/uicInclude/dirB/PageB.ui diff --git a/Tests/QtAutogen/uicInclude/dirB/PageB2.ui b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui new file mode 100644 index 0000000000..2225150b52 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirB/PageB2.ui @@ -0,0 +1,24 @@ + + + PageB2 + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui new file mode 100644 index 0000000000..873016ec80 --- /dev/null +++ b/Tests/QtAutogen/uicInclude/dirB/subB/PageBsub.ui @@ -0,0 +1,24 @@ + + + PageBsub + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + diff --git a/Tests/QtAutogen/uicInclude/main.cpp b/Tests/QtAutogen/uicInclude/main.cpp index 4ca66a7062..c8e760962e 100644 --- a/Tests/QtAutogen/uicInclude/main.cpp +++ b/Tests/QtAutogen/uicInclude/main.cpp @@ -6,5 +6,13 @@ int main(int argv, char** args) return 0; } -#include "sub/ui_PageB.h" +// .ui files in CMAKE_AUTOUIC_SEARCH_PATHS +#include "ui_PageA.h" +// .ui files in AUTOUIC_SEARCH_PATHS +#include "sub/gen/deep/ui_PageB2.h" +#include "subB/ui_PageBsub.h" +#include "ui_PageB.h" +// .ui files in source's vicinity +#include "sub/gen/deep/ui_PageC2.h" +#include "subC/ui_PageCsub.h" #include "ui_PageC.h" diff --git a/Tests/QtAutogen/uicInclude/subC/PageCsub.ui b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui new file mode 100644 index 0000000000..0268326b9b --- /dev/null +++ b/Tests/QtAutogen/uicInclude/subC/PageCsub.ui @@ -0,0 +1,24 @@ + + + PageCsub + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + +