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
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.
It has minimal dependencies, requiring only a C++ compiler on its own build system.
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.
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.
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?
Use lower-case CMake commands. That has been the sane convention for years.
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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With