Search code examples
qtcmakecatkin

How to force UIC to generate ui_mainwindow.h in the source directory using cmake


UIC successfully creates the ui_mainwindow.h file but it stores it in the build directory. This causes the compile time error 'ui_mainwindow.h: No such file or directory found'.

If I add the full path to the ui_mainwindow.h file in the build directory, cmake (catkin_make) successfully builds the project. Obviously I'd like to avoid using the absolute path to a header file in my source code.

The relevant parts of my CMakeLists:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 REQUIRED COMPONENTS Widgets Core )
add_executable(monitor src/mainwindow.cpp src/main.cpp src/mainwindow.ui)
qt5_use_modules(monitor Widgets)

target_link_libraries(monitor Qt5::Core Qt5::Widgets ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBRARIES} ${OpenCV_LIBS} )

How do I force UIC to build the ui_mainwindow.h file in my source directory. Or how do I include the cmake build directory in my CMakeLists.txt

I've tried

qt5_wrap_ui (monitor_UI src/mainwindow.ui OPTIONS -o 'ui_mainwindow.h')
add_executable(monitor src/mainwindow.cpp src/main.cpp ${monitor_UI})

with no success.


Solution

  • Based on hyde's comment, I simply added the build directory in the includepaths using

    include_directories(
      ${CMAKE_CURRENT_BINARY_DIR}
    )
    

    which solved my problem.