MantisBT - CMake
View Issue Details
0014021CMakeCMakepublic2013-03-18 07:392016-06-10 14:31
Piotr Pietraszkiewicz 
Kitware Robot 
normalmajoralways
closedmoved 
MS Visual Studio 2008Windows7
CMake 2.8.10.2 
 
0014021: Generated .sln files for MS Visual Studio 2008 do not apply Automoc to the top-level dependencies of a sub-folder (library)
In a subdirectory of my project I build a library (sub) which depends on
another library found in the top level directory (mainwindow).

My subfolder's sub/CMakeLists.txt:
~~~~
project ( sub )

include_directories("${CMAKE_SOURCE_DIR}")
add_library(sub SubWindow.h)
target_link_libraries(sub ${Qt4_LIBRARIES} mainlib mainwindow)
~~~~

My top level CMakeLists.txt:
~~~~
[..]
set(CMAKE_AUTOMOC TRUE)

[..]
ADD_SUBDIRECTORY(sub)

include_directories(. sub)

add_library(mainwindow MainWindow.h)
target_link_libraries(mainwindow ${Qt4_LIBRARIES})
~~~~

Both SubWindow.h and MainWindow.h are tagged with Q_OBJECT and thus need to be
processed by automoc. SubWindow.h depends on MainWindow.h.

Configuring the project on Cygwin/Linux environments and invoking "make" in the
"sub" sub-folder yields:
~~~~
~/src/caamtest/cygwin_build/sub:
$ make
Scanning dependencies of target mainwindow_automoc
[ 14%] Automoc for target mainwindow
Generating moc_MainWindow.cpp
[ 14%] Built target mainwindow_automoc
Scanning dependencies of target mainwindow
[ 28%] Building CXX object CMakeFiles/mainwindow.dir/mainwindow_automoc.cpp.o
Linking CXX static library libmainwindow.a
[ 28%] Built target mainwindow
Scanning dependencies of target sub_automoc
[ 42%] Automoc for target sub
Generating moc_SubWindow.cpp
[ 42%] Built target sub_automoc
Scanning dependencies of target mainlib_automoc
[ 57%] Automoc for target mainlib
[ 57%] Built target mainlib_automoc
Scanning dependencies of target mainlib
[ 71%] Building CXX object CMakeFiles/mainlib.dir/mainlib.cpp.o
[ 85%] Building CXX object CMakeFiles/mainlib.dir/mainlib_automoc.cpp.o
Linking CXX static library libmainlib.a
[ 85%] Built target mainlib
Scanning dependencies of target sub
[100%] Building CXX object sub/CMakeFiles/sub.dir/sub_automoc.cpp.o
Linking CXX static library libsub.a
[100%] Built target sub
~~~~

All fine, note that Automoc was started for both "mainwindow" and "sub".

In contrast, configuring the project on Windows environment (for MS VS 2008) and
building "sub" with devenv yields:
~~~~
D:\[..]\src\caamtest\windows_build\sub>devenv sub.sln /build

Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. Alle Rechte vorbehalten.
1>------ Erstellen übersprungen: Projekt: mainwindow_automoc, Konfiguration: Debug Win32 ------
1>Für diese Projektmappenkonfiguration wurde kein zu erstellendes Projekt ausgewählt.
2>------ Erstellen übersprungen: Projekt: mainlib_automoc, Konfiguration: Debug Win32 ------
2>Für diese Projektmappenkonfiguration wurde kein zu erstellendes Projekt ausgewählt.
3>------ Erstellen gestartet: Projekt: sub_automoc, Konfiguration: Debug Win32 ------
3>Automoc for target sub
[..]
~~~~

"Erstellen übersprungen" means "Building skipped". The automoc for
"mainwindow" is not started.

Inspecting the configuration of the sub.sln with:
  devenv sub.sln -> right click on "Project map" (Projektmappe "sub") ->
   Configuration
reveals that "mainlib_automoc" target is present but disabled (see screen-shot:
subsln_config.png).

I attach my sample project that helps to reproduce the problem.
No tags attached.
tgz caamtest.tgz (16,179) 2013-03-18 07:39
https://public.kitware.com/Bug/file/4685/caamtest.tgz
png subsln_config.png (66,012) 2013-03-18 07:40
https://public.kitware.com/Bug/file/4686/subsln_config.png
png
Issue History
2013-03-18 07:39Piotr PietraszkiewiczNew Issue
2013-03-18 07:39Piotr PietraszkiewiczFile Added: caamtest.tgz
2013-03-18 07:40Piotr PietraszkiewiczFile Added: subsln_config.png
2013-03-18 08:49Rolf Eike BeerNote Added: 0032653
2013-03-18 13:37Piotr PietraszkiewiczNote Added: 0032666
2013-03-19 11:06Piotr PietraszkiewiczNote Added: 0032674
2016-06-10 14:28Kitware RobotNote Added: 0042252
2016-06-10 14:28Kitware RobotStatusnew => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0032653)
Rolf Eike Beer   
2013-03-18 08:49   
include_directories(.) is doomed to cause error. Which directory do you want to add? The current source directory? The current binary directory? Some arbitrary directory from which the compiler is called which likely has no include files of interest in it?
(0032666)
Piotr Pietraszkiewicz   
2013-03-18 13:37   
Indeed. Thank you for your remark.

For my example here the following should do:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96ab7ae..08b66f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,8 +8,7 @@ ADD_DEFINITIONS(${QT_DEFINITIONS})

 ADD_SUBDIRECTORY(sub)

-include_directories(. sub)
-
+include_directories("${CMAKE_SOURCE_DIR}")
 add_library(mainwindow MainWindow.h)
 target_link_libraries(mainwindow ${Qt4_LIBRARIES})

Unfortunately, that doesn't improve the situation much. The "mainwindow_automoc"
target remains disabled in Visual Studio.
(0032674)
Piotr Pietraszkiewicz   
2013-03-19 11:06   
BTW. Dropping "set(CMAKE_AUTOMOC TRUE)" in favour of "QT4_WRAP_CPP" macros
seems to be one way to workaround this problem and to correctly invoke moc on
the top-level dependencies of "sub" even when building with "devenv sub.sln".
(0042252)
Kitware Robot   
2016-06-10 14:28   
Resolving issue as `moved`.

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.