How to add a .qrc file to an executable with CMake
-
wrote on 29 Aug 2021, 12:53 last edited by jkwok678
How can I add the resources.qrc to the executable when the project is seperated by library and executable?
As I have graphics that I want to display on the executable.cmake_minimum_required(VERSION 3.5) project(MyProject VERSION 0.1 LANGUAGES CXX) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Gui Core) add_library(Mylib STATIC map.cpp map.h window.cpp window.h ) add_library(Mylib ::Mylib ALIAS Mylib ) target_include_directories(Mylib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) target_link_libraries(Mylib PUBLIC Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets) set_target_properties(Mylib PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON ) add_executable(MyProject main.cpp ) target_link_libraries(MyProject PUBLIC MyLib::MyLib) set_target_properties(MyProject PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON )
-
wrote on 31 Aug 2021, 15:25 last edited by VRonin
Just add the qrc to the list of sources:
add_library(Mylib STATIC map.cpp map.h window.cpp window.h resources.qrc )
Since you set
AUTORCC ON
everything will be done automatically
1/3