Allow disabling .app bundles on Mac

This commit is contained in:
Yen Chi Hsuan 2017-05-06 01:49:52 +08:00
parent 9f819061cd
commit 3822625e77
4 changed files with 27 additions and 15 deletions

View File

@ -37,6 +37,7 @@ option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF) option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF)
option(WITH_ASAN "Enable address sanitizer checks (Linux only)" OFF) option(WITH_ASAN "Enable address sanitizer checks (Linux only)" OFF)
option(WITH_COVERAGE "Use to build with coverage tests (GCC only)." OFF) option(WITH_COVERAGE "Use to build with coverage tests (GCC only)." OFF)
option(WITH_APP_BUNDLE "Enable Application Bundle for OS X" ON)
option(WITH_XC_AUTOTYPE "Include Auto-Type." ON) option(WITH_XC_AUTOTYPE "Include Auto-Type." ON)
option(WITH_XC_HTTP "Include KeePassHTTP and Custom Icon Downloads." OFF) option(WITH_XC_HTTP "Include KeePassHTTP and Custom Icon Downloads." OFF)
@ -77,6 +78,10 @@ endmacro(add_gcc_compiler_flags)
add_definitions(-DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII) add_definitions(-DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII)
if(WITH_APP_BUNDLE)
add_definitions(-DWITH_APP_BUNDLE)
endif()
add_gcc_compiler_flags("-fno-common") add_gcc_compiler_flags("-fno-common")
add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long") add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long")
add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute") add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute")
@ -164,13 +169,13 @@ if(MINGW)
endif() endif()
endif() endif()
if(APPLE OR MINGW) if(APPLE AND WITH_APP_BUNDLE OR MINGW)
set(PROGNAME KeePassXC) set(PROGNAME KeePassXC)
else() else()
set(PROGNAME keepassxc) set(PROGNAME keepassxc)
endif() endif()
if(APPLE AND "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") if(APPLE AND WITH_APP_BUNDLE AND "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
set(CMAKE_INSTALL_PREFIX "/Applications") set(CMAKE_INSTALL_PREFIX "/Applications")
endif() endif()
@ -179,7 +184,7 @@ if(MINGW)
set(BIN_INSTALL_DIR ".") set(BIN_INSTALL_DIR ".")
set(PLUGIN_INSTALL_DIR ".") set(PLUGIN_INSTALL_DIR ".")
set(DATA_INSTALL_DIR "share") set(DATA_INSTALL_DIR "share")
elseif(APPLE) elseif(APPLE AND WITH_APP_BUNDLE)
set(CLI_INSTALL_DIR "/usr/local/bin") set(CLI_INSTALL_DIR "/usr/local/bin")
set(BIN_INSTALL_DIR ".") set(BIN_INSTALL_DIR ".")
set(PLUGIN_INSTALL_DIR "${PROGNAME}.app/Contents/PlugIns") set(PLUGIN_INSTALL_DIR "${PROGNAME}.app/Contents/PlugIns")

View File

@ -216,14 +216,15 @@ if(MINGW)
) )
endif() endif()
add_executable(${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES_MAINEXE} ${WIN32_ProductVersionFiles}) add_executable(${PROGNAME} WIN32 ${keepassx_SOURCES_MAINEXE} ${WIN32_ProductVersionFiles})
target_link_libraries(${PROGNAME} keepassx_core) target_link_libraries(${PROGNAME} keepassx_core)
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON) set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON)
if(APPLE) if(APPLE AND WITH_APP_BUNDLE)
configure_file(${CMAKE_SOURCE_DIR}/share/macosx/Info.plist.cmake ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) configure_file(${CMAKE_SOURCE_DIR}/share/macosx/Info.plist.cmake ${CMAKE_CURRENT_BINARY_DIR}/Info.plist)
set_target_properties(${PROGNAME} PROPERTIES set_target_properties(${PROGNAME} PROPERTIES
MACOSX_BUNDLE ON
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist)
endif() endif()
@ -231,7 +232,7 @@ install(TARGETS ${PROGNAME}
BUNDLE DESTINATION . COMPONENT Runtime BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime) RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime)
if(APPLE) if(APPLE AND WITH_APP_BUNDLE)
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"
DESTINATION "${DATA_INSTALL_DIR}") DESTINATION "${DATA_INSTALL_DIR}")

View File

@ -12,9 +12,15 @@ target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets
if(NOT DEFINED QT_BINARY_DIR) if(NOT DEFINED QT_BINARY_DIR)
set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder") set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder")
endif() endif()
add_custom_command(TARGET keepassx-autotype-cocoa if(WITH_APP_BUNDLE)
add_custom_command(TARGET keepassx-autotype-cocoa
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libkeepassx-autotype-cocoa.so ${PLUGIN_INSTALL_DIR} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libkeepassx-autotype-cocoa.so ${PLUGIN_INSTALL_DIR}
COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app -executable=${PLUGIN_INSTALL_DIR}/libkeepassx-autotype-cocoa.so -no-plugins COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app -executable=${PLUGIN_INSTALL_DIR}/libkeepassx-autotype-cocoa.so -no-plugins
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
COMMENT "Deploying autotype plugin") COMMENT "Deploying autotype plugin")
else()
install(TARGETS keepassx-autotype-cocoa
BUNDLE DESTINATION . COMPONENT Runtime
LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime)
endif()

View File

@ -49,7 +49,7 @@ QString FilePath::pluginPath(const QString& name)
// for TestAutoType // for TestAutoType
pluginPaths << QCoreApplication::applicationDirPath() + "/../src/autotype/test"; pluginPaths << QCoreApplication::applicationDirPath() + "/../src/autotype/test";
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE)
pluginPaths << QCoreApplication::applicationDirPath() + "/../PlugIns"; pluginPaths << QCoreApplication::applicationDirPath() + "/../PlugIns";
#endif #endif
@ -195,7 +195,7 @@ FilePath::FilePath()
else if (testSetDir(QString(KEEPASSX_SOURCE_DIR) + "/share")) { else if (testSetDir(QString(KEEPASSX_SOURCE_DIR) + "/share")) {
} }
#endif #endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) #if defined(Q_OS_UNIX) && !(defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE))
else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) { else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) {
} }
else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) { else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) {
@ -203,7 +203,7 @@ FilePath::FilePath()
else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) { else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) {
} }
#endif #endif
#ifdef Q_OS_MAC #if defined(Q_OS_MAC) && defined(WITH_APP_BUNDLE)
else if (testSetDir(appDirPath + "/../Resources")) { else if (testSetDir(appDirPath + "/../Resources")) {
} }
#endif #endif