1
votes

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.

2
Note that if you put generated files in source directory, it's kinda undermines the whole point of having a separate build dir. Perhaps you should do the "normal" thing and use include paths instead of making such an unusual build configuration.hyde
@hyde I'd be ok with adding the build directory in the include path. Is there a cmake variable that points to this build directory, or would i have to use something like ../../.. .. /build?Shawn Mathew
@hyde Thanks for the tip. I used ${CMAKE_CURRENT_BINARY_DIR} in the includepath.Shawn Mathew

2 Answers

1
votes

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.

0
votes

The AUTOGEN_BUILD_DIR CMake variable specifies where AUTOUIC should generate files. If you want the generated files to be placed in your current source directory, you can set it to CMAKE_CURRENT_SOURCE_DIR:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(AUTOGEN_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR})

An additional note from the CMake-Qt documentation for using AUTOUIC with the AUTOGEN_BUILD_DIR variable:

The generated ui_*.h files are placed in the <AUTOGEN_BUILD_DIR>/include directory which is automatically added to the target’s INCLUDE_DIRECTORIES.

So, you should not have to explicitly list the directory containing the generated headers in an include_directories() command.