1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

Compile sdrbase resources as a binary resource file loaded dynamically

This commit is contained in:
f4exb 2018-02-18 23:01:02 +01:00
parent 405c24d1e0
commit a85adbfe0f
5 changed files with 106 additions and 7 deletions

View File

@ -223,6 +223,13 @@ include_directories(
${OPENGL_INCLUDE_DIR}
)
##############################################################################
# External binary resources
include(${CMAKE_SOURCE_DIR}/cmake/include/Qt5ExternalResources.cmake)
qt5_add_external_resources(sdrbase.rcc sdrbase/resources/res.qrc)
##############################################################################
# main GUI application
@ -318,6 +325,7 @@ install(TARGETS sdrangelsrv DESTINATION bin)
#install files and directories
install(DIRECTORY udev-rules DESTINATION share/sdrangel)
install(FILES udev-rules/install.sh DESTINATION share/sdrangel/udev-rules PERMISSIONS WORLD_EXECUTE)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sdrbase.rcc DESTINATION bin)
##############################################################################

View File

@ -0,0 +1,80 @@
#
# External resource support for CMake's Qt5 support, version 1.0
# written by Grzegorz Antoniak <ga -at- anadoxin -dot- org>
# http://github.com/antekone/qt5-external-resources-cmake
#
# Tested on CMake 3.2.2
# qt5_parse_rcc_depends function
#
# Based on original Qt5CoreMacros.cmake/qt5_add_resources function.
function(QT5_PARSE_RCC_DEPENDS infile)
set(_RC_DEPENDS)
if(EXISTS "${infile}")
# parse file for dependencies
# all files are absolute paths or relative to the location of the qrc file
file(READ "${infile}" _RC_FILE_CONTENTS)
string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
foreach(_RC_FILE ${_RC_FILES})
string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
if(NOT IS_ABSOLUTE "${_RC_FILE}")
set(_RC_FILE "${rc_path}/${_RC_FILE}")
endif()
set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
endforeach()
# Since this cmake macro is doing the dependency scanning for these files,
# let's make a configured file and add it as a dependency so cmake is run
# again when dependencies need to be recomputed.
qt5_make_output_file("${infile}" "" "qrc.depends" out_depends)
configure_file("${infile}" "${out_depends}" COPYONLY)
set(out_depends_return ${out_depends} PARENT_SCOPE)
set(_RC_DEPENDS_RETURN ${_RC_DEPENDS} PARENT_SCOPE)
else()
# The .qrc file does not exist (yet). Let's add a dependency and hope
# that it will be generated later
set(out_depends)
endif()
endfunction()
# qt5_add_external_resources function
#
# Usage:
#
# qt5_add_external_resources(outfile res/infile.qrc)
#
# This should generate ${CMAKE_BINARY_DIR}/outfile.rcc, ready to be used inside
# the application. You can also use it like this:
#
# qt5_add_external_resources(outfile res/infile.qrc OPTIONS -someoption)
#
# if you would like to add some option to the RCC's command line.
function(QT5_ADD_EXTERNAL_RESOURCES rccfilename qrcfilename)
set(options)
set(oneValueArgs)
set(multiValueArgs OPTIONS)
cmake_parse_arguments(_RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(rcc_files ${_RCC_UNPARSED_ARGUMENTS})
set(rcc_options ${_RCC_OPTIONS})
get_filename_component(outfilename ${rccfilename} NAME_WE)
get_filename_component(infile ${qrcfilename} ABSOLUTE)
get_filename_component(rc_path ${infile} PATH)
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfilename}.rcc)
qt5_parse_rcc_depends(${infile})
add_custom_command(OUTPUT ${outfile}
COMMAND ${Qt5Core_RCC_EXECUTABLE}
ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile} -binary
MAIN_DEPENDENCY ${infile}
DEPENDS ${_RC_DEPENDS_RETURN} "${out_depends_return}" VERBATIM)
set(_RC_TARGETNAME "qrc_external_${outfilename}")
add_custom_target(${_RC_TARGETNAME} ALL DEPENDS ${outfile})
endfunction()
# vim:set et:

View File

@ -258,19 +258,12 @@ if (BUILD_DEBIAN)
include_directories(${LIBSERIALDVSRC})
endif (BUILD_DEBIAN)
set(sdrbase_RESOURCES
resources/res.qrc
)
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_SHARED)
qt5_add_resources(sdrbase_RESOURCES_RCC ${sdrbase_RESOURCES})
add_library(sdrbase SHARED
${sdrbase_SOURCES}
${sdrbase_HEADERS_MOC}
${sdrbase_RESOURCES_RCC}
)
include_directories(

View File

@ -26,6 +26,7 @@
#include <QDateTime>
#include <QSysInfo>
#include <QKeyEvent>
#include <QResource>
#include <plugin/plugininstancegui.h>
#include <plugin/plugininstancegui.h>
@ -180,6 +181,14 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
connect(ui->tabInputsView, SIGNAL(currentChanged(int)), this, SLOT(tabInputViewIndexChanged()));
QString applicationDirPath = qApp->applicationDirPath();
if (QResource::registerResource(applicationDirPath + "/sdrbase.rcc")) {
qDebug("MainWindow::MainWindow: registered resource file %s/%s", qPrintable(applicationDirPath), "sdrbase.rcc");
} else {
qWarning("MainWindow::MainWindow: could not register resource file %s/%s", qPrintable(applicationDirPath), "sdrbase.rcc");
}
m_apiAdapter = new WebAPIAdapterGUI(*this);
m_requestMapper = new WebAPIRequestMapper(this);
m_requestMapper->setAdapter(m_apiAdapter);

View File

@ -18,6 +18,7 @@
#include <QDebug>
#include <QSysInfo>
#include <QResource>
#include <unistd.h>
#include "dsp/dspengine.h"
@ -68,6 +69,14 @@ MainCore::MainCore(qtwebapp::LoggerWithFile *logger, const MainParser& parser, Q
loadSettings();
QString applicationDirPath = QCoreApplication::instance()->applicationDirPath();
if (QResource::registerResource(applicationDirPath + "/sdrbase.rcc")) {
qDebug("MainCore::MainCore: registered resource file %s/%s", qPrintable(applicationDirPath), "sdrbase.rcc");
} else {
qWarning("MainCore::MainCore: could not register resource file %s/%s", qPrintable(applicationDirPath), "sdrbase.rcc");
}
m_apiAdapter = new WebAPIAdapterSrv(*this);
m_requestMapper = new WebAPIRequestMapper(this);
m_requestMapper->setAdapter(m_apiAdapter);