MantisBT - CMake
View Issue Details
0012873CMakeCMakepublic2012-01-12 23:092016-06-10 14:21
joseph2002 
 
normalminoralways
closedfixed 
AllAllAll
CMake 2.8.7 
CMake 3.6CMake 3.6 
0012873: AUTOMOC produces same output moc file if target has two source files resides in different sub-directory
consider following directory structure:

src
src/CMakeLists.txt
src/sub1
src/sub1/test.h
src/sub1/test.cpp
src/sub2
src/sub2/test.h
src/sub2/test.cpp

src/CMakeLists.txt:
ADD_LIBRARY( testsrc sub1/test.cpp sub2/test.cpp )

Then AUTOMOC will produce the same moc_test.cpp in the binary folder of src:
${BINARY_DIR}/src/moc_test.cpp
${BINARY_DIR}/src/testsrc_automoc.cpp Which contains two lines of #include "moc_test.cpp"

This is not desired. CMake should keep directory structure when automocing, and produces:
${BINARY_DIR}/src/sub1/moc_test.cpp
${BINARY_DIR}/src/sub2/moc_test.cpp

No tags attached.
Issue History
2012-01-12 23:09joseph2002New Issue
2012-01-13 09:28Brad KingAssigned To => Alex Neundorf
2012-01-13 09:28Brad KingStatusnew => assigned
2012-01-18 14:37Alex NeundorfPrioritynormal => high
2012-01-18 14:37Alex NeundorfTarget Version => CMake 2.8.8
2012-04-19 08:47David ColeTarget VersionCMake 2.8.8 => CMake 2.8.9
2012-07-09 07:13David ColeNote Added: 0029992
2012-07-09 07:18David ColeTarget VersionCMake 2.8.9 =>
2012-08-13 14:26Alex NeundorfPriorityhigh => normal
2012-08-13 14:26Alex NeundorfStatusassigned => backlog
2015-04-17 23:11Kwabena W. AgyemanNote Added: 0038539
2015-07-20 05:11Jan SteinkeNote Added: 0039158
2016-02-16 10:50Brad KingNote Added: 0040495
2016-02-18 10:43Brad KingNote Added: 0040506
2016-02-18 10:43Brad KingStatusbacklog => resolved
2016-02-18 10:43Brad KingResolutionopen => fixed
2016-02-18 10:43Brad KingFixed in Version => CMake 3.6
2016-02-18 10:43Brad KingTarget Version => CMake 3.6
2016-02-19 05:33Stephen KellyNote Added: 0040512
2016-02-19 09:01Brad KingNote Added: 0040513
2016-02-19 09:01Brad KingAssigned ToAlex Neundorf =>
2016-02-19 09:01Brad KingStatusresolved => acknowledged
2016-02-19 09:01Brad KingResolutionfixed => open
2016-02-19 09:01Brad KingFixed in VersionCMake 3.6 =>
2016-02-19 09:01Brad KingTarget VersionCMake 3.6 =>
2016-04-12 13:47Brad KingNote Added: 0040845
2016-04-22 09:02Brad KingNote Added: 0040922
2016-04-22 09:02Brad KingStatusacknowledged => resolved
2016-04-22 09:02Brad KingResolutionopen => fixed
2016-04-22 09:02Brad KingFixed in Version => CMake 3.6
2016-04-22 09:02Brad KingTarget Version => CMake 3.6
2016-06-10 14:21Kitware RobotNote Added: 0041185
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0029992)
David Cole   
2012-07-09 07:13   
Unset target version field; too late for a fix to go into 2.8.9; deferred until a future version.
(0038539)
Kwabena W. Agyeman   
2015-04-17 23:11   
This is still broken. It needs to be fixed...
(0039158)
Jan Steinke   
2015-07-20 05:11   
I encountered the same behavior.
I agree with the author that it limits the power of cmake quite a lot. The only workaround is renaming the files manually so there are no two filenames the same. That, however, might take too much time depending on the size of the project. I spend several hours just renaming files and fixing imports.
(0040495)
Brad King   
2016-02-16 10:50   
Patch proposed in mailing list thread:

 [PATCH] Proposal of fix for issue 0012873 (AUTOMOC produces same output moc file if target has two source files resides in different sub-directory)
 http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/15785 [^]
(0040506)
Brad King   
2016-02-18 10:43   
This has been fixed by the patch linked in 0012873:0040495:

 Automoc: Fix support of files with the same name
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9beb2744 [^]
(0040512)
Stephen Kelly   
2016-02-19 05:33   
I don't think that patch is correct. It should be possible to #include "moc_foo.cpp" in foo.cpp https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html [^]

I think the correct solution is to generate the moc files in different (per target) directories, and add those directories to the target INCLUDE_DIRECTORIES. See also

 QtAutogen: Put generated qrc files in a target-specific dir.
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=33774ca2 [^]
(0040513)
Brad King   
2016-02-19 09:01   
Re 0012873:0040512: Good point, thanks. It looks like that documented behavior is not covered by the test suite though. That should be addressed as part of work on this issue too. I've reverted the change for now:

 Revert "Automoc: Fix support of files with the same name ..."
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=091b649e [^]
(0040845)
Brad King   
2016-04-12 13:47   
Re 0012873:0040513, 0012873:0040512: Additional discussion on mailing list:

http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/16229 [^]
(0040922)
Brad King   
2016-04-22 09:02   
Discussion in the thread linked in 0012873:0040845 resulted in this fix:

 Autogen: Generate not included moc files in subdirectories
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=488ea8c7 [^]
(0041185)
Kitware Robot   
2016-06-10 14:21   
This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.