Skip to content

Commit

Permalink
support windows packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed Apr 30, 2024
1 parent 25b556a commit 3b75528
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
cmake_minimum_required (VERSION 3.12)
project(VNote VERSION 3.17.0 LANGUAGES C CXX)
project(VNote
VERSION 3.17.0
DESCRIPTION "A pleasant note-taking platform"
HOMEPAGE_URL "https://app.vnote.fun"
LANGUAGES C CXX)

set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type, defaults to Release")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(QHOTKEY_INSTALL OFF CACHE BOOL "Disable installing QHotKey" FORCE)
add_subdirectory(libs)

add_subdirectory(src)

# TODO: find a better way to organize tests
# add_subdirectory(tests)
2 changes: 1 addition & 1 deletion libs/vtextedit
23 changes: 22 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_INSTALL_BINDIR "." CACHE STRING "Binary dir for install")

set(QT_DEFAULT_MAJOR_VERSION 6 CACHE STRING "Qt version to use (5 or 6), defaults to 6")
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} REQUIRED COMPONENTS Core Gui Network PrintSupport Sql Svg Widgets WebChannel WebEngineWidgets LinguistTools)
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} OPTIONAL_COMPONENTS Core5Compat)
Expand Down Expand Up @@ -31,7 +33,8 @@ qt_add_translation(VX_QM_FILES ${VX_TS_FILES})

# Resources
set(VX_RESOURCE_FILES data/core/core.qrc)
qt_add_binary_resources(VX_EXTRA_RESOURCE data/extra/extra.qrc DESTINATION vnote_extra.rcc)
qt_add_binary_resources(VX_EXTRA_RESOURCE data/extra/extra.qrc DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/vnote_extra.rcc
OPTIONS -compress 9)

add_executable(vnote WIN32 MACOSX_BUNDLE
application.cpp application.h
Expand Down Expand Up @@ -86,3 +89,21 @@ if((QT_DEFAULT_MAJOR_VERSION GREATER 5))
Qt::Core5Compat
)
endif()

# Copy the qt.conf on Windows
if(MSVC)
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(FILES "${PROJECT_SOURCE_DIR}/package/qt.conf"
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

include(${CMAKE_CURRENT_LIST_DIR}/Packaging.cmake)
105 changes: 105 additions & 0 deletions src/Packaging.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# 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)

find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS "${QT_BIN_DIR}")
find_program(LINUXDEPLOY_EXECUTABLE linuxdeploy linuxdeploy-x86_64.AppImage HINTS "${QT_BIN_DIR}")
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${QT_BIN_DIR}")
find_program(MACDEPLOYQTFIX_EXECUTABLE macdeployqtfix.py HINTS "${QT_BIN_DIR}")
find_package(Python)

mark_as_advanced(WINDEPLOYQT_EXECUTABLE LINUXDEPLOY_EXECUTABLE MACDEPLOYQT_EXECUTABLE)

function(windeployqt target)
# Bundle Library Files
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)

if(CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
set(WINDEPLOYQT_ARGS --debug)
else()
set(WINDEPLOYQT_ARGS --release)
endif()

add_custom_target(deploy
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/"
COMMAND "${CMAKE_COMMAND}" -E
env PATH="${QT_BIN_DIR}" "${WINDEPLOYQT_EXECUTABLE}"
${WINDEPLOYQT_ARGS}
--verbose 0
--no-quick-import
--no-opengl-sw
--no-compiler-runtime
--translations zh_CN,ja
--dir "${CMAKE_CURRENT_BINARY_DIR}/winqt/"
$<TARGET_FILE:${target}>
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/generic/"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/styles/"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/winqt/qmltooling/"
COMMENT "Deploying Qt..."
DEPENDS vnote
)

install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/winqt/" DESTINATION ${CMAKE_INSTALL_BINDIR})
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
endfunction()

set(CPACK_PACKAGE_VENDOR "VNoteX")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_CONTACT "Le Tan <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_DESCRIPTION}")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING.LESSER")
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})

set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}")

# Start menu entry on Windows
set(CPACK_PACKAGE_EXECUTABLES "vnote" "VNote")
# Desktop link on Windows
set(CPACK_CREATE_DESKTOP_LINKS "vnote")

set(CPACK_STRIP_FILES TRUE)

# WIX generator
set(CPACK_WIX_UPGRADE_GUID BA25F337-991A-4893-9D8A-AD5E89BAF5C4)
set(CPACK_WIX_PRODUCT_GUID BA25F337-991A-4893-9D8A-AD5E89BAF5C4)
set(CPACK_WIX_LICENSE_RTF "${PROJECT_SOURCE_DIR}/package/lgpl-3.0.rtf")
set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_LIST_DIR}/data/core/icons/vnote.ico")
set(CPACK_WIX_UI_BANNER "${PROJECT_SOURCE_DIR}/package/wix_banner.png")
set(CPACK_WIX_UI_DIALOG "${PROJECT_SOURCE_DIR}/package/wix_dialog.png")

#------------------------------------------------------------------------------
# include CPack, so we get target for packages
set(CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/BundleConfig.cmake")

add_custom_target(pack
COMMAND ${CMAKE_CPACK_COMMAND} "--config" "${CMAKE_BINARY_DIR}/BundleConfig.cmake"
COMMENT "Running CPACK. Please wait..."
DEPENDS vnote)
set(CPACK_GENERATOR)

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

list(APPEND CPACK_GENERATOR ZIP)
message(STATUS "Package generation - Windows - Zip")

find_program(WIX_EXECUTABLE wix HINTS "${QT_BIN_DIR}" DOC "Path to the WiX utility")

if (NOT WIX_EXECUTABLE-NOTFOUND)
list(APPEND CPACK_GENERATOR WIX)
message(STATUS "Package generation - Windows - WiX")
endif()

windeployqt(vnote)
endif()

include(CPack)
2 changes: 1 addition & 1 deletion src/data/core/translations/vnote_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@
<message>
<location filename="../../../unitedentry/helpunitedentry.cpp" line="35"/>
<source>Clear the input except the entry name</source>
<translation>清楚输入但保留入口名字</translation>
<translation>清除输入但保留入口名字</translation>
</message>
<message>
<location filename="../../../unitedentry/helpunitedentry.cpp" line="36"/>
Expand Down

0 comments on commit 3b75528

Please sign in to comment.