Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tamlok committed May 23, 2024
1 parent 827af10 commit d2de7e2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ aqtinstall.log
tags
CMakeLists.txt.user
build
.DS_Store
55 changes: 36 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ endif()
# Application icon on Windows
set(VX_APP_ICON_RC_WIN data/core/icons/vnote.rc)

# Application icon on macOS
# The MACOSX_BUNDLE_ICON_FILE variable is added to the Info.plist
# generated by CMake. This variable contains the .icns file name,
# without the path.
set(MACOSX_BUNDLE_ICON_FILE vnote.icns)
# And the following tells CMake where to find and install the file itself.
set(VX_APP_ICON_MACOS data/core/icons/vnote.icns)
set_source_files_properties(${VX_APP_ICON_MACOS} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
Expand All @@ -39,21 +42,20 @@ add_custom_target(lrelease DEPENDS ${VX_QM_FILES})

# TODO: VTextEdit translations
list(APPEND VX_QM_FILES
data/core/translations/qdialogbuttonbox_zh_CN.qm
data/core/translations/qtbase_ja.qm
data/core/translations/qtbase_zh_CN.qm
data/core/translations/qtv_ja.qm
data/core/translations/qtv_zh_CN.qm
data/core/translations/qwebengine_zh_CN.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qdialogbuttonbox_zh_CN.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qtbase_ja.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qtbase_zh_CN.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qtv_ja.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qtv_zh_CN.qm
${CMAKE_CURRENT_LIST_DIR}/data/core/translations/qwebengine_zh_CN.qm
)
install(FILES ${VX_QM_FILES} DESTINATION "${CMAKE_INSTALL_BINDIR}/translations" OPTIONAL)

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

add_executable(vnote WIN32
add_executable(vnote WIN32 MACOSX_BUNDLE
application.cpp application.h
commandlineoptions.cpp commandlineoptions.h
fakeaccessible.cpp fakeaccessible.h
Expand Down Expand Up @@ -115,21 +117,36 @@ if(WIN32)
endif()

# Installation
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/vnote_extra.rcc"
DESTINATION ${CMAKE_INSTALL_BINDIR})

if (WIN32)
install(TARGETS vnote RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES "${PROJECT_SOURCE_DIR}/package/qt.conf" DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${VX_EXTRA_RESOURCE_FILES_RCC} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${VX_QM_FILES} DESTINATION "${CMAKE_INSTALL_BINDIR}/translations" OPTIONAL)
elseif(APPLE)
set(CMAKE_MACOSX_BUNDLE OFF)
set(CMAKE_MACOSX_RPATH ON)
install(TARGETS vnote BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

# TODO: declare install for macOS if necessary. For packing, we will manually copy files into
# the src/vnote.app bundle.

# The generated Info.plist will be overridden.
set_target_properties(vnote
PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}"
MACOSX_BUNDLE_INFO_STRING "${PROJECT_DESCRIPTION}"
MACOSX_BUNDLE_GUI_IDENTIFIER "fun.vnote.app"
MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "Distributed under LGPL-3.0 license. Copyright (c) 2024 app.vnote.fun"
)
else()
install(TARGETS vnote
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# TODO: move them to data dir
install(FILES ${VX_EXTRA_RESOURCE_FILES_RCC} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${VX_QM_FILES} DESTINATION "${CMAKE_INSTALL_BINDIR}/translations" OPTIONAL)

set(desktop.path applications)
set(desktop.files data/core/vnote.desktop)
Expand All @@ -147,9 +164,9 @@ else()
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}
foreach(item IN ITEMS desktop icon16 icon32 icon48 icon64 icon128 icon256 iconsvg)
install(FILES ${CMAKE_CURRENT_LIST_DIR}/${${item}.files}
DESTINATION share/${${item}.path}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach()
endif()
Expand Down
23 changes: 16 additions & 7 deletions src/Packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ function(windeployqt target)
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
DEPENDS vnote lrelease
)

add_dependencies(deploy lrelease)
add_dependencies(pack deploy)

install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/winqt/" DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)
Expand Down Expand Up @@ -126,16 +125,26 @@ if(WIN32)

windeployqt(vnote)
elseif(APPLE)
# Manually copy resources.
set(VX_BUNDLE_CONTENTS_DIR $<TARGET_FILE_DIR:vnote>/..)
add_custom_target(deploy
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_LIST_DIR}/data/core/Info.plist" ${VX_BUNDLE_CONTENTS_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${VX_EXTRA_RESOURCE_FILES_RCC} ${VX_BUNDLE_CONTENTS_DIR}/Resources
COMMAND ${CMAKE_COMMAND} -E make_directory ${VX_BUNDLE_CONTENTS_DIR}/Resources/translations
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${VX_QM_FILES} ${VX_BUNDLE_CONTENTS_DIR}/Resources/translations
COMMENT "Copying resources into bundle Contents ${VX_BUNDLE_CONTENTS_DIR}"
DEPENDS vnote lrelease
)
add_dependencies(pack deploy)

message(STATUS "MACDeployQtExecutable: ${MACDEPLOYQT_EXECUTABLE}")
if (MACDEPLOYQT_EXECUTABLE)
message(STATUS "Package generation - MacOS - DMG")

list(APPEND CPACK_GENERATOR External)
set(CPACK_BUNDLE_NAME "${PROJECT_NAME}" )
set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_LIST_DIR}/data/core/Info.plist")
set(CPACK_BUNDLE_ICON "${CMAKE_CURRENT_LIST_DIR}/data/core/icons/vnote.icns")
set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}")
set(CPACK_DMG_FORMAT "UDBZ")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CPackMacDeployQt.cmake.in "${CMAKE_BINARY_DIR}/CPackExternal.cmake")
set(CPACK_EXTERNAL_PACKAGE_SCRIPT "${CMAKE_BINARY_DIR}/CPackExternal.cmake")
include(InstallRequiredSystemLibraries)
Expand Down
11 changes: 9 additions & 2 deletions src/core/configmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,21 @@ void ConfigMgr::initAppPrefixPath()
// Support QFile("app:abc.txt").
QStringList potential_dirs;
auto app_dir_path = QCoreApplication::applicationDirPath();
qInfo() << "executable dir: " << app_dir_path;
qInfo() << "app prefix path: " << app_dir_path;
potential_dirs << app_dir_path;

#if defined(Q_OS_LINUX)
QDir localBinDir(app_dir_path);
if (localBinDir.exists("../local/bin/vnote")) {
auto app_dir_path2 = localBinDir.cleanPath(localBinDir.filePath("../local/bin"));
qInfo() << "executable dir: " << app_dir_path2;
qInfo() << "app prefix path: " << app_dir_path2;
potential_dirs << app_dir_path2;
}
#elif defined(Q_OS_MACOS)
QDir localBinDir(app_dir_path);
if (localBinDir.exists("../Resources")) {
auto app_dir_path2 = localBinDir.cleanPath(localBinDir.filePath("../Resources"));
qInfo() << "app prefix path: " << app_dir_path2;
potential_dirs << app_dir_path2;
}
#endif
Expand Down

0 comments on commit d2de7e2

Please sign in to comment.