From 9beb2744d7685fca9cd5717308d4457dffdefcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Plucin=CC=81ski?= Date: Sat, 13 Feb 2016 11:30:31 +0100 Subject: [PATCH] Automoc: Fix support of files with the same name (#12873) --- Source/cmQtAutoGenerators.cxx | 35 ++++++++++++++++++++++++++--- Tests/QtAutogen/Adir/CMakeLists.txt | 2 +- Tests/QtAutogen/Adir/bar/foo.cpp | 4 ++++ Tests/QtAutogen/Adir/bar/foo.h | 10 +++++++++ Tests/QtAutogen/Adir/foo.cpp | 4 ++++ Tests/QtAutogen/Adir/foo.h | 8 +++++++ 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Tests/QtAutogen/Adir/bar/foo.cpp create mode 100644 Tests/QtAutogen/Adir/bar/foo.h create mode 100644 Tests/QtAutogen/Adir/foo.cpp create mode 100644 Tests/QtAutogen/Adir/foo.h diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index b16eccda3..226ab430e 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1104,10 +1104,39 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, std::cout << "AUTOGEN: Checking " << headerName << std::endl; } - const std::string basename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(headerName); + std::string headerDirectory; + if (cmsys::SystemTools::IsSubDirectory(headerName, + this->ProjectSourceDir)) + { + headerDirectory = this->ProjectSourceDir; + } + else if (cmsys::SystemTools::IsSubDirectory(headerName, + this->ProjectBinaryDir)) + { + headerDirectory = this->ProjectBinaryDir; + } + else + { + cmsys::SystemTools::SplitPathRootComponent(headerName, + &headerDirectory); + } - const std::string currentMoc = "moc_" + basename + ".cpp"; + std::string baseHeaderName = + cmsys::SystemTools::GetFilenameWithoutLastExtension(headerName); + + headerDirectory = cmsys::SystemTools::RelativePath( + headerDirectory, cmsys::SystemTools::GetParentDirectory(headerName)); + + if (!headerDirectory.empty()) + { + headerDirectory += "/"; + } + + std::string mocName = headerDirectory + baseHeaderName; + + cmSystemTools::ReplaceString(mocName, "/", "_"); + + const std::string currentMoc = "moc_" + mocName + ".cpp"; std::string macroName; if (requiresMocing(contents, macroName)) { diff --git a/Tests/QtAutogen/Adir/CMakeLists.txt b/Tests/QtAutogen/Adir/CMakeLists.txt index a1c36ffce..0c7848dbb 100644 --- a/Tests/QtAutogen/Adir/CMakeLists.txt +++ b/Tests/QtAutogen/Adir/CMakeLists.txt @@ -3,6 +3,6 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) -add_library(libA SHARED libA.cpp) +add_library(libA SHARED libA.cpp foo.cpp bar/foo.cpp) target_link_libraries(libA LINK_PUBLIC ${QT_QTCORE_TARGET}) generate_export_header(libA) diff --git a/Tests/QtAutogen/Adir/bar/foo.cpp b/Tests/QtAutogen/Adir/bar/foo.cpp new file mode 100644 index 000000000..3f5e0a989 --- /dev/null +++ b/Tests/QtAutogen/Adir/bar/foo.cpp @@ -0,0 +1,4 @@ +#include "foo.h" + +bar::foo::foo() {} +bar::foo::~foo() {} diff --git a/Tests/QtAutogen/Adir/bar/foo.h b/Tests/QtAutogen/Adir/bar/foo.h new file mode 100644 index 000000000..daf23679a --- /dev/null +++ b/Tests/QtAutogen/Adir/bar/foo.h @@ -0,0 +1,10 @@ +#include + +namespace bar { + class foo: public QObject { + Q_OBJECT + public: + foo(); + ~foo(); + }; +} diff --git a/Tests/QtAutogen/Adir/foo.cpp b/Tests/QtAutogen/Adir/foo.cpp new file mode 100644 index 000000000..86e4d8eec --- /dev/null +++ b/Tests/QtAutogen/Adir/foo.cpp @@ -0,0 +1,4 @@ +#include "foo.h" + +foo::foo() {} +foo::~foo() {} diff --git a/Tests/QtAutogen/Adir/foo.h b/Tests/QtAutogen/Adir/foo.h new file mode 100644 index 000000000..a51960c28 --- /dev/null +++ b/Tests/QtAutogen/Adir/foo.h @@ -0,0 +1,8 @@ +#include + +class foo: public QObject { + Q_OBJECT +public: + foo(); + ~foo(); +};