From d5f042c3619674095221459cbacbdefa1cadd56a Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Fri, 27 Sep 2019 16:59:04 -0700 Subject: [PATCH] static link resources --- launchers/qt/CMakeLists.txt | 28 +++++++++------------------- launchers/qt/src/Launcher.cpp | 3 --- launchers/qt/src/LauncherState.h | 2 +- launchers/qt/src/PathUtils.cpp | 4 ++-- launchers/qt/src/PathUtils.h | 4 +++- launchers/qt/src/main.cpp | 1 + 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index 53b1f54796..d54189137c 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -123,8 +123,6 @@ foreach(plugin ${Qt5Gui_PLUGINS}) set(plugin_libs ${plugin_libs} ${_loc}) endforeach() -qt5_add_resources(EXAMPLE_RCC_SRC build/resources.qrc) - set(src_files src/main.cpp src/Launcher.h @@ -143,7 +141,6 @@ set(src_files src/CommandlineOptions.cpp deps/miniz/miniz.h deps/miniz/miniz.cpp - #${RES_SOURCES} ) @@ -167,13 +164,13 @@ set(TARGET_NAME ${PROJECT_NAME}) set_packaging_parameters() if (WIN32) - add_executable(${PROJECT_NAME} ${src_files})#build/resources.qrc ${EXAMPLE_RCC_SRC}) + add_executable(${PROJECT_NAME} ${src_files} ${RES_SOURCES}) elseif (APPLE) set_target_properties(${this_target} PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.in) set(MACOSX_BUNDLE_ICON_FILE "interface.icns") - add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${src_files}) + add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${src_files} ${RES_SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "NO") endif() @@ -222,21 +219,14 @@ if (APPLE) ${OPENSSL_INCLUDE_DIR}) endif() -set(INTERFACE_EXEC_DIR "$") -set(RESOURCES_DEV_DIR "${INTERFACE_EXEC_DIR}/resources") -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${RESOURCES_RCC}" - "${INTERFACE_EXEC_DIR}") - -if (LAUNCHER_SOURCE_TREE_RESOURCES) - target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="${CMAKE_CURRENT_SOURCE_DIR}/resources/") - message("Use source tree resources path: file://${CMAKE_CURRENT_SOURCE_DIR}/resources/") -else() - target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="qrc:/") - message("Use resource.rcc path: qrc:/") -endif() + if (LAUNCHER_SOURCE_TREE_RESOURCES) + target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="${CMAKE_CURRENT_SOURCE_DIR}/resources/") + message("Use source tree resources path: file://${CMAKE_CURRENT_SOURCE_DIR}/resources/") + else() + target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PREFIX_URL="qrc:/") + message("Use resource.rcc path: qrc:/") + endif() target_compile_definitions(${PROJECT_NAME} PRIVATE LAUNCHER_BUILD_VERSION="${BUILD_VERSION}") diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index 96da608f7d..0b51328aef 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -9,9 +9,6 @@ #include "PathUtils.h" Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { - QString resourceBinaryLocation = QGuiApplication::applicationDirPath() + "/resources.rcc"; - qDebug() << "resources.rcc path: " << resourceBinaryLocation; - QResource::registerResource(resourceBinaryLocation); _launcherState = std::make_shared(); _launcherWindow = std::make_unique(); _launcherWindow->rootContext()->setContextProperty("LauncherState", _launcherState.get()); diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index b66d9e90e3..b96440c827 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -130,7 +130,7 @@ public: Q_INVOKABLE float getDownloadProgress() const { return _downloadProgress; } signals: - void updateSourceUrl(QString sourceUrl); + void updateSourceUrl(QUrl sourceUrl); void uiStateChanged(); void applicationStateChanged(); void downloadProgressChanged(); diff --git a/launchers/qt/src/PathUtils.cpp b/launchers/qt/src/PathUtils.cpp index ae02585788..542e268308 100644 --- a/launchers/qt/src/PathUtils.cpp +++ b/launchers/qt/src/PathUtils.cpp @@ -2,6 +2,6 @@ #include -QString PathUtils::resourcePath(const QString& source) { - return QString(RESOURCE_PREFIX_URL + source); +QUrl PathUtils::resourcePath(const QString& source) { + return QUrl(RESOURCE_PREFIX_URL + source); } diff --git a/launchers/qt/src/PathUtils.h b/launchers/qt/src/PathUtils.h index 29d9b609d6..3bfddd624c 100644 --- a/launchers/qt/src/PathUtils.h +++ b/launchers/qt/src/PathUtils.h @@ -2,10 +2,12 @@ #include #include +#include +#include class PathUtils : public QObject { Q_OBJECT public: PathUtils() = default; ~PathUtils() = default; - Q_INVOKABLE static QString resourcePath(const QString& source); + Q_INVOKABLE static QUrl resourcePath(const QString& source); }; diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index 6b2bd39fde..a1c7ab61ca 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -29,6 +29,7 @@ bool hasSuffix(const std::string path, const std::string suffix) { } int main(int argc, char *argv[]) { + Q_INIT_RESOURCE(resources); #ifdef Q_OS_MAC // auto updater if (argc == 3) {