diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ec37473c..5fa90173a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,9 @@ include(CheckCXXSourceCompiles) option(WITH_TESTS "Enable building of unit tests" ON) 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_ASAN "Enable address sanitizer checks (Linux 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_APP_BUNDLE "Enable Application Bundle for OS X" ON) +option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON) option(WITH_XC_AUTOTYPE "Include Auto-Type." ON) option(WITH_XC_HTTP "Include KeePassHTTP and Custom Icon Downloads." OFF) @@ -110,16 +110,20 @@ endif() add_gcc_compiler_cxxflags("-fno-exceptions -fno-rtti") add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual") add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings") + if(WITH_ASAN) - if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") - message(FATAL_ERROR "WITH_ASAN is only supported on Linux at the moment.") + if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE)) + message(FATAL_ERROR "WITH_ASAN is only supported on Linux / macOS at the moment.") endif() add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN") - if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) - add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)) + add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN") + endif() endif() + endif() string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) @@ -216,17 +220,36 @@ if(WITH_TESTS) enable_testing() endif(WITH_TESTS) -find_package(Qt5Core 5.2 REQUIRED) -find_package(Qt5Network 5.2 REQUIRED) -find_package(Qt5Concurrent 5.2 REQUIRED) -find_package(Qt5Widgets 5.2 REQUIRED) -find_package(Qt5Test 5.2 REQUIRED) -find_package(Qt5LinguistTools 5.2 REQUIRED) -find_package(Qt5Network 5.2 REQUIRED) -if (UNIX AND NOT APPLE) - find_package(Qt5DBus 5.2 REQUIRED) +if(UNIX AND NOT APPLE) + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools DBus REQUIRED) +elseif(APPLE) + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools REQUIRED + HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH + ) + find_package(Qt5 COMPONENTS MacExtras + HINTS /usr/local/Cellar/qt/*/lib/cmake ENV PATH + ) +else() + find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools REQUIRED) 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_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 build in macOS") + else() + message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}") + endif() +endif() # Debian sets the the build type to None for package builds. # Make sure we don't enable asserts there. @@ -240,17 +263,8 @@ find_package(ZLIB REQUIRED) set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR}) -check_cxx_source_compiles(" - #include - - #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1200) - #error zlib 1.2.x or higher is required to use the gzip format - #endif - - int main() { return 0; }" ZLIB_SUPPORTS_GZIP) - -if(NOT ZLIB_SUPPORTS_GZIP) - message(FATAL_ERROR "zlib 1.2.x or higher is required to use the gzip format") +if(ZLIB_VERSION_STRING VERSION_LESS "1.2.0") + message(FATAL_ERROR "zlib 1.2.0 or higher is required to use the gzip format") endif() # Optional diff --git a/README.md b/README.md index 669b0b666..e379123c1 100644 --- a/README.md +++ b/README.md @@ -70,10 +70,12 @@ cmake accepts the following options: -DWITH_TESTS=[ON|OFF] Enable/Disable building of unit tests (default: ON) -DWITH_GUI_TESTS=[ON|OFF] Enable/Disable building of GUI tests (default: OFF) -DWITH_DEV_BUILD=[ON|OFF] Enable/Disable deprecated method warnings (default: OFF) - -DWITH_ASAN=[ON|OFF] Enable/Disable address sanitizer checks (Linux only) (default: OFF) + -DWITH_ASAN=[ON|OFF] Enable/Disable address sanitizer checks (Linux / macOS only) (default: OFF) -DWITH_COVERAGE=[ON|OFF] Enable/Disable coverage tests (GCC only) (default: OFF) ``` +:exclamation: When building with ASan support on macOS, you need to use `export ASAN_OPTIONS=detect_leaks=0` before running the tests (no LSan support in macOS). + ### Contributing We are always looking for suggestions how to improve our application. If you find any bugs or have an idea for a new feature, please let us know by opening a report in our [issue tracker](https://github.com/keepassxreboot/keepassxc/issues) on GitHub or join us on IRC on freenode channels #keepassxc or #keepassxc-dev. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd8a1fd33..3d5e7bf48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -234,6 +234,9 @@ target_link_libraries(keepassx_core if(APPLE) target_link_libraries(keepassx_core "-framework Foundation") + if(Qt5MacExtras_FOUND) + target_link_libraries(keepassx_core Qt5::MacExtras) + endif() endif() if (UNIX AND NOT APPLE) target_link_libraries(keepassx_core Qt5::DBus) @@ -264,13 +267,7 @@ if(APPLE AND WITH_APP_BUNDLE) set_target_properties(${PROGNAME} PROPERTIES MACOSX_BUNDLE ON 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") install(DIRECTORY "${QT_LIBRARY_DIR}/Resources/qt_menu.nib" DESTINATION "${DATA_INSTALL_DIR}") @@ -284,16 +281,17 @@ if(APPLE AND WITH_APP_BUNDLE) set(CPACK_PACKAGE_FILE_NAME "${PROGNAME}-${KEEPASSXC_VERSION}") 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} POST_BUILD - COMMAND ${QT_BINARY_DIR}/macdeployqt ${PROGNAME}.app + COMMAND ${MACDEPLOYQT_EXE} ${PROGNAME}.app WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src COMMENT "Deploying app bundle") endif() +install(TARGETS ${PROGNAME} + BUNDLE DESTINATION . COMPONENT Runtime + RUNTIME DESTINATION ${BIN_INSTALL_DIR} COMPONENT Runtime) + if(MINGW) if(${CMAKE_SIZEOF_VOID_P} EQUAL "8") set(OUTPUT_FILE_POSTFIX "Win64") diff --git a/src/autotype/mac/CMakeLists.txt b/src/autotype/mac/CMakeLists.txt index ac93de0e7..08c532784 100644 --- a/src/autotype/mac/CMakeLists.txt +++ b/src/autotype/mac/CMakeLists.txt @@ -9,14 +9,12 @@ set(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") 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) add_custom_command(TARGET keepassx-autotype-cocoa POST_BUILD 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 COMMENT "Deploying autotype plugin") else() diff --git a/utils/fix_mac.sh b/utils/fix_mac.sh deleted file mode 100755 index 2e4e84e5e..000000000 --- a/utils/fix_mac.sh +++ /dev/null @@ -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