From 47bde34671d87f1b4f9ab0c00ab6edd66c2dc8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Mon, 18 Mar 2024 14:10:50 +0800 Subject: [PATCH] update --- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- example/CMakeLists.txt | 10 ++--- example/example.qrc | 1 + example/res/template/src/CMakeLists.txt.in | 48 ++++++++++++++-------- example/src/helper/InitalizrHelper.cpp | 1 + scripts/windows-mingw-publish.ps1 | 2 +- scripts/windows-publish.ps1 | 2 +- 8 files changed, 41 insertions(+), 27 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2f67a136..3d86e852 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -58,7 +58,7 @@ jobs: # 先删除所有dSYM文件,减少包的体积 sudo find /Users/runner/work/FluentUI/Qt/${{ matrix.qt_ver }}/macos/qml -name "*.dSYM" | xargs rm -r # 拷贝依赖 - sudo macdeployqt bin/release/${targetName}.app -qmldir=. -dmg + sudo macdeployqt bin/Release/${targetName}.app -qmldir=. -dmg - uses: actions/upload-artifact@v2 with: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 42ba9767..4455a010 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -74,7 +74,7 @@ jobs: # make sure Qt plugin finds QML sources so it can deploy the imported files export QML_SOURCES_PATHS=./ # 拷贝依赖 - linuxdeploy-x86_64.AppImage --plugin=qt --output=appimage --create-desktop-file --icon-file=${targetName}.svg --executable=bin/release/${targetName} --appdir bin/release/ + linuxdeploy-x86_64.AppImage --plugin=qt --output=appimage --create-desktop-file --icon-file=${targetName}.svg --executable=bin/Release/${targetName} --appdir bin/release/ mv ${{ env.targetName }}-*.AppImage ${{ env.targetName }}.AppImage - uses: actions/upload-artifact@v2 diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 828bf9c0..e0528d8f 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -12,11 +12,7 @@ if(FLUENTUI_BUILD_STATIC_LIB) endif() #设置可执行文件输出目录 -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug) -else() - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/release) -endif() +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}) if(APPLE) set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS) @@ -135,8 +131,8 @@ if(WIN32) endif() #复制FluentUI源码到运行目录下,用于脚手架生成 -file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/source) -file(COPY ${CMAKE_SOURCE_DIR}/src/ DESTINATION ${APPLICATION_DIR_PATH}/source) +file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/source/) +file(COPY ${CMAKE_SOURCE_DIR}/src/ DESTINATION ${APPLICATION_DIR_PATH}/source/) if(QT_VERSION VERSION_GREATER_EQUAL "6.2") #如果是Qt6.2以上,则使用qt_add_qml_module添加资源文件 diff --git a/example/example.qrc b/example/example.qrc index 135e4636..88bdf47f 100644 --- a/example/example.qrc +++ b/example/example.qrc @@ -207,5 +207,6 @@ res/template/src/main.qml.in res/template/src/qml.qrc.in res/template/src/zh_CN.ts.in + res/template/src/README.md.in diff --git a/example/res/template/src/CMakeLists.txt.in b/example/res/template/src/CMakeLists.txt.in index fe360cca..6d1d3717 100644 --- a/example/res/template/src/CMakeLists.txt.in +++ b/example/res/template/src/CMakeLists.txt.in @@ -9,16 +9,12 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(APPLICATION_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/debug) -else() - set(APPLICATION_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/release) -endif() +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}) if(APPLE) - set(APPLICATION_REAL_PATH ${APPLICATION_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS) + set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS) else() - set(APPLICATION_REAL_PATH ${APPLICATION_OUTPUT_DIRECTORY}) + set(APPLICATION_DIR_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) endif() find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick) @@ -27,13 +23,13 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick) find_program(QT_LUPDATE NAMES lupdate) find_program(QT_LRELEASE NAMES lrelease) file(GLOB TS_FILE_PATHS ${CMAKE_CURRENT_LIST_DIR}/ *.ts) -add_custom_target(UpdateTranslations +add_custom_target(Script-UpdateTranslations COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${QT_LUPDATE} ${CMAKE_CURRENT_LIST_DIR} -ts ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_en_US.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${QT_LRELEASE} ${PROJECT_NAME}_zh_CN.ts WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${CMAKE_COMMAND} -E make_directory ${APPLICATION_REAL_PATH}/i18n - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}_en_US.qm ${PROJECT_NAME}_zh_CN.qm ${APPLICATION_REAL_PATH}/i18n + COMMAND ${CMAKE_COMMAND} -E make_directory ${APPLICATION_DIR_PATH}/i18n + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_NAME}_en_US.qm ${PROJECT_NAME}_zh_CN.qm ${APPLICATION_DIR_PATH}/i18n SOURCES ${TS_FILE_PATHS} ) @@ -53,12 +49,7 @@ else() ) endif() -add_dependencies(${PROJECT_NAME} UpdateTranslations) - -set_target_properties(${PROJECT_NAME} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${APPLICATION_OUTPUT_DIRECTORY}" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${APPLICATION_OUTPUT_DIRECTORY}" -) +add_dependencies(${PROJECT_NAME} Script-UpdateTranslations) target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core @@ -86,3 +77,28 @@ if(QT_VERSION_MAJOR EQUAL 6) qt_import_qml_plugins(${PROJECT_NAME}) qt_finalize_executable(${PROJECT_NAME}) endif() + +if (CMAKE_BUILD_TYPE MATCHES "Release") + if (APPLE) + find_program(QT_DEPLOY_QT NAMES macdeployqt) + add_custom_target(Script-DeployRelease + COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist + COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/dist/%1 -qmldir=${CMAKE_CURRENT_LIST_DIR} + COMMENT "Deploying Qt Dependencies After Build........." + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/README.md + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + endif() + if(WIN32) + find_program(QT_DEPLOY_QT NAMES windeployqt) + add_custom_target(Script-DeployRelease + COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_SOURCE_DIR}/dist + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_SOURCE_DIR}/dist + COMMAND ${QT_DEPLOY_QT} ${CMAKE_SOURCE_DIR}/dist/%1.exe -qmldir=${CMAKE_CURRENT_LIST_DIR} + COMMENT "Deploying Qt Dependencies After Build........." + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/README.md + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endif() +endif() diff --git a/example/src/helper/InitalizrHelper.cpp b/example/src/helper/InitalizrHelper.cpp index 0e4d285a..7ae2a741 100644 --- a/example/src/helper/InitalizrHelper.cpp +++ b/example/src/helper/InitalizrHelper.cpp @@ -104,5 +104,6 @@ void InitalizrHelper::generate(const QString& name,const QString& path){ copyFile(":/example/res/template/src/App.qml.in",projectDir.filePath("src/App.qml")); copyFile(":/example/res/template/src/qml.qrc.in",projectDir.filePath("src/qml.qrc")); copyFile(":/example/res/template/src/logo.ico.in",projectDir.filePath("src/logo.ico")); + copyFile(":/example/res/template/src/README.md.in",projectDir.filePath("src/README.md")); return this->success(projectPath); } diff --git a/scripts/windows-mingw-publish.ps1 b/scripts/windows-mingw-publish.ps1 index 861a83d8..08ea5b04 100644 --- a/scripts/windows-mingw-publish.ps1 +++ b/scripts/windows-mingw-publish.ps1 @@ -17,7 +17,7 @@ function Main() { New-Item -ItemType Directory dist # 拷贝exe - Copy-Item bin\release\* dist\ -Force -Recurse | Out-Null + Copy-Item bin\Release\* dist\ -Force -Recurse | Out-Null # 拷贝依赖 windeployqt --qmldir . --plugindir dist\plugins --no-translations --compiler-runtime dist\$targetName # 删除不必要的文件 diff --git a/scripts/windows-publish.ps1 b/scripts/windows-publish.ps1 index df0f5ad4..52ce6771 100644 --- a/scripts/windows-publish.ps1 +++ b/scripts/windows-publish.ps1 @@ -27,7 +27,7 @@ function Main() { New-Item -ItemType Directory dist # 拷贝exe - Copy-Item bin\release\* dist -Force -Recurse | Out-Null + Copy-Item bin\Release\* dist -Force -Recurse | Out-Null # 拷贝依赖 windeployqt --qmldir . --plugindir dist\plugins --no-translations --compiler-runtime dist\$targetName # 删除不必要的文件