diff --git a/examples/deployqt.cmake b/examples/deployqt.cmake new file mode 100644 index 0000000..de10f06 --- /dev/null +++ b/examples/deployqt.cmake @@ -0,0 +1,61 @@ +#[[ + MIT License + + Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +]] + +function(deploy_qt_libraries arg_target) + find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) + find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) + if(NOT DEFINED QT_QMAKE_EXECUTABLE) + get_target_property(QT_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) + endif() + if(NOT EXISTS "${QT_QMAKE_EXECUTABLE}") + message("Cannot find the QMake executable.") + return() + endif() + get_filename_component(QT_BIN_DIRECTORY "${QT_QMAKE_EXECUTABLE}" DIRECTORY) + find_program(QT_DEPLOY_EXECUTABLE NAMES windeployqt macdeployqt HINTS "${QT_BIN_DIRECTORY}") + if(NOT EXISTS "${QT_DEPLOY_EXECUTABLE}") + message("Cannot find the deployqt tool.") + return() + endif() + if(WIN32) + add_custom_command(TARGET ${arg_target} POST_BUILD COMMAND + "${QT_DEPLOY_EXECUTABLE}" + --dir "$/qml" + --libdir "$" + --plugindir "$/plugins" + --qmldir "$" + --qmlimport "${PROJECT_BINARY_DIR}/imports" + --no-translations + --no-system-d3d-compiler + --no-virtualkeyboard + --no-compiler-runtime + --no-opengl-sw + "$" + ) + elseif(APPLE) + add_custom_command(TARGET ${arg_target} POST_BUILD COMMAND + "${QT_DEPLOY_EXECUTABLE}" "$" + ) + endif() +endfunction() diff --git a/examples/mainwindow/CMakeLists.txt b/examples/mainwindow/CMakeLists.txt index 38c2f52..9e37d07 100644 --- a/examples/mainwindow/CMakeLists.txt +++ b/examples/mainwindow/CMakeLists.txt @@ -57,3 +57,6 @@ target_compile_definitions(MainWindow PRIVATE QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060500 ) + +include(../deployqt.cmake) +deploy_qt_libraries(MainWindow) diff --git a/examples/openglwidget/CMakeLists.txt b/examples/openglwidget/CMakeLists.txt index f3913a3..4ca97d4 100644 --- a/examples/openglwidget/CMakeLists.txt +++ b/examples/openglwidget/CMakeLists.txt @@ -76,3 +76,6 @@ target_compile_definitions(OpenGLWidget PRIVATE QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060500 ) + +include(../deployqt.cmake) +deploy_qt_libraries(OpenGLWidget) diff --git a/examples/quick-blur/CMakeLists.txt b/examples/quick-blur/CMakeLists.txt index 440f5c6..68b4c16 100644 --- a/examples/quick-blur/CMakeLists.txt +++ b/examples/quick-blur/CMakeLists.txt @@ -82,3 +82,6 @@ target_compile_definitions(QuickBlur PRIVATE QT_DISABLE_DEPRECATED_BEFORE=0x060500 $<$,$>:QT_QML_DEBUG> ) + +include(../deployqt.cmake) +deploy_qt_libraries(QuickBlur) diff --git a/examples/quick-blur/scripts/d3d11.bat b/examples/quick-blur/scripts/d3d11.bat index 48187fa..af27dc2 100644 --- a/examples/quick-blur/scripts/d3d11.bat +++ b/examples/quick-blur/scripts/d3d11.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=d3d11 "%~dp0QuickBlur.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/quick-blur/scripts/opengl.bat b/examples/quick-blur/scripts/opengl.bat index 02c2a9c..b66fbab 100644 --- a/examples/quick-blur/scripts/opengl.bat +++ b/examples/quick-blur/scripts/opengl.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=opengl "%~dp0QuickBlur.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/quick-blur/scripts/vulkan.bat b/examples/quick-blur/scripts/vulkan.bat index 330734a..48d8563 100644 --- a/examples/quick-blur/scripts/vulkan.bat +++ b/examples/quick-blur/scripts/vulkan.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=vulkan "%~dp0QuickBlur.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index 7c3b638..e0c8334 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -82,3 +82,6 @@ target_compile_definitions(Quick PRIVATE QT_DISABLE_DEPRECATED_BEFORE=0x060500 $<$,$>:QT_QML_DEBUG> ) + +include(../deployqt.cmake) +deploy_qt_libraries(Quick) diff --git a/examples/quick/scripts/d3d11.bat b/examples/quick/scripts/d3d11.bat index e99cea4..891763d 100644 --- a/examples/quick/scripts/d3d11.bat +++ b/examples/quick/scripts/d3d11.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=d3d11 "%~dp0Quick.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/quick/scripts/opengl.bat b/examples/quick/scripts/opengl.bat index 3206f4e..2b269ca 100644 --- a/examples/quick/scripts/opengl.bat +++ b/examples/quick/scripts/opengl.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=opengl "%~dp0Quick.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/quick/scripts/vulkan.bat b/examples/quick/scripts/vulkan.bat index 04ba74f..949fdc3 100644 --- a/examples/quick/scripts/vulkan.bat +++ b/examples/quick/scripts/vulkan.bat @@ -25,4 +25,4 @@ setlocal set QSG_RHI_BACKEND=vulkan "%~dp0Quick.exe" endlocal -exit /b +exit /b 0 diff --git a/examples/widget-blur/CMakeLists.txt b/examples/widget-blur/CMakeLists.txt index db19bab..768ad5b 100644 --- a/examples/widget-blur/CMakeLists.txt +++ b/examples/widget-blur/CMakeLists.txt @@ -56,3 +56,6 @@ target_compile_definitions(WidgetBlur PRIVATE QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060500 ) + +include(../deployqt.cmake) +deploy_qt_libraries(WidgetBlur) diff --git a/examples/widget/CMakeLists.txt b/examples/widget/CMakeLists.txt index 68e81bb..504f697 100644 --- a/examples/widget/CMakeLists.txt +++ b/examples/widget/CMakeLists.txt @@ -56,3 +56,6 @@ target_compile_definitions(Widget PRIVATE QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060500 ) + +include(../deployqt.cmake) +deploy_qt_libraries(Widget)