From b4ee213de2762116e7da68f3c92a74b31ac51310 Mon Sep 17 00:00:00 2001 From: Qsaker Date: Thu, 23 Nov 2023 13:23:41 +0800 Subject: [PATCH] chore: update files of project --- .cmake/sak_common.cmake | 27 ++++++++++++++++++++++++++- .github/workflows/build-daily.yml | 31 ++++++++++++++++++++++++++++--- CMakeLists.txt | 13 +++++++------ 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/.cmake/sak_common.cmake b/.cmake/sak_common.cmake index 31e52d5b..03cfcce9 100644 --- a/.cmake/sak_common.cmake +++ b/.cmake/sak_common.cmake @@ -8,6 +8,8 @@ add_compile_definitions(SAK_AUTHOR_EMAIL="qsaker@foxmail.com") add_compile_definitions(SAK_GITEE_REPOSITORY_URL="https://gitee.com/qsaker/QtSwissArmyKnife") add_compile_definitions(SAK_GITHUB_REPOSITORY_URL="https://github.com/qsaker/QtSwissArmyKnife") +set(SAK_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/sak) + # Set the suffix of the library. if(${CMAKE_BUILD_TYPE} STREQUAL "Release") @@ -48,9 +50,18 @@ macro(sak_find_qt_package modules) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${modules}) endmacro() +function(sak_copy_glog target) +add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + ${SAK_RUNTIME_OUTPUT_DIRECTORY}/${target}/$) +endfunction() + # Add executable. It can be used by Qt5 and Qt6. function(sak_add_executable target sources) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/sak/${target}") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SAK_RUNTIME_OUTPUT_DIRECTORY}/${target}") if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(${target} MANUAL_FINALIZATION) else() @@ -67,6 +78,8 @@ function(sak_add_executable target sources) target_sources(${target} PRIVATE ${ARGV${INDEX}}) endwhile() + sak_copy_glog(${target}) + if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(${target}) endif() @@ -81,3 +94,15 @@ function(sak_set_target_properties target) TRUE WIN32_EXECUTABLE TRUE) endfunction() + +function(sak_tar_target target) + string(TOLOWER ${target} lower_target) + string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} lower_system_name) + string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} lower_system_processor) + set(TAR_FILE_NAME ${lower_target}-${lower_system_name}-${lower_system_processor}) + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E tar "cf" ${TAR_FILE_NAME}.zip --format=zip ${target} + WORKING_DIRECTORY ${SAK_RUNTIME_OUTPUT_DIRECTORY}) +endfunction() \ No newline at end of file diff --git a/.github/workflows/build-daily.yml b/.github/workflows/build-daily.yml index b5efa4ec..6f8c6368 100644 --- a/.github/workflows/build-daily.yml +++ b/.github/workflows/build-daily.yml @@ -1,5 +1,7 @@ name: build-daily on: push +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: new-release: @@ -11,8 +13,6 @@ jobs: uses: actions/checkout@v3 - name: Delete old release uses: liudonghua123/delete-release-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: release_name: 'continuous' - name: Create Release @@ -20,4 +20,29 @@ jobs: with: tag: 'continuous' allowUpdates: true - \ No newline at end of file + build-for-windows: + runs-on: windows-2019 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install Qt + uses: jurplel/install-qt-action@v3 + with: + version: '6.5.3' + target: 'desktop' + arch: 'win64_msvc2019_64' + dir: ${{ github.workspace }} + modules: 'qtcharts qtserialbus qtserialport qtwebsockets' + - name: Build for Windows + run: | + mkdir build + cd build + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 + cmake -DCMAKE_PREFIX_PATH='${{ github.workspace }}/Qt/6.5.3/win64_msvc2019_64/lib/cmake/Qt6' -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles" ../ + nmake + - name: Upload Release Asset for Windnows + uses: Shopify/upload-to-release@v1 + with: + name: 'continuous' + path: 'build/sak/qtswissarmyknife-windows-amd64.zip' + repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f0dfd9d..e27b73a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,20 +150,21 @@ if(SAK_IMPORT_MODULE_BLUETOOTH) include_directories(src/optional/bluetooth) endif() -sak_add_executable("SwissArmyKnife" ${SAK_APP_SOURCES}) -sak_auto_execute_deployqt(SwissArmyKnife) -sak_set_target_properties(SwissArmyKnife) +sak_add_executable("QtSwissArmyKnife" ${SAK_APP_SOURCES}) +sak_auto_execute_deployqt(QtSwissArmyKnife) +sak_tar_target(QtSwissArmyKnife) +sak_set_target_properties(QtSwissArmyKnife) target_link_libraries( - SwissArmyKnife + QtSwissArmyKnife PRIVATE glog::glog Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::SerialPort Qt${QT_VERSION_MAJOR}::SerialBus) if(SAK_IMPORT_MODULE_BLUETOOTH) - target_link_libraries(SwissArmyKnife PRIVATE Qt${QT_VERSION_MAJOR}::Bluetooth) + target_link_libraries(QtSwissArmyKnife PRIVATE Qt${QT_VERSION_MAJOR}::Bluetooth) endif() install( - TARGETS SwissArmyKnife + TARGETS QtSwissArmyKnife BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})