CMake & QT5 & Conan // CMAKE_AUTOUIC not generating ui header files

1.4k views Asked by At

I've tried solution given in this thread: CMake & QT5 - QT5_WRAP_UI not generating ui header files but nothing changes.

Here is my first CMakeLists.txt (at the root of the project, which calls the second one)

    cmake_minimum_required (VERSION 3.11.2)
    project(babel)
    include(${CMAKE_SOURCE_DIR}/build/conanbuildinfo.cmake)
    conan_basic_setup()
    subdirs(client)

and the second one is:

    include_directories(${babel_SOURCE_DIR}/client/inc)
    include_directories(${babel_SOURCE_DIR}/common)

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
    set(babel_client_SRCS
    main.cpp
    mainwindow.cpp
    )

    set(CMAKE_CXX_FLAGS "-Wall -fPIC -std=c++11")
    set(CMAKE_AUTOUIC ON)
    set(AUTOGEN_BUILD_DIR ${CMAKE_SOURCE_DIR/client/inc})

    add_executable(babel_client ${babel_client_SRCS})
    target_link_libraries(babel_client ${CONAN_LIBS})

my main.cpp got #include "ui_mainwindow.h" and here is the error output:

[ 33%] Building CXX object client/src/CMakeFiles/babel_client.dir/main.cpp.o
/plopPath/client/src/main.cpp:1:10: fatal error: ui_mainwindow.h: No such file or directory
 #include "ui_mainwindow.h"
      ^~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [client/src/CMakeFiles/babel_client.dir/build.make:63: client/src/CMakeFiles/babel_client.dir/main.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:104: client/src/CMakeFiles/babel_client.dir/all] Error 2
gmake: *** [Makefile:84: all] Error 2

Any Ideas? I've tried putting the set(CMAKE_AUTOUIC ON) at different places in my CMaleLists.txt but it looks like nothing changes (there is NO ui_mainwindow.h created in the project folders)

PS: I'm using the multiplatform binary manager CONAN to get Qt (using Qt without .ui files is working perfectly fine however)

1

There are 1 answers

0
Eric Lemanissier On

As shown in the documentation http://doc.qt.io/qt-5/cmake-manual.html, you have to add the mainwindow.ui file to babel_client_SRCS so that it is then passed to add_executable