1

I'm using Qt 5 and I put all my headers in separate include folders, and AUTOMOC is unable to find my headers.

src
 |- sim
     |- include
         |- sim
            |- client.h (contains Q_OBJECT)
     |- client.cpp

My CMake Code:

set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
add_library(client client.cpp)
target_include_directories(client PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>)
target_link_libraries(client sim Qt5::Widgets)

This results in undefined references to my signals because the QObject MOC class in client is not being generated. I tried adding this to force it to search for client.h...

#include "moc_client.cpp"

However then I get the error

AutoMoc error
-------------
  "/home/peter/projects/smartmouse/smartmouse-simulator/src/sim/client.cpp"
The file includes the moc file "moc_client.cpp", but the header "client.{h,hh,h++,hm,hpp,hxx,in,txx}" could not be found.

I get why this is, because the docs only say it searches the current folder so it's not going to look int the include/sim folder. My question is how do I get AUTOMOC to find include/sim/client.h?

I also tried using qt5_wrap_cpp but it doesn't seem to actually call the moc compiler, it only sets up some information. I tried:

qt5_wrap_cpp(client include/sim/client.h)

But it did not generate any cmake targets as far as I can tell

EDIT:

I've also noticed in the AutogenInfo.cmake file that no header is found: set(AM_HEADERS "")

Peter Mitrano
  • 2,132
  • 28
  • 31

1 Answers1

1

I just ran into this similar issue and while I'm not satisfied with this answer, it might be helpful.

CMAKE_AUTOMOC is not picking up client.cpp's #include "sim/client.h" but you can manually add it to the target sources:

add_library(client client.cpp include/sim/client.h)

roschach
  • 8,390
  • 14
  • 74
  • 124
dhalinar
  • 11
  • 1