From 2ae61cb96b623c38cfd40f5858ddbafc68ecc441 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 13 Oct 2017 10:04:37 -0700 Subject: [PATCH] Prototype packaging QML and related resources into a QRC --- cmake/macros/GenerateQrc.cmake | 20 ++++++++++++++++++++ cmake/templates/resources.qrc.in | 5 +++++ interface/CMakeLists.txt | 22 +++++++++++++++++----- interface/src/Application.cpp | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 cmake/macros/GenerateQrc.cmake create mode 100644 cmake/templates/resources.qrc.in diff --git a/cmake/macros/GenerateQrc.cmake b/cmake/macros/GenerateQrc.cmake new file mode 100644 index 0000000000..0283b3ea9b --- /dev/null +++ b/cmake/macros/GenerateQrc.cmake @@ -0,0 +1,20 @@ + +function(GENERATE_QRC) + set(oneValueArgs OUTPUT PREFIX PATH) + set(multiValueArgs GLOBS) + cmake_parse_arguments(GENERATE_QRC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + if ("${GENERATE_QRC_PREFIX}" STREQUAL "") + set(QRC_PREFIX_PATH /) + else() + set(QRC_PREFIX_PATH ${GENERATE_QRC_PREFIX}) + endif() + + foreach(GLOB ${GENERATE_QRC_GLOBS}) + file(GLOB_RECURSE FOUND_FILES RELATIVE ${GENERATE_QRC_PATH} ${GLOB}) + foreach(FILENAME ${FOUND_FILES}) + set(QRC_CONTENTS "${QRC_CONTENTS}${GENERATE_QRC_PATH}/${FILENAME}\n") + endforeach() + endforeach() + + configure_file("${HF_CMAKE_DIR}/templates/resources.qrc.in" ${GENERATE_QRC_OUTPUT}) +endfunction() diff --git a/cmake/templates/resources.qrc.in b/cmake/templates/resources.qrc.in new file mode 100644 index 0000000000..6466b9ec51 --- /dev/null +++ b/cmake/templates/resources.qrc.in @@ -0,0 +1,5 @@ + + +@QRC_CONTENTS@ + + diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index b16ad58431..08af8601c5 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,6 +1,20 @@ set(TARGET_NAME interface) project(${TARGET_NAME}) +file(GLOB_RECURSE QML_SRC resources/qml/*.qml resources/qml/*.js) +add_custom_target(qml SOURCES ${QML_SRC}) +GroupSources("resources/qml") + +function(JOIN VALUES GLUE OUTPUT) + string (REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}") + string (REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping + set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE) +endfunction() + + +set(INTERFACE_QML_QRC ${CMAKE_CURRENT_BINARY_DIR}/qml.qrc) +generate_qrc(OUTPUT ${INTERFACE_QML_QRC} PATH ${CMAKE_CURRENT_SOURCE_DIR}/resources GLOBS *.qml *.qss *.js *.html *.ttf *.gif *.svg *.png *.jpg) + # set a default root dir for each of our optional externals if it was not passed set(OPTIONAL_EXTERNALS "LeapMotion") @@ -66,9 +80,7 @@ qt5_wrap_ui(QT_UI_HEADERS "${QT_UI_FILES}") # add them to the interface source files set(INTERFACE_SRCS ${INTERFACE_SRCS} "${QT_UI_HEADERS}" "${QT_RESOURCES}") -file(GLOB_RECURSE QML_SRC resources/qml/*.qml resources/qml/*.js) -add_custom_target(qml SOURCES ${QML_SRC}) -GroupSources("resources/qml") +list(APPEND INTERFACE_SRCS ${INTERFACE_QML_QRC}) if (UNIX) install( @@ -131,10 +143,10 @@ if (APPLE) # append the discovered resources to our list of interface sources list(APPEND INTERFACE_SRCS ${DISCOVERED_RESOURCES}) - - set(INTERFACE_SRCS ${INTERFACE_SRCS} "${CMAKE_CURRENT_SOURCE_DIR}/icon/${INTERFACE_ICON_FILENAME}") + list(APPEND INTERFACE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/icon/${INTERFACE_ICON_FILENAME}) endif() + # create the executable, make it a bundle on OS X if (APPLE) add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e5d5e696a1..d41f9d1369 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2246,7 +2246,7 @@ void Application::initializeUi() { offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to // support the window management and scripting proxies for VR use - offscreenUi->createDesktop(QString("hifi/Desktop.qml")); + offscreenUi->createDesktop(QString("qrc:///qml/hifi/Desktop.qml")); // FIXME either expose so that dialogs can set this themselves or // do better detection in the offscreen UI of what has focus