Skip to content

Commit

Permalink
fix Linux build (#2494)
Browse files Browse the repository at this point in the history
Fix Linux build

TODO: fix application dir path locations with AppImage. Translations and vnote_extra.rcc does not work now.
  • Loading branch information
tamlok authored May 10, 2024
1 parent 522b374 commit 918aa15
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 78 deletions.
93 changes: 50 additions & 43 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ on:

# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled'
required: false
default: false

env:
VNOTE_VER: 3.17.0
CMAKE_VER: 3.24.3

jobs:
build-linux:
name: Build On Ubuntu
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
Expand All @@ -30,15 +37,27 @@ jobs:
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- name: Install a Fresh CMake
run: |
wget --no-verbose https://github.com/Kitware/CMake/releases/download/v${CMAKE_VER}/cmake-${CMAKE_VER}-Linux-x86_64.sh
chmod +x cmake-${CMAKE_VER}-Linux-x86_64.sh
mkdir ${{runner.workspace}}/cmake
sudo ./cmake-${CMAKE_VER}-Linux-x86_64.sh --skip-license --prefix=${{runner.workspace}}/cmake
sudo rm -f /usr/local/bin/cmake /usr/local/bin/cpack
sudo ln -s ${{runner.workspace}}/cmake/bin/cmake /usr/local/bin/cmake
sudo ln -s ${{runner.workspace}}/cmake/bin/cpack /usr/local/bin/cpack
- name: Install linuxdeploy
uses: miurahr/install-linuxdeploy-action@v1
with:
plugins: qt appimage

- name: Install dependencies
- name: Install Dependencies
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libfcitx5-qt-dev tree
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libfcitx5-qt-dev fcitx-libs-dev extra-cmake-modules libxkbcommon-dev
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y tree
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y fuse libxcb-cursor-dev
- name: Cache Qt
id: cache-qt
Expand All @@ -50,15 +69,33 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: 6.5.2
version: 6.5.3
target: desktop
modules: 'qtwebengine qtwebchannel qtpositioning qtpdf qtimageformats qt5compat'
modules: 'qtwebengine qtwebchannel qtpositioning qtpdf qtimageformats qt5compat qtserialport'
tools: 'tools_opensslv3_src'
cache: 'true'

- name: Compile OpenSSLV3
run: |
cd ${Qt6_DIR}/../../Tools/OpenSSLv3/src
./Configure
make -j2
sudo make install
- name: Create Build Dir
run: mkdir build
working-directory: ${{runner.workspace}}

- name: Compile fcitxqt5
run: |
git clone https://github.com/fcitx/fcitx-qt5
cd fcitx-qt5
mkdir build && cd build
cmake -DENABLE_QT5=OFF -DENABLE_QT6=ON ..
make -j2
sudo make install
working-directory: ${{runner.workspace}}/build

- name: Compile qt6ct
run: |
git clone https://github.com/trialuser02/qt6ct qt6ct.git
Expand All @@ -70,42 +107,13 @@ jobs:
- name: Configure Project
run: |
qmake -v
# TODO: libfcitx5
qmake CONFIG+=release -spec linux-g++-64 ${GITHUB_WORKSPACE}/vnote.pro
cmake --version
cmake ${GITHUB_WORKSPACE}
working-directory: ${{runner.workspace}}/build

- name: Build Project
run: make -j$(nproc)
working-directory: ${{runner.workspace}}/build

- name: Install Project
run: |
mkdir AppDir
make install INSTALL_ROOT=${{runner.workspace}}/build/AppDir
tree AppDir
working-directory: ${{runner.workspace}}/build

- name: Package Project
run: |
# Move the lib out to avoid duplication
mv AppDir/usr/lib ./
LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
Qt6_Dir=$QT_HOST_BINS/..
tree $Qt6_Dir
tree $Qt6_Dir/../..
# Copy translations
mkdir -p AppDir/usr/translations
cp $Qt6_Dir/translations/qt_zh_CN.qm AppDir/usr/translations
# Package qt5ct (EXTRA_QT_PLUGINS seems not work)
# EXTRA_QT_PLUGINS="platformthemes/libqt5ct.so;styles/libqt5ct-style.so"
mkdir -p AppDir/usr/plugins/platformthemes
mkdir -p AppDir/usr/plugins/styles
cp $Qt6_Dir/plugins/platformthemes/* AppDir/usr/plugins/platformthemes/
cp $Qt6_Dir/plugins/styles/* AppDir/usr/plugins/styles/
# Package libssl.so and libcrypto.so
Qt_Tools=$Qt6_Dir/../../Tools
linuxdeploy-x86_64.AppImage --appdir ./AppDir --plugin qt --output appimage -l $Qt_Tools/OpenSSL/binary/lib/libcrypto.so.* -l $Qt_Tools/OpenSSL/binary/lib/
tree AppDir
cmake --build . --target pack
working-directory: ${{runner.workspace}}/build

- name: Fix Package
Expand All @@ -122,15 +130,14 @@ jobs:
linuxdeploy-plugin-appimage-x86_64.AppImage --appdir=./squashfs-root
mv VNote*.AppImage ../
popd
mv VNote*.AppImage vnote-linux-x64_v${{env.VNOTE_VER}}.AppImage
cp vnote-linux-x64_v${{env.VNOTE_VER}}.AppImage vnote-linux-x64.AppImage
mv VNote*.AppImage VNote-${{env.VNOTE_VER}}-linux-x64.AppImage
working-directory: ${{runner.workspace}}/build

- name: Archive Artifacts
uses: actions/upload-artifact@v2
with:
name: vnote-linux-x64_v${{env.VNOTE_VER}}
path: ${{runner.workspace}}/build/vnote-linux-x64_v${{env.VNOTE_VER}}.AppImage
name: VNote-${{env.VNOTE_VER}}-linux-x64
path: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64.AppImage

- name: Update Tag
if: github.ref == 'refs/heads/master'
Expand All @@ -143,7 +150,7 @@ jobs:
uses: johnwbyrd/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ${{runner.workspace}}/build/vnote-linux-x64.AppImage
files: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64
release: Continuous Build
tag: continuous-build

Expand All @@ -152,7 +159,7 @@ jobs:
uses: ncipollo/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: ${{runner.workspace}}/build/vnote-linux-x64_v${{env.VNOTE_VER}}.AppImage
artifacts: ${{runner.workspace}}/build/VNote-${{env.VNOTE_VER}}-linux-x64
commit: master
tag: v${{env.VNOTE_VER}}
allowUpdates: true
Expand Down
30 changes: 12 additions & 18 deletions .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,20 @@ jobs:
fail-fast: false
matrix:
config:
- {
name: "Build On Win64 Qt 5.15",
arch: win64_msvc2019_64,
qt: 5.15.2,
qt_modules: qtwebengine,
qt_tools: tools_opensslv3_x64,
qt_major: 5,
- name: "Build On Win64 Qt 5.15"
arch: win64_msvc2019_64
qt: 5.15.2
qt_modules: qtwebengine
qt_tools: tools_opensslv3_x64
qt_major: 5
suffix: "-windows7"
}
- {
name: "Build On Win64 Qt 6.5",
arch: win64_msvc2019_64,
qt: 6.5.2,
qt_modules: "qtwebengine qtwebchannel qtpositioning qtpdf qtimageformats qt5compat",
qt_tools: tools_opensslv3_x64,
qt_major: 6,
- name: "Build On Win64 Qt 6.5"
arch: win64_msvc2019_64
qt: 6.5.3
qt_modules: "qtwebengine qtwebchannel qtpositioning qtpdf qtimageformats qt5compat"
qt_tools: tools_opensslv3_x64
qt_major: 6
suffix: ""
}

steps:
# Checks-out your repository under $GITHUB_WORKSPACE.
Expand Down Expand Up @@ -101,9 +97,7 @@ jobs:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DQT_DEFAULT_MAJOR_VERSION=${{matrix.config.qt_major}} -DOPENSSL_EXTRA_LIB_DIR=${{runner.workspace}}\build\openssl-utils.git\1.1.1j\Win_x64 %GITHUB_WORKSPACE%
cmake --build .
cmake --build . --target=deploy
cmake --build . --target=pack
cmake --build . --target=install
7z x VNote*.zip -o*
dir
working-directory: ${{runner.workspace}}/build
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.12)
cmake_minimum_required (VERSION 3.20)
project(VNote
VERSION 3.17.0
DESCRIPTION "A pleasant note-taking platform"
Expand Down
2 changes: 1 addition & 1 deletion libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
add_subdirectory(QHotKey)
add_subdirectory(QHotkey)
add_subdirectory(vtextedit)
2 changes: 1 addition & 1 deletion libs/vtextedit
Submodule vtextedit updated 1 files
+2 −0 CMakeLists.txt
39 changes: 33 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.20)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand Down Expand Up @@ -106,19 +106,46 @@ if((QT_DEFAULT_MAJOR_VERSION GREATER 5))
endif()

# Copy the qt.conf on Windows
if(MSVC)
if(WIN32)
add_custom_command(TARGET vnote POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/package/qt.conf" $<TARGET_FILE_DIR:vnote>)
endif()

# Installation
if (MSVC)
install(TARGETS vnote
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS vnote
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/vnote_extra.rcc"
DESTINATION ${CMAKE_INSTALL_BINDIR})

if (WIN32)
install(FILES "${PROJECT_SOURCE_DIR}/package/qt.conf"
DESTINATION ${CMAKE_INSTALL_BINDIR})
elseif(APPLE)

else()
set(desktop.path applications)
set(desktop.files data/core/vnote.desktop)
set(icon16.path icons/hicolor/16x16/apps)
set(icon16.files data/core/logo/16x16/vnote.png)
set(icon32.path icons/hicolor/32x32/apps)
set(icon32.files data/core/logo/32x32/vnote.png)
set(icon48.path icons/hicolor/48x48/apps)
set(icon48.files data/core/logo/48x48/vnote.png)
set(icon64.path icons/hicolor/64x64/apps)
set(icon64.files data/core/logo/64x64/vnote.png)
set(icon128.path icons/hicolor/128x128/apps)
set(icon128.files data/core/logo/128x128/vnote.png)
set(icon256.path icons/hicolor/256x256/apps)
set(icon256.files data/core/logo/256x256/vnote.png)
set(iconsvg.path icons/hicolor/scalable/apps)
set(iconsvg.files data/core/logo/vnote.svg)
foreach(items IN ITEMS desktop icon16 icon32 icon48 icon64 icon128 icon256 iconsvg)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/${${items}.files}
DESTINATION share/${${items}.path}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach()
endif()

include(${CMAKE_CURRENT_LIST_DIR}/Packaging.cmake)
16 changes: 16 additions & 0 deletions src/CPackLinuxDeployQt.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
message(STATUS "VX_APPIMAGE_DEST_DIR ${VX_APPIMAGE_DEST_DIR}")
message(STATUS "VX_APPIMAGE_DESKTOP_FILE ${VX_APPIMAGE_DESKTOP_FILE}")

execute_process(
COMMAND ${CMAKE_MAKE_PROGRAM} DESTDIR=${VX_APPIMAGE_DEST_DIR} install
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
execute_process(
COMMAND env QMAKE=${QMAKE_EXECUTABLE} LD_LIBRARY_PATH=/usr/local/lib64:$ENV{LD_LIBRARY_PATH} "${LINUXDEPLOY_EXECUTABLE}" --plugin=qt --output=appimage
--appdir=${VX_APPIMAGE_DEST_DIR} -e ${CMAKE_CURRENT_BINARY_DIR}/vnote -d ${VX_APPIMAGE_DESKTOP_FILE}
-i ${CMAKE_CURRENT_LIST_DIR}/data/core/logo/64x64/vnote.png
-l ${QT_PLUGINS_DIR}/platformthemes/libqgtk3.so
-l /usr/local/lib64/libcrypto.so.3
-l /usr/local/lib64/libssl.so.3
# --exclude-library option does not work as expected
# --exclude-library=libssl.so.1.1,libcrypto.so.1.1,libnss3.so,libnssutil3.so
WORKING_DIRECTORY ${CPACK_PACKAGE_DIRECTORY})
31 changes: 24 additions & 7 deletions src/Packaging.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# from: https://github.com/miurahr/cmake-qt-packaging-example

find_package(Qt${QT_DEFAULT_MAJOR_VERSION} REQUIRED COMPONENTS Core)

get_target_property(QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION)
get_filename_component(QT_BIN_DIR "${QMAKE_EXECUTABLE}" DIRECTORY)
execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)

set(QT_TOOLS_DIR "${QT_BIN_DIR}/../../../Tools")
cmake_path(NORMAL_PATH QT_TOOLS_DIR OUTPUT_VARIABLE QT_TOOLS_DIR)

set(QT_PLUGINS_DIR "${QT_BIN_DIR}/../plugins")
cmake_path(NORMAL_PATH QT_PLUGINS_DIR OUTPUT_VARIABLE QT_PLUGINS_DIR)

# To use the specific version of Qt
set(WINDEPLOYQT_EXECUTABLE "${QT_BIN_DIR}/windeployqt.exe")
Expand All @@ -28,8 +31,6 @@ function(windeployqt target)
endif()
endif()

message(INFO " debug: windeployqt:${WINDEPLOYQT_EXECUTABLE}")

add_custom_target(deploy
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/"
COMMAND "${CMAKE_COMMAND}" -E
Expand All @@ -49,19 +50,19 @@ function(windeployqt target)
)

add_dependencies(deploy lrelease)
add_dependencies(pack deploy)

install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/winqt/" DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)

cmake_path(NORMAL_PATH QT_TOOLS_DIR OUTPUT_VARIABLE QT_TOOLS_DIR)
set(OPENSSL_ROOT_DIR "${QT_TOOLS_DIR}/OpenSSL/Win_x64" CACHE STRING "OpenSSL dir")
file(GLOB OPENSSL_LIBS_FILES "${OPENSSL_ROOT_DIR}/bin/lib*.dll")
cmake_path(NORMAL_PATH OPENSSL_LIBS_FILES OUTPUT_VARIABLE OPENSSL_LIBS_FILES)
install(FILES ${OPENSSL_LIBS_FILES} DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)

message(INFO " debug: OpenSSLExtraLIBDIR:${OPENSSL_EXTRA_LIB_DIR}")
message(STATUS "OpenSSLExtraLIBDIR:${OPENSSL_EXTRA_LIB_DIR}")
file(GLOB OPENSSL_EXTRA_LIB_FILES "${OPENSSL_EXTRA_LIB_DIR}/lib*.dll")
cmake_path(NORMAL_PATH OPENSSL_EXTRA_LIB_FILES OUTPUT_VARIABLE OPENSSL_EXTRA_LIB_FILES)
message(INFO " debug: OpenSSLExtraLibFiles:${OPENSSL_EXTRA_LIB_FILES}")
message(STATUS "OpenSSLExtraLibFiles:${OPENSSL_EXTRA_LIB_FILES}")
install(FILES ${OPENSSL_EXTRA_LIB_FILES} DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)

set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
Expand Down Expand Up @@ -104,9 +105,11 @@ add_custom_target(pack
COMMAND ${CMAKE_CPACK_COMMAND} "--config" "${CMAKE_BINARY_DIR}/BundleConfig.cmake"
COMMENT "Running CPACK. Please wait..."
DEPENDS vnote)
add_dependencies(pack lrelease)

set(CPACK_GENERATOR)

if (WIN32)
if(WIN32)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${QT_BIN_DIR}" DOC "Path to the windeployqt utility")

list(APPEND CPACK_GENERATOR ZIP)
Expand All @@ -120,6 +123,20 @@ if (WIN32)
endif()

windeployqt(vnote)
elseif(APPLE)
else()
message(STATUS "LinuxDeployExecutable: ${LINUXDEPLOY_EXECUTABLE}")
if(LINUXDEPLOY_EXECUTABLE)
message(STATUS "Package generation - Linux - AppImage")

set(CPACK_GENERATOR "External;${CPACK_GENERATOR}")
set(VX_APPIMAGE_DEST_DIR "${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/Linux/External/AppImage")
set(VX_APPIMAGE_DESKTOP_FILE "${VX_APPIMAGE_DEST_DIR}${CMAKE_INSTALL_PREFIX}/share/applications/vnote.desktop")
configure_file(${CMAKE_CURRENT_LIST_DIR}/CPackLinuxDeployQt.cmake.in "${CMAKE_BINARY_DIR}/CPackExternal.cmake")
set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${CMAKE_BINARY_DIR}/CPackExternal.cmake")
endif()

set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_LIST_DIR}/data/core/logo/64x64/vnote.png")
endif()

include(CPack)
2 changes: 1 addition & 1 deletion src/data/core/vnote.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Icon=vnote
Terminal=false
Exec=vnote %F
MimeType=text/markdown;
Categories=Qt;Utility;TextEditor;Office;
Categories=Utility

0 comments on commit 918aa15

Please sign in to comment.