diff --git a/CMakeLists.txt b/CMakeLists.txt index def89ea89..68a346e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Support Visual Studio Code include(CMakeToolsHelpers OPTIONAL) include(FeatureSummary) +include(KPXCHelpers) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) diff --git a/cmake/KPXCHelpers.cmake b/cmake/KPXCHelpers.cmake new file mode 100644 index 000000000..b7896401a --- /dev/null +++ b/cmake/KPXCHelpers.cmake @@ -0,0 +1,33 @@ +function(kpxc_run_macdeployqt_on_installed_helper_binary app_name installed_binary_relative_path) + # Running macdeployqt on a POST_BUILD copied binary is not useful for CPack, because + # the copied binary will be overriden by the corresponding install(TARGETS) command of the same + # binary. + # Thus, we run macdeployqt using install(CODE) on the already installed binary. + # The precondition is that install(TARGETS) has to be called before this function is called. + set(escaped_prefix "\${CMAKE_INSTALL_PREFIX}") + set(app_bundle_name "${app_name}.app") + set(app_bundle_path "${escaped_prefix}/${app_bundle_name}") + set(installed_binary_path "${escaped_prefix}/${installed_binary_relative_path}") + + if(CMAKE_VERSION VERSION_GREATER "3.14") + set(command_echo "COMMAND_ECHO STDOUT") + else() + set(command_echo "") + endif() + + install(CODE + " +execute_process( + COMMAND + ${MACDEPLOYQT_EXE} + ${app_bundle_path} + -executable=${installed_binary_path} -no-plugins 2> /dev/null + ${command_echo} + RESULT_VARIABLE exit_code +) +if(NOT exit_code EQUAL 0) + message(FATAL_ERROR + \"Running macdeployqt on ${installed_binary_path} failed with exit code \${exit_code}.\") +endif() +") +endfunction() diff --git a/src/autotype/mac/CMakeLists.txt b/src/autotype/mac/CMakeLists.txt index 883eeab73..1f77ac184 100644 --- a/src/autotype/mac/CMakeLists.txt +++ b/src/autotype/mac/CMakeLists.txt @@ -4,15 +4,16 @@ add_library(keepassxc-autotype-cocoa MODULE ${autotype_mac_SOURCES}) set_target_properties(keepassxc-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon") target_link_libraries(keepassxc-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets) +install(TARGETS keepassxc-autotype-cocoa + LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) + if(WITH_APP_BUNDLE) add_custom_command(TARGET keepassxc-autotype-cocoa POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/libkeepassxc-autotype-cocoa.so ${PLUGIN_INSTALL_DIR}/libkeepassxc-autotype-cocoa.so - COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app -executable=${PLUGIN_INSTALL_DIR}/libkeepassxc-autotype-cocoa.so -no-plugins 2> /dev/null WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src - COMMENT "Deploying autotype plugin") -else() - install(TARGETS keepassxc-autotype-cocoa - BUNDLE DESTINATION . COMPONENT Runtime - LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime) + COMMENT "Copying autotype plugin into app bundle") + + kpxc_run_macdeployqt_on_installed_helper_binary( + "${PROGNAME}" "${PLUGIN_INSTALL_DIR}/libkeepassxc-autotype-cocoa.so") endif() diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index f0d6cbd46..b25c6b06d 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -71,10 +71,13 @@ endif() if(APPLE AND WITH_APP_BUNDLE) set(CLI_APP_DIR "${CMAKE_BINARY_DIR}/src/${CLI_INSTALL_DIR}") + add_custom_command(TARGET keepassxc-cli POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/keepassxc-cli ${CLI_APP_DIR}/keepassxc-cli - COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app -executable=${CLI_APP_DIR}/keepassxc-cli -no-plugins 2> /dev/null WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src - COMMENT "Deploying keepassxc-cli") + COMMENT "Copying keepassxc-cli into app bundle") + + kpxc_run_macdeployqt_on_installed_helper_binary( + "${PROGNAME}" "${CLI_INSTALL_DIR}/keepassxc-cli") endif() diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index 589d7f7d8..066d65b81 100755 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -34,9 +34,11 @@ if(WITH_XC_BROWSER) add_custom_command(TARGET keepassxc-proxy POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/keepassxc-proxy ${PROXY_APP_DIR}/keepassxc-proxy - COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app -executable=${PROXY_APP_DIR}/keepassxc-proxy -no-plugins 2> /dev/null WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src - COMMENT "Deploying keepassxc-proxy") + COMMENT "Copying keepassxc-proxy into app bundle") + + kpxc_run_macdeployqt_on_installed_helper_binary( + "${PROGNAME}" "${PROXY_INSTALL_DIR}/keepassxc-proxy") endif() if(WIN32)