summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-08-04 16:16:22 +0200
committerMilian Wolff <milian.wolff@kdab.com>2014-08-07 13:32:41 +0200
commit4ce1fd950d8c20d21c851340350fb2b1dc920ce4 (patch)
tree6913a5e690354884884865ae1dc192a411a3aca4 /examples
parentc18879b89f770ea8964828587e3ab19c32393720 (diff)
downloadqtwebchannel-4ce1fd950d8c20d21c851340350fb2b1dc920ce4.tar.gz
Make standalone example mostly self-contained.
Install qwebchannel.js file and also copy it to the build dir. This makes the examples subdirectory self-contained and useable when compiling it from the install directory. Making individual examples self-contained would cause too much code duplication, so it was not done. Change-Id: Ifeb5eac7d05b92779d24cb4da413f3fb173f992d Reviewed-by: Sumedha Widyadharma <sumedha.widyadharma@basyskom.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qwebchannel/exampleassets.pri31
-rw-r--r--examples/qwebchannel/standalone/index.html2
-rw-r--r--examples/qwebchannel/standalone/main.cpp2
-rw-r--r--examples/qwebchannel/standalone/standalone.pro7
4 files changed, 38 insertions, 4 deletions
diff --git a/examples/qwebchannel/exampleassets.pri b/examples/qwebchannel/exampleassets.pri
new file mode 100644
index 0000000..035ca12
--- /dev/null
+++ b/examples/qwebchannel/exampleassets.pri
@@ -0,0 +1,31 @@
+# This adds the qwebchannel js library to an example, creating a self-contained bundle
+QTDIR_build {
+ # Build from within Qt. Copy and install the reference lib.
+ jslib = $$dirname(_QMAKE_CONF_)/src/webchannel/qwebchannel.js
+ copyfiles = $$jslib
+} else {
+ # This is what an actual 3rd party project would do.
+ jslib = qwebchannel.js
+}
+
+# This installs all assets including qwebchannel.js, regardless of the source.
+exampleassets.files += $$jslib
+INSTALLS += exampleassets
+
+# This code ensures that all assets are present in the build directory.
+
+!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
+ # Shadow build, copy all example assets.
+ copyfiles = $$exampleassets.files
+}
+
+defineReplace(stripSrcDir) {
+ return($$basename(1))
+}
+
+assetcopy.input = copyfiles
+assetcopy.output = $$OUT_PWD/${QMAKE_FUNC_FILE_IN_stripSrcDir}
+assetcopy.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
+assetcopy.name = COPY ${QMAKE_FILE_IN}
+assetcopy.CONFIG = no_link target_predeps
+QMAKE_EXTRA_COMPILERS += assetcopy
diff --git a/examples/qwebchannel/standalone/index.html b/examples/qwebchannel/standalone/index.html
index 8c85143..778a502 100644
--- a/examples/qwebchannel/standalone/index.html
+++ b/examples/qwebchannel/standalone/index.html
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script type="text/javascript" src="../../../src/webchannel/qwebchannel.js"></script>
+ <script type="text/javascript" src="./qwebchannel.js"></script>
<script type="text/javascript">
//BEGIN SETUP
function output(message)
diff --git a/examples/qwebchannel/standalone/main.cpp b/examples/qwebchannel/standalone/main.cpp
index cc22ed3..fa3912d 100644
--- a/examples/qwebchannel/standalone/main.cpp
+++ b/examples/qwebchannel/standalone/main.cpp
@@ -139,7 +139,7 @@ int main(int argc, char** argv)
channel.registerObject(QStringLiteral("dialog"), &dialog);
// open a browser window with the client HTML page
- QUrl url = QUrl::fromLocalFile(SOURCE_DIR "/index.html");
+ QUrl url = QUrl::fromLocalFile(BUILD_DIR "/index.html");
url.setQuery(QStringLiteral("webChannelBaseUrl=") + server.serverUrl().toString());
QDesktopServices::openUrl(url);
diff --git a/examples/qwebchannel/standalone/standalone.pro b/examples/qwebchannel/standalone/standalone.pro
index 6b96169..fdeb87a 100644
--- a/examples/qwebchannel/standalone/standalone.pro
+++ b/examples/qwebchannel/standalone/standalone.pro
@@ -14,6 +14,9 @@ HEADERS += \
FORMS += \
dialog.ui
-DEFINES += "SOURCE_DIR=\"\\\""$$PWD"\\\"\""
+DEFINES += "BUILD_DIR=\"\\\""$$OUT_PWD"\\\"\""
-EXAMPLE_FILES += index.html
+exampleassets.files += \
+ index.html
+exampleassets.path = $$[QT_INSTALL_EXAMPLES]/qwebchannel/standalone
+include(../exampleassets.pri)