qt4cmakesubclassingqtguiros

error for compiling qt gui with cmake along with promoted widget


I have a qt GUI project based on ROS(catkin), it is my cmake

cmake_minimum_required(VERSION 2.8.0)
project(jir_seg)

find_package(catkin REQUIRED COMPONENTS qt_build roscpp)
include_directories(${catkin_INCLUDE_DIRS})

catkin_package()

rosbuild_prepare_qt4(QtCore QtGui)

file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS      include/jir_seg/*.hpp)

QT4_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT4_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT4_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)

add_executable(jir_seg ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})
target_link_libraries(jir_seg ${QT_LIBRARIES} ${catkin_LIBRARIES} )
install(TARGETS jir_seg RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

it's auto generated cmake in catkin, in my project i have a subclass from qgeraphicview (JIRSEGSubClassQGV.hpp) that i promoted a widget to it, the problem is when i compiled this code i get this error

In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/JIRSEG2DWindow.cpp:1:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:   JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg/JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg/JIRSEGMainWindow.hpp:9,
             from /home/vahid/catkin_ws/src/jir_seg/src/JIRSEGMainWindow.cpp:1:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:  JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
In file included from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEG2DWindow.hpp:14:0,
             from /home/vahid/catkin_ws/src/jir_seg/src/../include/jir_seg  /JIRSEGMainWindow.hpp:9,
             from /home/vahid/catkin_ws/src/jir_seg/src/main.cpp:5:
/home/vahid/catkin_ws/build/jir_seg/ui_JIRSEG2DWindow.h:26:33: fatal error:   JIRSEGSubClassQGV.hpp: No such file or directory
compilation terminated.
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/JIRSEGMainWindow.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/JIRSEG2DWindow.cpp.o] Error 1
make[2]: *** [jir_seg/CMakeFiles/jir_seg.dir/src/main.cpp.o] Error 1
make[1]: *** [jir_seg/CMakeFiles/jir_seg.dir/all] Error 2
make: *** [all] Error 2

the header that UIC adds to ui_*.h is '#include "JIRSEGSubClassQGV.hpp"', i tried some ways to solve but none of them doesn't work, any help appreciated.


Solution

  • The CMake has no idea about purpose of directories, so if you put header files inside subdirectory include, you must notify CMake about this using iclude_directories directive:

    include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/jir_seg)