Compiling qml files into rcc files in CMake - c++

I want to make a Qt Quick project using CMake with compiled qml files. I put my QML files into a separate qrc/rcc file in a cmake projekt:
qt5_add_binary_resources("res" "qml.qrc" DESTINATION "qml.rcc")
This works fine so far. Now I wanted to compile them. According to the documentation I only need to change
qt5_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES example.qrc)
add_executable(myapp ${SRC_LIST} ${RESOURCES)
in a project. So I changed my CMakeLists.txt to
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources("QML_RESOURCE" "qml.qrc")
qt5_add_binary_resources("res" ${QML_RESOURCE} DESTINATION "qml.rcc")
But now I get
FAILED: qml.rcc cmd.exe /C "cd /D "D:\buildPath" && C:\Qt\5.12.3\msvc2017_64\bin\rcc.exe --binary --name res --output qml.rcc "D:/buildPath/main_qml.cpp" "D:/buildPath/qmlcache_loader.cpp""
RCC Parse Error: 'D:/buildPath/main_qml.cpp' Line: 1 Column: 1 [Start tag expected.] [2/4 30.3/sec] Automatic MOC for target PROJECT_NAME ninja: build stopped: subcommand failed.
17:10:39: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1. Error while building/deploying project PROJECT_NAME (kit: Desktop Qt 5.12.3 MSVC2017 64bit) When executing step "Build with CMake"
There isn't much information about Qt and CMake, so I don't know what to do about this. I hope someone can give me some advice.
The full working CMakeLists is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
add_executable(${PROJECT_NAME} "main.cpp" ${RESOURCES})
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
The full not working file is
cmake_minimum_required(VERSION 3.1)
project(QtQuickCompiler LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
qt5_add_binary_resources(qml ${RESOURCES} DESTINATION "qml.rcc")
add_executable(${PROJECT_NAME} "main.cpp")
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
This was created using the template projects provided by QtCreator.

Related

CMake, MinGW=Undefined Reference to GetIpAddrTable-> iphlpapi.h

I have a CMake project that works pretty good in Linux, but it doesn't under Windows.
The first issue comes by final linking:
[100%] Linking CXX shared library libProjlib.dll
CMakeFiles\Projlib.dir/objects.a(configserver.cpp.obj): In function `ConfigServer::findAdapter(unsigned long*)':
C:/Users/jose/Documents/git-Projects/Proj/Projlib/configserver.cpp:859: undefined reference to `GetIpAddrTable'
Error 1
findAdapter belongs to C:\Qt\Tools\mingw810_64\x86_64-w64-mingw32\include\iphlpapi.h, but doesn't link automatic
My project is missconfigured, I think. I would like to select the MinGW compiler, automatic through CMakeLists.txt (For now, I configure the compiler means cmake-gui.exe ..), and naturally fix the issue, but I don't know how. (Google didn't gave me a solution)
Please, any help or suggestion, link.. etc. will be wellcomed.
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_PROJECT_NAME "testProject")
project(${CMAKE_PROJECT_NAME})
set(CMAKE_BUILD_TYPE Debug)
if("Windows" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on Windows")
elseif("Linux" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on GNU/Linux :-)")
endif()
set(CMAKE_BUILD_PARALLEL_LEVEL 8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#list(APPEND CMAKE_PREFIX_PATH "/home/enigma/Qt/5.15.2/gcc_64") #linux
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\Tools\\mingw810_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
message(STATUS "___________________________________________________${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(binPath "binDebugProj")
elseif()
set(binPath "binProj")
endif()
set(TMP_BUILD "tmpBuild")
set(Proj_LIB "Projlib")
add_subdirectory(${Proj_LIB} "${CMAKE_SOURCE_DIR}/../${binPath}/${TMP_BUILD}/${Proj_LIB}")
include_directories(${Proj_LIB})
The Solution is:
target_link_libraries(${CARDEA_LIB} PUBLIC Qt5::Core Qt5::Network iphlpapi)
At the end did work. (I was savin in anoter CMakeLists.txt AGGHH, too musch hours today)

Why VS doesn't see included files?

I am a student writing a project. I have created a program (here's the link to SVN: https://mysvn.ru/Ilya_Antonov/antonov_sem_prj). I use CMake to build it and generate the .sln project. But when run it in Visual Studio, there are some errors: the compiler can't open the files "drumswindow.h" and "mainwindow.h" (fatal error C1083). Please, take a look at my CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(MusicSimulator VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)
add_executable(MusicSimulator
mainwindow.ui
mainwindow.cpp
mainwindow.h
main.cpp
drumswindow.ui
drumswindow.cpp
drumswindow.h
keyswindow.ui
keyswindow.cpp
keyswindow.h
images.qrc
drumres.qrc
keysres2.qrc
keysres3.qrc
keysres4.qrc
keysres5.qrc
keysres6.qrc
)
target_link_libraries(MusicSimulator Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Multimedia)
What have I done wrong here?
You don't include the current source dir and therefore the compiler doesn't find it. Either add the current source dir or use the correct include statements (#include "keyswindow.h" for example)

QTCreator cannot build

I have started a project with QTCreator and CMake but without adding anything it has a build error:
Running /Users/hectoresteban/Qt/Tools/CMake/CMake.app/Contents/bin/cmake '-GCodeBlocks - Ninja' /Users/hectoresteban/Documents/C++/Qt/trial in /Users/hectoresteban/Documents/C++/Qt/trial/build.
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
See also "/Users/hectoresteban/Documents/C++/Qt/trial/build/CMakeFiles/CMakeOutput.log".
CMake process exited with exit code 1.
Elapsed time: 00:00.
What should I do? I do not want to build it with Ninja but with a normal Unix Makefile but I do not know how to change the build settings
The initial CMakeLists.txt is:
cmake_minimum_required(VERSION 3.5)
project(trial LANGUAGES CXX)
set(ANDROID_NDK_ROOT "/Users/hectoresteban/Documents/C++/Qt/android-ndk-r21d")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core LinguistTools REQUIRED)
set(TS_FILES trial_en_DE.ts)
add_executable(trial
main.cpp
${TS_FILES}
)
target_link_libraries(trial Qt5::Core)
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})

Unknown CMake command "check_language"

I have a project containing both "normal" code and CUDA code. The whole project is managed by cmake. Now, depending on the availability of CUDA on the target machine I would like to be able to switch the CUDA-files on and off. For that, I intended to use the CMake-command "check_language", and implemented it in the following CMakeLists-file:
cmake_minimum_required(VERSION 3.17)
set(PROJECT_NAME "Hello_World_with_CUDA")
set(PROJECT_VERSION 1.0.0)
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} DESCRIPTION "UPPE pulse propagation library" LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CMAKE_CUDA_COMPILER)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CMAKE_CUDA_COMPILER)
cmake_policy (SET CMP0074 NEW)
set(PROJECT_SRC source/main.cpp source/test.cu)
set(PROJECT_INC include/test.hpp)
set(PROJECT_SRC ${PROJECT_SRC}
${PROJECT_INC})
add_executable(${PROJECT_NAME}
${PROJECT_SRC})
target_include_directories(${PROJECT_NAME} PRIVATE
include)
Nevertheless, I get the error
CMake Error at CMakeLists.txt:17 (check_language):
Unknown CMake command "check_language".
even though I have cmake in the version 3.17.2. Why that, and how can I still use that check? Or do I have to resort to different solutions?
Of course, if I switch out the block
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CMAKE_CUDA_COMPILER)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CMAKE_CUDA_COMPILER)
with
find_package(CUDA QUIET)
if(CUDA_FOUND)
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(USE_CUDA)
else(CUDA_FOUND)
message(STATUS "No CUDA support")
remove_definitions(USE_CUDA)
endif(CUDA_FOUND)
it works, but I intended to use the suggested approach, not the deprecated version.
Add the CheckLanguage module to the CMakeLists.txt file to use enable_language with include(CheckLanguage).
As Tsyvarev posted here

Integrating QT with CMAKE in Mac OS

I am trying to integrate my QT project to my CLION project.
In this case I am having problems with the CMAKE and QT integration.
The content of my CmakeList.txt is:
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/")
find_package(Qt5Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui)
target_link_libraries(helloworld Qt5::Widgets)
But I am getting the following error:
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
Could someone help me?
Thank you
after some tries, I found the solution to my problem.
So I am posting my CMakeList.txt code in case you have the same problem.
cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/clang_64/lib/cmake")
find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui ui/input.ui)
target_link_libraries(BD2_PROYECTO_1 Qt5::Widgets)
I hope this will helpful for you.