From d2de7e2b9cfe078a2ef102f3958d237054983e35 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 23 May 2024 07:53:06 -0700 Subject: [PATCH] fix --- .gitignore | 1 + src/CMakeLists.txt | 55 +++++++++++++++++++++++++++--------------- src/Packaging.cmake | 23 ++++++++++++------ src/core/configmgr.cpp | 11 +++++++-- 4 files changed, 62 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 2a5e9bc31d..50258e8d0f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ aqtinstall.log tags CMakeLists.txt.user build +.DS_Store diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d06c9024d..b0cde80b36 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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") @@ -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 @@ -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) @@ -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() diff --git a/src/Packaging.cmake b/src/Packaging.cmake index b93669226b..2f590a737a 100644 --- a/src/Packaging.cmake +++ b/src/Packaging.cmake @@ -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) @@ -126,16 +125,26 @@ if(WIN32) windeployqt(vnote) elseif(APPLE) + # Manually copy resources. + set(VX_BUNDLE_CONTENTS_DIR $/..) + 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) diff --git a/src/core/configmgr.cpp b/src/core/configmgr.cpp index 047f7ffe98..104da66cbe 100644 --- a/src/core/configmgr.cpp +++ b/src/core/configmgr.cpp @@ -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