Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake & QT5 - QT5_WRAP_UI not generating ui header files

I have a simple CMakeLists.txt that looks like this:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(calculator)

FIND_PACKAGE(Qt5Core)
FIND_PACKAGE(Qt5Gui)
FIND_PACKAGE(Qt5Widgets)

SET(CMAKE_AUTOMOC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(calculator_SOURCES main.cpp mainwindow.cpp)
SET(calculator_HEADERS mainwindow.h)
SET(calculator_FORMS mainwindow.ui)

QT5_WRAP_CPP(calculator_HEADERS_MOC ${calculator_HEADERS})
QT5_WRAP_UI(calculator_FORMS_HEADERS ${calculator_FORMS})

ADD_LIBRARY(calculator_CONFIG ${calculator_HEADERS_MOC} ${calculator_FORMS_HEADERS})
QT5_USE_MODULES(calculator_CONFIG Widgets)

ADD_EXECUTABLE(calculator ${calculator_SOURCES} ${calculator_CONFIG})
QT5_USE_MODULES(calculator Core Gui Widgets)

And when I try to build the project using cmake -G "Unix Makefiles" and subsequently make, the console says that ui_mainwindow.h is not found. What is the problem? Is it my cmake file?


Full Error Output:

[ 22%] Building CXX object CMakeFiles/calculator.dir/mainwindow.cpp.o
/home/centurion/Code/cpp/calculator/mainwindow.cpp:2:27: fatal error: ui_mainwindow.h: No such file or directory
 #include "ui_mainwindow.h"
                           ^
compilation terminated.
make[2]: *** [CMakeFiles/calculator.dir/mainwindow.cpp.o] Error 1
make[1]: *** [CMakeFiles/calculator.dir/all] Error 2
make: *** [all] Error 2
like image 335
Kenny Worden Avatar asked Sep 16 '14 17:09

Kenny Worden


People also ask

What is CMake is used for?

CMake is an open-source, cross-platform tool that uses compiler and platform independent configuration files to generate native build tool files specific to your compiler and platform. The CMake Tools extension integrates Visual Studio Code and CMake to make it easy to configure, build, and debug your C++ project.

Is CMake only for C++?

It has minimal dependencies, requiring only a C++ compiler on its own build system.

Is CMake C or C++?

CMake was written in C++, requires only a C++ compiler to build, and precompiled binaries are available for most systems. Scripting it yourself also typically means you will not be generating native Xcode or Visual Studio workspaces, making Mac and Windows builds limited.

Is Python a CMake?

CMake, the cross-platform build system generator, is now easily installable in Python distributions! This makes creation of cross-platform C/C++ CPython extension modules accessible to many more developers. The official package manager for Pythonpackage manager for PythonPython Package Manager (PyPM) is a Python utility intended to simplify the tasks of locating, installing, upgrading and removing Python packages. It can determine if the most recent version of a software package is installed on a system, and can install or upgrade that package from a local or remote host.https://en.wikipedia.org › wiki › Python_Package_ManagerPython Package Manager - Wikipedia, pip, is available with both Python 2.7 and the recent Python 3.


2 Answers

I was running in the same issue with cmake 3.2.2. Try using

SET(CMAKE_AUTOUIC ON)  

if the ui files are not generated. Maybe the default behaviour changed recently?

like image 50
Goldfishslayer Avatar answered Oct 03 '22 00:10

Goldfishslayer


  1. Use lower-case CMake commands. That has been the sane convention for years.

  2. Why are you using both AUTOMOC and qt5_wrap_cpp? AUTOMOC is designed to replace the macro. http://www.cmake.org/cmake/help/v3.0/manual/cmake-qt.7.html#automoc

  3. If using CMake 2.8.11 or later, then don't use qt5_use_modules. I wrote that as a stop-gap hack until CMake 2.8.11 was released. The target_link_libraries command does what qt5_use_modules does, but better and more-generically. http://doc-snapshot.qt-project.org/qt5-5.3/cmake-manual.html

  4. The library has no sources of its own and is not used. You're clearly 'doing it wrong' here. Move the ${calculator_FORMS_HEADERS} variable usage to the executables sources. Then after addressing point 2, remove the library.

like image 40
steveire Avatar answered Oct 02 '22 22:10

steveire