Improve building of macOS target

This commit is contained in:
Adolfo E. García 2017-10-15 16:27:07 -06:00
parent de065c728f
commit 7198f20d69
4 changed files with 39 additions and 47 deletions

View File

@ -36,7 +36,7 @@ include(CheckCXXSourceCompiles)
option(WITH_TESTS "Enable building of unit tests" ON) option(WITH_TESTS "Enable building of unit tests" ON)
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF) 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 and macOS only)" OFF) option(WITH_ASAN "Enable address sanitizer checks (Linux / macOS 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 macOS" ON) option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON)
@ -112,13 +112,13 @@ add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virt
add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings") add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings")
if(WITH_ASAN) if(WITH_ASAN)
if(NOT (LINUX OR APPLE)) if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE))
message(FATAL_ERROR "WITH_ASAN is only supported on Linux and macOS at the moment.") message(FATAL_ERROR "WITH_ASAN is only supported on Linux / macOS at the moment.")
endif() endif()
add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN")
if(LINUX) if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN")
endif() endif()
@ -220,17 +220,33 @@ if(WITH_TESTS)
enable_testing() enable_testing()
endif(WITH_TESTS) endif(WITH_TESTS)
find_package(Qt5Core 5.2 REQUIRED) if(UNIX AND NOT APPLE)
find_package(Qt5Network 5.2 REQUIRED) find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools DBus REQUIRED)
find_package(Qt5Concurrent 5.2 REQUIRED) elseif(APPLE)
find_package(Qt5Widgets 5.2 REQUIRED) find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools MacExtras REQUIRED
find_package(Qt5Test 5.2 REQUIRED) HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH
find_package(Qt5LinguistTools 5.2 REQUIRED) )
find_package(Qt5Network 5.2 REQUIRED) else()
if (UNIX AND NOT APPLE) find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools REQUIRED)
find_package(Qt5DBus 5.2 REQUIRED)
endif() endif()
if(Qt5Core_VERSION VERSION_LESS "5.2.0")
message(FATAL_ERROR "Qt version 5.2.0 or higher is required")
endif()
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
if(APPLE)
set(CMAKE_MACOSX_RPATH TRUE)
find_program(MACDEPLOYQT_EXE macdeployqt HINTS /usr/local/opt/qt5/bin ENV PATH)
if(NOT MACDEPLOYQT_EXE)
message(FATAL_ERROR "macdeployqt is required to use build in macOS")
else()
message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}")
endif()
endif()
# Debian sets the the build type to None for package builds. # Debian sets the the build type to None for package builds.
# Make sure we don't enable asserts there. # Make sure we don't enable asserts there.

View File

@ -234,6 +234,9 @@ target_link_libraries(keepassx_core
if(APPLE) if(APPLE)
target_link_libraries(keepassx_core "-framework Foundation") target_link_libraries(keepassx_core "-framework Foundation")
if(Qt5MacExtras_FOUND)
target_link_libraries(keepassx_core Qt5::MacExtras)
endif()
endif() endif()
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus) target_link_libraries(keepassx_core Qt5::DBus)
@ -264,13 +267,7 @@ if(APPLE AND WITH_APP_BUNDLE)
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)
endif()
install(TARGETS ${PROGNAME}
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime)
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}")
@ -284,16 +281,17 @@ if(APPLE AND WITH_APP_BUNDLE)
set(CPACK_PACKAGE_FILE_NAME "${PROGNAME}-${KEEPASSXC_VERSION}") set(CPACK_PACKAGE_FILE_NAME "${PROGNAME}-${KEEPASSXC_VERSION}")
include(CPack) include(CPack)
if(NOT DEFINED QT_BINARY_DIR)
set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder")
endif()
add_custom_command(TARGET ${PROGNAME} add_custom_command(TARGET ${PROGNAME}
POST_BUILD POST_BUILD
COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src
COMMENT "Deploying app bundle") COMMENT "Deploying app bundle")
endif() endif()
install(TARGETS ${PROGNAME}
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime)
if(MINGW) if(MINGW)
if(${CMAKE_SIZEOF_VOID_P} EQUAL "8") if(${CMAKE_SIZEOF_VOID_P} EQUAL "8")
set(OUTPUT_FILE_POSTFIX "Win64") set(OUTPUT_FILE_POSTFIX "Win64")

View File

@ -9,14 +9,12 @@ set(autotype_mac_mm_SOURCES
add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES} ${autotype_mac_mm_SOURCES}) add_library(keepassx-autotype-cocoa MODULE ${autotype_mac_SOURCES} ${autotype_mac_mm_SOURCES})
set_target_properties(keepassx-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon") set_target_properties(keepassx-autotype-cocoa PROPERTIES LINK_FLAGS "-framework Foundation -framework AppKit -framework Carbon")
target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets) target_link_libraries(keepassx-autotype-cocoa ${PROGNAME} Qt5::Core Qt5::Widgets)
if(NOT DEFINED QT_BINARY_DIR)
set(QT_BINARY_DIR "/usr/local/opt/qt5/bin" CACHE PATH "QT binary folder")
endif()
if(WITH_APP_BUNDLE) if(WITH_APP_BUNDLE)
add_custom_command(TARGET keepassx-autotype-cocoa 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 ${MACDEPLOYQT_EXE} ${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() else()

View File

@ -1,20 +0,0 @@
#!/bin/bash
# Canonical path to qt5 directory
QT="/usr/local/Cellar/qt"
if [ ! -d "$QT" ]; then
# Alternative (old) path to qt5 directory
QT+="5"
if [ ! -d "$QT" ]; then
echo "Qt/Qt5 not found!"
exit
fi
fi
QT5_DIR="$QT/$(ls $QT | sort -r | head -n1)"
echo $QT5_DIR
# Change qt5 framework ids
for framework in $(find "$QT5_DIR/lib" -regex ".*/\(Qt[a-zA-Z]*\)\.framework/Versions/5/\1"); do
echo "$framework"
install_name_tool -id "$framework" "$framework"
done