From 1f802295f2e42fd38477f22d7275ebe166a48f10 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 5 Feb 2019 14:58:37 +0100 Subject: Autogen: Extend the SameName test with same name but different extension files --- Tests/QtAutogen/SameName/CMakeLists.txt | 4 ++++ Tests/QtAutogen/SameName/main.cpp | 13 ++++++++++++- Tests/QtAutogen/SameName/object.h | 13 +++++++++++++ Tests/QtAutogen/SameName/object.h++ | 13 +++++++++++++ Tests/QtAutogen/SameName/object.hpp | 13 +++++++++++++ Tests/QtAutogen/SameName/object.hxx | 13 +++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 Tests/QtAutogen/SameName/object.h create mode 100644 Tests/QtAutogen/SameName/object.h++ create mode 100644 Tests/QtAutogen/SameName/object.hpp create mode 100644 Tests/QtAutogen/SameName/object.hxx diff --git a/Tests/QtAutogen/SameName/CMakeLists.txt b/Tests/QtAutogen/SameName/CMakeLists.txt index 6d42499..8d4f71f 100644 --- a/Tests/QtAutogen/SameName/CMakeLists.txt +++ b/Tests/QtAutogen/SameName/CMakeLists.txt @@ -17,6 +17,10 @@ add_executable(sameName ccc/item.cpp ccc/data.qrc item.cpp + object.h + object.h++ + object.hpp + object.hxx data.qrc main.cpp ) diff --git a/Tests/QtAutogen/SameName/main.cpp b/Tests/QtAutogen/SameName/main.cpp index a4ffcb3..92f15cd 100644 --- a/Tests/QtAutogen/SameName/main.cpp +++ b/Tests/QtAutogen/SameName/main.cpp @@ -3,14 +3,25 @@ #include "bbb/aaa/item.hpp" #include "bbb/item.hpp" #include "ccc/item.hpp" +#include "item.hpp" +#include "object.h" +#include "object.h++" +#include "object.hpp" +#include "object.hxx" int main(int argv, char** args) { - // Object instances + // Item instances + ::Item item; ::aaa::Item aaa_item; ::aaa::bbb::Item aaa_bbb_item; ::bbb::Item bbb_item; ::bbb::aaa::Item bbb_aaa_item; ::ccc::Item ccc_item; + // Object instances + ::Object_h obj_h; + ::Object_hplpl obj_hplpl; + ::Object_hpp obj_hpp; + ::Object_hxx obj_hxx; return 0; } diff --git a/Tests/QtAutogen/SameName/object.h b/Tests/QtAutogen/SameName/object.h new file mode 100644 index 0000000..8662094 --- /dev/null +++ b/Tests/QtAutogen/SameName/object.h @@ -0,0 +1,13 @@ +#ifndef OBJECT_H +#define OBJECT_H + +#include + +class Object_h : public QObject +{ + Q_OBJECT + Q_SLOT + void go(){}; +}; + +#endif diff --git a/Tests/QtAutogen/SameName/object.h++ b/Tests/QtAutogen/SameName/object.h++ new file mode 100644 index 0000000..64222b7 --- /dev/null +++ b/Tests/QtAutogen/SameName/object.h++ @@ -0,0 +1,13 @@ +#ifndef OBJECT_HPLPL +#define OBJECT_HPLPL + +#include + +class Object_hplpl : public QObject +{ + Q_OBJECT + Q_SLOT + void go(){}; +}; + +#endif diff --git a/Tests/QtAutogen/SameName/object.hpp b/Tests/QtAutogen/SameName/object.hpp new file mode 100644 index 0000000..035050e --- /dev/null +++ b/Tests/QtAutogen/SameName/object.hpp @@ -0,0 +1,13 @@ +#ifndef OBJECT_HPP +#define OBJECT_HPP + +#include + +class Object_hpp : public QObject +{ + Q_OBJECT + Q_SLOT + void go(){}; +}; + +#endif diff --git a/Tests/QtAutogen/SameName/object.hxx b/Tests/QtAutogen/SameName/object.hxx new file mode 100644 index 0000000..c3c050f --- /dev/null +++ b/Tests/QtAutogen/SameName/object.hxx @@ -0,0 +1,13 @@ +#ifndef OBJECT_HXX +#define OBJECT_HXX + +#include + +class Object_hxx : public QObject +{ + Q_OBJECT + Q_SLOT + void go(){}; +}; + +#endif -- cgit v0.12 From a28caabf453ab41851b75a40a2e49706439f9478 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Tue, 5 Feb 2019 15:43:27 +0100 Subject: Autogen: AUTOMOC support for files with the same name but different extensions This adds support for AUTOMOC to moc header files with the same but different extensions (e.g `obj.h`, `obj.hpp`, `obj.hxx`). If a moc file would appear multiple times in `mocs_compilation.cpp`, a number suffix is appended to the name to make it unique. Closes #14489 --- Source/cmQtAutoGeneratorMocUic.cxx | 46 ++++++++++++++++++++++++++++---------- Source/cmQtAutoGeneratorMocUic.h | 2 +- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Source/cmQtAutoGeneratorMocUic.cxx b/Source/cmQtAutoGeneratorMocUic.cxx index 0ba5224..ddff4cf 100644 --- a/Source/cmQtAutoGeneratorMocUic.cxx +++ b/Source/cmQtAutoGeneratorMocUic.cxx @@ -678,19 +678,21 @@ void cmQtAutoGeneratorMocUic::JobMocT::Process(WorkerT& wrk) BuildFile += '/'; BuildFile += IncludeString; } else { - std::string rel = wrk.FileSys().GetFilePathChecksum(SourceFile); - rel += "/moc_"; - rel += wrk.FileSys().GetFilenameWithoutLastExtension(SourceFile); - rel += ".cpp"; - // Register relative file path - wrk.Gen().ParallelMocAutoRegister(rel); + // Relative build path + std::string relPath = wrk.FileSys().GetFilePathChecksum(SourceFile); + relPath += "/moc_"; + relPath += wrk.FileSys().GetFilenameWithoutLastExtension(SourceFile); + + // Register relative file path with duplication check + relPath = wrk.Gen().ParallelMocAutoRegister(relPath); + // Absolute build path if (wrk.Base().MultiConfig) { BuildFile = wrk.Base().AutogenIncludeDir; BuildFile += '/'; - BuildFile += rel; + BuildFile += relPath; } else { - BuildFile = wrk.Base().AbsoluteBuildPath(rel); + BuildFile = wrk.Base().AbsoluteBuildPath(relPath); } } @@ -1953,11 +1955,31 @@ bool cmQtAutoGeneratorMocUic::ParallelMocIncluded( return (MocIncludedFiles_.find(sourceFile) != MocIncludedFiles_.end()); } -void cmQtAutoGeneratorMocUic::ParallelMocAutoRegister( - std::string const& mocFile) +std::string cmQtAutoGeneratorMocUic::ParallelMocAutoRegister( + std::string const& baseName) { - std::lock_guard mocLock(JobsMutex_); - MocAutoFiles_.emplace(mocFile); + std::string res; + { + std::lock_guard mocLock(JobsMutex_); + res = baseName; + res += ".cpp"; + if (MocAutoFiles_.find(res) == MocAutoFiles_.end()) { + MocAutoFiles_.emplace(res); + } else { + // Append number suffix to the file name + for (unsigned int ii = 2; ii != 1024; ++ii) { + res = baseName; + res += '_'; + res += std::to_string(ii); + res += ".cpp"; + if (MocAutoFiles_.find(res) == MocAutoFiles_.end()) { + MocAutoFiles_.emplace(res); + break; + } + } + } + } + return res; } void cmQtAutoGeneratorMocUic::ParallelMocAutoUpdated() diff --git a/Source/cmQtAutoGeneratorMocUic.h b/Source/cmQtAutoGeneratorMocUic.h index 32a6006..c22df29 100644 --- a/Source/cmQtAutoGeneratorMocUic.h +++ b/Source/cmQtAutoGeneratorMocUic.h @@ -389,7 +389,7 @@ public: bool ParallelJobPushMoc(JobHandleT& jobHandle); bool ParallelJobPushUic(JobHandleT& jobHandle); bool ParallelMocIncluded(std::string const& sourceFile); - void ParallelMocAutoRegister(std::string const& mocFile); + std::string ParallelMocAutoRegister(std::string const& baseName); void ParallelMocAutoUpdated(); private: -- cgit v0.12