Qt with CMake often leads to trouble during linking.
After reading several posts and tries I found out that AUTOMOC takes source files given with add_executable
but ignores my header files inside the include folder given with include_directories( inc )
. After adding the header filed to add_executable
the build was successful.
But what is the correct way to tell AUTOMOC the header files?
In my CMake CMakeLists.txt I use
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories( inc )
set(QT5_MODULES Widgets)
find_package(Qt5 REQUIRED COMPONENTS ${QT5_MODULES})
add_definitions( -DQT_NO_KEYWORDS
-DQT_CORE_LIB
-DQT_GUI_LIB
-DQT_WIDGETS_LIB
-DQT_NO_DEBUG
-DROSCONSOLE_BACKEND_LOG4CXX
-fPIC)
add_executable( MyGui
src/main.cpp
inc/gui.h src/gui.cpp )
ament_target_dependencies( MyGui )
qt5_use_modules(MyGui ${QT5_MODULES})