From 8abee988e7707a3774d9690bbd58765f29663d45 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Thu, 3 Oct 2024 20:47:45 +0800 Subject: [PATCH] add linux deploy. --- Analyser/CMakeLists.txt | 27 +++++++++- CMakeLists.txt | 3 ++ resources/build.sh | 113 ++++++++++++++++++++++++++++++++++++++++ resources/run.sh.in | 5 ++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100755 resources/build.sh create mode 100644 resources/run.sh.in diff --git a/Analyser/CMakeLists.txt b/Analyser/CMakeLists.txt index 0f5d90c..0b7a88e 100644 --- a/Analyser/CMakeLists.txt +++ b/Analyser/CMakeLists.txt @@ -8,7 +8,7 @@ qt_standard_project_setup(REQUIRES 6.5) configure_file(Configuration.h.in Configuration.h) -add_executable(Analyser Analyser.rc +qt_add_executable(Analyser Analyser.rc main.cpp Application.h Application.cpp CategoryLogSinkBackend.h CategoryLogSinkBackend.cpp @@ -43,6 +43,9 @@ if(UNIX) set_target_properties(Analyser PROPERTIES SUFFIX .AppImage ) + set(EXECUTABLE_NAME Analyser.AppImage) +else() + set(EXECUTABLE_NAME Analyser.exe) endif() if(CMAKE_BUILD_TYPE STREQUAL "Release") set_property(TARGET Analyser PROPERTY @@ -77,3 +80,25 @@ target_link_libraries(Analyser PRIVATE Qt${QT_VERSION_MAJOR}::JpegPrivate PRIVATE Qt${QT_VERSION_MAJOR}::BundledLibjpeg ) + +install(TARGETS Analyser + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +configure_file( + ${CMAKE_SOURCE_DIR}/resources/run.sh.in + ${CMAKE_CURRENT_BINARY_DIR}/scripts/${EXECUTABLE_NAME} + @ONLY +) +install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/scripts/${EXECUTABLE_NAME} DESTINATION .) + +qt_generate_deploy_qml_app_script( + TARGET Analyser + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR + NO_TRANSLATIONS + DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM +) +install(SCRIPT ${deploy_script}) + diff --git a/CMakeLists.txt b/CMakeLists.txt index a373e66..e2f8a46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) +include(CPack) include(FetchContent) FetchContent_Declare(Kylin GIT_REPOSITORY https://gitea.amass.fun/amass/Kylin.git @@ -52,3 +53,5 @@ add_subdirectory(Database) add_subdirectory(Analyser) add_subdirectory(OtaUpdate) add_subdirectory(UnitTest) + +install(DIRECTORY ${CMAKE_BINARY_DIR}/lib DESTINATION .) diff --git a/resources/build.sh b/resources/build.sh new file mode 100755 index 0000000..3db8e4b --- /dev/null +++ b/resources/build.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +base_path=$(pwd) +build_path=${base_path}/build +qt_prefix_path="/opt/Qt/6.7.3/gcc_64" + +debug_deploy=false + +if [ -d ${qt_prefix_path} ]; then # 先找Qt6 + cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \ + -DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \ + -DQT_DIR=${qt_prefix_path}/lib/cmake/Qt6 \ + -DQt6_DIR=${qt_prefix_path}/lib/cmake/Qt6 \ + -DQt6Core_DIR=${qt_prefix_path}/lib/cmake/Qt6Core \ + -DQt6Gui_DIR=${qt_prefix_path}/lib/cmake/Qt6Gui \ + -DQt6Qml_DIR=${qt_prefix_path}/lib/cmake/Qt6Qml \ + -DQt6Widgets_DIR=${qt_prefix_path}/lib/cmake/Qt6Widgets \ + -DQt6Quick_DIR=${qt_prefix_path}/lib/cmake/Qt6Quick \ + -DQt6Svg_DIR=${qt_prefix_path}/lib/cmake/Qt6Svg " +elif [ -d "/opt/Qt/5.15.2/gcc_64" ]; then + qt_prefix_path="/opt/Qt/5.15.2/gcc_64" + cmake_qt_parameters="-DCMAKE_PREFIX_PATH=${qt_prefix_path} \ + -DQT_QMAKE_EXECUTABLE=${qt_prefix_path}/bin/qmake \ + -DQT_DIR=${qt_prefix_path}/lib/cmake/Qt5 \ + -DQt5_DIR=${qt_prefix_path}/lib/cmake/Qt5 \ + -DQt5Core_DIR=${qt_prefix_path}/lib/cmake/Qt5Core \ + -DQt5Gui_DIR=${qt_prefix_path}/lib/cmake/Qt5Gui \ + -DQt5Qml_DIR=${qt_prefix_path}/lib/cmake/Qt5Qml \ + -DQt5Widgets_DIR=${qt_prefix_path}/lib/cmake/Qt5Widgets \ + -DQt5Quick_DIR=${qt_prefix_path}/lib/cmake/Qt5Quick \ + -DQt5Svg_DIR=${qt_prefix_path}/lib/cmake/Qt5Svg " +else + cmake_qt_parameters="" + echo "please install qt6.7.3 or qt5.15.2 ..." +fi + +function cmake_scan() { + if [ ! -d ${build_path} ]; then + mkdir ${build_path} + fi + + if [ $debug_deploy = true ]; then + build_mode=-DCMAKE_BUILD_TYPE=Debug + echo "build application in debug mode." + else + build_mode=-DCMAKE_BUILD_TYPE=Release + echo "build application in release mode." + fi + + + cmake \ + -G Ninja \ + -S ${base_path} \ + -B ${build_path} \ + ${cmake_qt_parameters} \ + $build_mode +} + +function build() { + if [ ! -f "${build_path}/CMakeCache.txt" ]; then + cmake_scan + fi + if [ $? -ne 0 ]; then + exit 1 + fi + cmake \ + --build ${build_path} \ + --target all + if [ $? -ne 0 ]; then + exit 1 + fi +} + +function deploy() { + if [ -d ${build_path}/lib ]; then + rm -fr ${build_path}/lib + fi + mkdir ${build_path}/lib + ldd ${build_path}/Analyser/Analyser.AppImage | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ${build_path}/lib + ldd ${build_path}/Analyser/Analyser.AppImage | grep "ld-linux" | awk '{print $1}' | xargs -I '{}' cp -v '{}' ${build_path}/lib + # ldd ${build_path}/OtaUpdate/SmartLockerUpdater | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ${build_path}/lib + # ldd ${build_path}/OtaUpdate/SmartLockerUpdater | grep "ld-linux" | awk '{print $1}' | xargs -I '{}' cp -v '{}' ${build_path}/lib + + rm ${build_path}/lib/ld-linux-x86-64.so.2 + rm ${build_path}/lib/libc.so.6 + rm ${build_path}/lib/libm.so.6 + rm ${build_path}/lib/libstdc++.so.6 + cd build; cpack; cd .. +} + +function main() { + local cmd=$1 + shift 1 + case $cmd in + build) + build + ;; + scan) + cmake_scan + ;; + clean) + clean + ;; + deploy) + deploy + ;; + *) + build + ;; + esac +} + +main $@ diff --git a/resources/run.sh.in b/resources/run.sh.in new file mode 100644 index 0000000..d596f48 --- /dev/null +++ b/resources/run.sh.in @@ -0,0 +1,5 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="$(dirname "\$0")/lib:$LD_LIBRARY_PATH" + +"$(dirname "\$0")/bin/@EXECUTABLE_NAME@" "$@"