1

I'm new to Qt and I'm trying to convert a .pro file into a CMakeLists.text to use the project with CMake.

OS: Windows 10

.pro files:

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
    main.cpp \
    mainwindow.cpp \
    parallelogrambutton.cpp \
    rombusbutton.cpp \
    scrollarea.cpp \
    skewedbutton.cpp \
    trapezbutton.cpp

HEADERS += \
    mainwindow.h \
    parallelogrambutton.h \
    rombusbutton.h \
    scrollarea.h \
    skewedbutton.h \
    trapezbutton.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    Resources.qrc

The result of manual conversion to CMakeText.txt

cmake_minimum_required(VERSION 3.15)

project(Project)

set(CMAKE_PREFIX_PATH "C:/Qt/5.14.1/mingw73_64")
set(CMAKE_INCLUDE_PATH "C:/Qt/5.14.1/mingw73_64/bin")

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5 COMPONENTS Core Gui REQUIRED)

qt5_add_resources(Resources.qrc)

set(SOURCES
        main.cpp
        mainwindow.cpp
        parallelogrambutton.cpp
        rombusbutton.cpp
        scrollarea.cpp
        skewedbutton.cpp
        trapezbutton.cpp
        )

set(HEADERS
        mainwindow.h
        parallelogrambutton.h
        rombusbutton.h
        scrollarea.h
        skewedbutton.h
        trapezbutton.h
        )

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

qt5_use_modules(${PROJECT_NAME} Core Gui)

But when I'm trying to run this CMake file I'm getting the following error:

The error message:

/<CMAKE_PATH>\cmake.exe --build /<PATH>/cmake-build-debug --target Project -- -j 4
[ 10%] Automatic MOC and UIC for target Project

AutoMoc subprocess error
------------------------
The moc process failed to compile
  "/<PATH>/mainwindow.h"
into
  "/<PATH>/cmake-build-debug/Project_autogen/EWIEGA46WW/moc_mainwindow.cpp".

Command
-------
/<CMAKE_PREFIX_PATH>/bin/moc.exe -I/<PATH>/cmake-build-debug -I/<PATH> -I/<CMAKE_PREFIX_PATH>/include -I/<CMAKE_PREFIX_PATH>/include/QtCore -I/<CMAKE_PREFIX_PATH>/./mkspecs/win32-g++ -I/<CMAKE_PREFIX_PATH>/include/QtGui -I/<CMAKE_PREFIX_PATH>/include/QtANGLE -I/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++ -I/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/x86_64-pc-cygwin -I/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/backward -I/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include -I/usr/include -I/usr/include/w32api -DQT_CORE_LIB -DQT_GUI_LIB --include /<PATH>/cmake-build-debug/Project_autogen/moc_predefs.h -o /<PATH>/cmake-build-debug/Project_autogen/EWIEGA46WW/moc_mainwindow.cpp /<PATH>/mainwindow.h

Output
------

make[3]: *** [CMakeFiles/Project_autogen.dir/build.make:58: CMakeFiles/Project_autogen] Error 1
make[2]: *** [CMakeFiles/Makefile2:104: CMakeFiles/Project_autogen.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/Project.dir/rule] Error 2
make: *** [Makefile:118: Project] Error 2

Can any of you explain to me what I'm doing wrong here?

Mircea
  • 1,671
  • 7
  • 25
  • 41
  • Similar error in the [question](https://stackoverflow.com/questions/60497974/qt-moc-failure-when-building-on-windows-10) here, although no solutions posted for it yet. – Kevin Jun 02 '20 at 14:02

1 Answers1

0

It looks like you are using obsolete CMake commands of Qt, see https://doc.qt.io/qt-5/cmake-command-reference.html.

You can create a new CMake-based project in Qt Creator and take it as a base. Qt Creator v4.12.x will generate something like:

cmake_minimum_required(VERSION 3.15)

project(Project)

set(CMAKE_PREFIX_PATH "C:/Qt/5.14.1/mingw73_64")
set(CMAKE_INCLUDE_PATH "C:/Qt/5.14.1/mingw73_64/bin")

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5 COMPONENTS Core Gui REQUIRED)

set(SOURCES
    main.cpp
    Resources.qrc
    mainwindow.cpp
    parallelogrambutton.cpp
    rombusbutton.cpp
    scrollarea.cpp
    skewedbutton.cpp
    trapezbutton.cpp
)

set(HEADERS
    mainwindow.h
    parallelogrambutton.h
    rombusbutton.h
    scrollarea.h
    skewedbutton.h
    trapezbutton.h
)

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS})

target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui)
Dmitry Sokolov
  • 3,118
  • 1
  • 30
  • 35