Question

There is a medium-sized project with a top level CMakeLists.txt which defines some common stuff and invokes the configuration of all artifacts (subprojects) in the project like this:

add_subdirectory(components/A)
add_subdirectory(components/B)
add_subdirectory(components/C)

add_subdirectory(components/E)

Artifacts are static/shared libraries or executables (which somehow depend on each other). In this example, there is only one executable: E. Everything configures and builds perfectly fine when plain old qt4_wrap_cpp is used to process MOC.

When switching to the (relatively) new AUTOMOC feature by adding the following to the top CMakeLists.txt:

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

all the sources of static/shared libraries are AUTOMOC'ed just fine. However, the sources of executable target (E in this example) are never AUTOMOC'ed.

I've tried both MSYS Makefiles and Ninja generators, and both simply do not create the target for AUTOMOC'ing, but only for executable's sources (for static/shared library targets AUTOMOC'ing target is added).

  • Has anyone experienced that already?
  • What could be the cause?
  • Does that smell like a bug?

Update


I found the cause, the discussion is on CMake mailing list.

Was it helpful?

Solution

To summarize, the problem was that E didn't include Qt module neither explicitly:

find_package(Qt4 ...)

nor implicitly:

find_package(MyPrecious ...)

where MyPrecious could be some 3rd party module which includes Qt by itself.

As a result, non-cached variables like QT_VERSION_* are not present in the scope of E subproject, and for that reason AUTOMOC feature cannot function properly. Nasty pitfall I'd say. For more details refer to CMake mailing list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top