CMake errors when building Qt simple app.
-
I want to use Sublime for developing in Qt. So i decided to pick CMake for this job.
here is what i've done so far. (and here is the tutorial I tried)Folder structure
. ├── build ├── CMakeLists.txt └── src ├── CMakeLists.txt ├── main.cpp ├── main.qml └── main.qrcmain.cpp
#include <QApplication> #include <QQmlApplicationEngine> int main(int argc, char** argv) { QApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }main.qml
import QtQuick 2.0 import QtQuick.Controls 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Minimal Qml") }main.qrc
<RCC> <qresource prefix="/"> <file>main.qml</file> </qresource> </RCC>CMakeLists.txt
cmake_minimum_required(VERSION 2.8) find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED) add_subdirectory(src)src/CMakeLists.txt
include_directories(${Qt5Widgets_INCLUDE_DIRS} ${QtQml_INCLUDE_DIRS}) add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} ${${Qt5Quick_DEFINITIONS}}) qt5_add_resources(QT_RESOURCES qml.qrc) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(PROJECT "app") project(${PROJECT}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -fstrict-aliasing -pedantic-errors -pedantic -Wno-deprecated-declarations -Wno-unused-variable") if(NOT DEFINED HEADERS) file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h) endif() if(NOT DEFINED SOURCES) file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) endif() source_group("Header Files" FILES ${HEADERS}) source_group("Source Files" FILES ${SOURCES}) add_executable(${PROJECT} ${HEADERS} ${SOURCES} ${QT_RESOURCES}) target_link_libraries(${PROJECT} Qt5::Widgets Qt5::Qml Qt5::Quick )and here is how I use cmake in terminal
cd build cmake .. make ./app #i would call this command if i have had no errorsafter doing
makecommand, terminal shows me following erros>errors
Scanning dependencies of target MinimalQml_autogen
[ 20%] Automatic MOC and UIC for target MinimalQml
[ 20%] Built target MinimalQml_autogen
Scanning dependencies of target MinimalQml
[ 40%] Building CXX object src/CMakeFiles/MinimalQml.dir/main.cpp.o
make[2]: *** No rule to make target 'src/qrc_qml.cpp', needed by 'src/CMakeFiles/MinimalQml.dir/qrc_qml.cpp.o'. Stop.
make[1]: *** [CMakeFiles/Makefile2:92: src/CMakeFiles/MinimalQml.dir/all] Error 2
make: *** [Makefile:84: all] Error 2