Install macOS bundle icons on build

Installs bundle icons to the Resources folder during the build stage and not during the install stage. This ensures that the app has an icon when run directly from the .app folder inside the IDE. Previously, the icon would be installed only when running make install or cpack.
This commit is contained in:
Janek Bevendorff 2025-11-15 00:13:48 +01:00 committed by Janek Bevendorff
parent 5332075193
commit eefee1f092
3 changed files with 23 additions and 19 deletions

View file

@ -67,11 +67,6 @@ if(UNIX AND NOT APPLE AND NOT HAIKU)
install(FILES linux/${APP_ID}.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) install(FILES linux/${APP_ID}.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
endif(UNIX AND NOT APPLE AND NOT HAIKU) endif(UNIX AND NOT APPLE AND NOT HAIKU)
if(APPLE)
install(FILES macosx/Assets.car DESTINATION ${DATA_INSTALL_DIR})
install(FILES macosx/keepassxc.icns DESTINATION ${DATA_INSTALL_DIR})
endif()
if(WIN32) if(WIN32)
install(FILES windows/qt.conf DESTINATION ${BIN_INSTALL_DIR}) install(FILES windows/qt.conf DESTINATION ${BIN_INSTALL_DIR})
endif() endif()

View file

@ -13,11 +13,11 @@
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>${PROGNAME}</string> <string>${PROGNAME}</string>
<key>CFBundleIconFile</key> <key>CFBundleIconFile</key>
<string>keepassxc.icns</string> <string>${MACOSX_BUNDLE_ICON_NAME}.icns</string>
<key>CFBundleIconName</key> <key>CFBundleIconName</key>
<string>keepassxc</string> <string>${MACOSX_BUNDLE_ICON_NAME}</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>org.keepassxc.keepassxc</string> <string>${MACOSX_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>

View file

@ -421,7 +421,12 @@ if(WIN32)
endif() endif()
# Main Executable Definition # Main Executable Definition
add_executable(${PROGNAME} main.cpp)
target_link_libraries(${PROGNAME} keepassxc_gui)
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON)
if(WIN32) if(WIN32)
set_target_properties(${PROGNAME} PROPERTIES WIN32 ON)
include(GenerateProductVersion) include(GenerateProductVersion)
generate_product_version( generate_product_version(
WIN32_ResourceFiles WIN32_ResourceFiles
@ -432,20 +437,24 @@ if(WIN32)
VERSION_PATCH ${KEEPASSXC_VERSION_PATCH} VERSION_PATCH ${KEEPASSXC_VERSION_PATCH}
) )
list(APPEND WIN32_ResourceFiles "${CMAKE_SOURCE_DIR}/share/windows/icon.rc") list(APPEND WIN32_ResourceFiles "${CMAKE_SOURCE_DIR}/share/windows/icon.rc")
endif() target_sources(${PROGNAME} PUBLIC ${WIN32_ResourceFiles})
add_executable(${PROGNAME} WIN32 main.cpp ${WIN32_ResourceFiles}) elseif(APPLE AND WITH_APP_BUNDLE)
target_link_libraries(${PROGNAME} keepassxc_gui) set(MACOSX_BUNDLE_IDENTIFIER org.keepassxc.keepassxc)
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON) set(MACOSX_BUNDLE_ICON_NAME keepassxc)
configure_file("${CMAKE_SOURCE_DIR}/share/macosx/Info.plist.cmake" ${CMAKE_CURRENT_BINARY_DIR}/Info.plist)
# macOS App Bundle install(FILES "${CMAKE_SOURCE_DIR}/share/macosx/embedded.provisionprofile" DESTINATION ${BUNDLE_INSTALL_DIR})
if(APPLE AND WITH_APP_BUNDLE) set(MACOSX_BUNDLE_RESOURCE_FILES
install(FILES ${CMAKE_SOURCE_DIR}/share/macosx/embedded.provisionprofile DESTINATION ${BUNDLE_INSTALL_DIR}) "${CMAKE_SOURCE_DIR}/share/macosx/Assets.car"
configure_file(${CMAKE_SOURCE_DIR}/share/macosx/Info.plist.cmake ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) "${CMAKE_SOURCE_DIR}/share/macosx/keepassxc.icns"
)
set_target_properties(${PROGNAME} PROPERTIES set_target_properties(${PROGNAME} PROPERTIES
MACOSX_BUNDLE ON MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist"
CPACK_BUNDLE_APPLE_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/share/macosx/keepassxc.entitlements") CPACK_BUNDLE_APPLE_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/share/macosx/keepassxc.entitlements"
RESOURCE "${MACOSX_BUNDLE_RESOURCE_FILES}"
)
target_sources(${PROGNAME} PUBLIC ${MACOSX_BUNDLE_RESOURCE_FILES})
if(QT_MAC_USE_COCOA AND EXISTS "${QT_LIBRARY_DIR}/Resources/qt_menu.nib") if(QT_MAC_USE_COCOA AND EXISTS "${QT_LIBRARY_DIR}/Resources/qt_menu.nib")
install(DIRECTORY "${QT_LIBRARY_DIR}/Resources/qt_menu.nib" install(DIRECTORY "${QT_LIBRARY_DIR}/Resources/qt_menu.nib"