0

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)

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
Zodiac
  • 1
  • 3
  • If you're using cmake 3.11 then you should not set compiler flags by hand. Instead, you should set compiler options which specify compiler flags regardless of which compiler you use. For example, you can use `set (CMAKE_CXX_STANDARD 11)` since cmake 3.1, and also `set_target_properties(FooTarget PROPERTIES CXX_STANDARD 11 CXX_EXTENSIONS OFF)`. – RAM Oct 31 '18 at 09:44

1 Answers1

0

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

Eric Lemanissier
  • 357
  • 2
  • 15