2017-06-09 23:40:36 +02:00
|
|
|
# Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2018-01-17 00:56:47 +01:00
|
|
|
# Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
2010-08-07 15:10:44 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
# version 3 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-12-20 08:25:55 +00:00
|
|
|
cmake_minimum_required(VERSION 3.1.0)
|
|
|
|
|
|
|
|
project(KeePassXC)
|
|
|
|
|
2013-11-24 22:09:52 +01:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
2016-12-02 03:55:09 +00:00
|
|
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo Debug DebugFull Profile MinSizeRel."
|
2013-11-24 22:09:52 +01:00
|
|
|
FORCE)
|
|
|
|
endif()
|
|
|
|
|
2012-05-21 23:37:29 +02:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
2010-09-11 19:49:30 +02:00
|
|
|
|
2017-05-05 20:20:27 -04:00
|
|
|
# Support Visual Studio Code
|
|
|
|
include(CMakeToolsHelpers OPTIONAL)
|
|
|
|
|
2012-05-21 20:33:33 +02:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
|
2010-08-13 18:08:06 +02:00
|
|
|
option(WITH_TESTS "Enable building of unit tests" ON)
|
2011-12-26 19:18:21 +01:00
|
|
|
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
|
2015-10-13 22:51:31 +02:00
|
|
|
option(WITH_DEV_BUILD "Use only for development. Disables/warns about deprecated methods." OFF)
|
2017-10-15 16:27:07 -06:00
|
|
|
option(WITH_ASAN "Enable address sanitizer checks (Linux / macOS only)" OFF)
|
2017-03-15 15:26:40 +01:00
|
|
|
option(WITH_COVERAGE "Use to build with coverage tests (GCC only)." OFF)
|
2017-10-15 06:54:27 -06:00
|
|
|
option(WITH_APP_BUNDLE "Enable Application Bundle for macOS" ON)
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2017-11-27 22:46:03 -05:00
|
|
|
set(WITH_XC_ALL OFF CACHE BOOLEAN "Build in all available plugins")
|
|
|
|
|
2017-03-02 22:07:42 -05:00
|
|
|
option(WITH_XC_AUTOTYPE "Include Auto-Type." ON)
|
2018-01-17 00:56:47 +01:00
|
|
|
option(WITH_XC_NETWORKING "Include networking code (e.g. for downlading website icons)." OFF)
|
|
|
|
option(WITH_XC_BROWSER "Include browser integration with keepassxc-browser." OFF)
|
|
|
|
option(WITH_XC_HTTP "Include KeePassHTTP-compatible browser integration (deprecated, implies WITH_NETWORKING)." OFF)
|
2017-02-25 17:11:02 +01:00
|
|
|
option(WITH_XC_YUBIKEY "Include YubiKey support." OFF)
|
2017-10-29 17:17:24 +02:00
|
|
|
option(WITH_XC_SSHAGENT "Include SSH agent support." OFF)
|
2018-01-17 00:56:47 +01:00
|
|
|
|
|
|
|
if(WITH_XC_HTTP)
|
|
|
|
message(WARNING "KeePassHTTP support has been deprecated and will be removed in a future version. Please use WITH_XC_BROWSER instead!\n"
|
|
|
|
"For enabling / disabling network access code, WITH_XC_HTTP has been replaced by WITH_XC_NETWORKING.")
|
|
|
|
set(WITH_XC_NETWORKING ON CACHE BOOL "Include networking code (e.g. for downlading website icons)." FORCE)
|
|
|
|
endif()
|
2016-12-04 19:57:24 +01:00
|
|
|
|
2017-11-27 22:46:03 -05:00
|
|
|
if(WITH_XC_ALL)
|
|
|
|
# Enable all options
|
|
|
|
set(WITH_XC_AUTOTYPE ON)
|
|
|
|
set(WITH_XC_NETWORKING ON)
|
|
|
|
set(WITH_XC_BROWSER ON)
|
|
|
|
set(WITH_XC_HTTP ON) # Deprecated
|
|
|
|
set(WITH_XC_YUBIKEY ON)
|
|
|
|
set(WITH_XC_SSHAGENT ON)
|
|
|
|
endif()
|
|
|
|
|
2017-05-06 11:50:05 -04:00
|
|
|
# Process ui files automatically from source files
|
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
|
|
|
|
set(KEEPASSXC_VERSION_MAJOR "2")
|
2017-11-27 22:46:03 -05:00
|
|
|
set(KEEPASSXC_VERSION_MINOR "3")
|
2018-05-09 19:22:16 +02:00
|
|
|
set(KEEPASSXC_VERSION_PATCH "3")
|
2017-05-06 11:50:05 -04:00
|
|
|
set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION_MAJOR}.${KEEPASSXC_VERSION_MINOR}.${KEEPASSXC_VERSION_PATCH}")
|
2010-08-13 18:08:06 +02:00
|
|
|
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_BUILD_TYPE "Snapshot" CACHE STRING "Set KeePassXC build type to distinguish between stable releases and snapshots")
|
|
|
|
set_property(CACHE KEEPASSXC_BUILD_TYPE PROPERTY STRINGS Snapshot Release PreRelease)
|
|
|
|
|
2018-01-29 23:00:52 -05:00
|
|
|
# Check if on a tag, if so build as a release
|
|
|
|
execute_process(COMMAND git tag --points-at HEAD
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_TAG)
|
2018-03-01 14:39:22 +01:00
|
|
|
if(GIT_TAG)
|
|
|
|
set(OVERRIDE_VERSION ${GIT_TAG})
|
|
|
|
elseif(EXISTS ${CMAKE_SOURCE_DIR}/.version)
|
2018-02-22 21:31:32 +01:00
|
|
|
file(READ ${CMAKE_SOURCE_DIR}/.version OVERRIDE_VERSION)
|
|
|
|
endif()
|
2018-02-17 17:46:19 +01:00
|
|
|
|
2018-02-22 21:31:32 +01:00
|
|
|
string(REGEX REPLACE "(\r?\n)+" "" OVERRIDE_VERSION "${OVERRIDE_VERSION}")
|
|
|
|
if(OVERRIDE_VERSION)
|
|
|
|
if(OVERRIDE_VERSION MATCHES "^[\\.0-9]+-(alpha|beta)[0-9]+$")
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_BUILD_TYPE PreRelease)
|
2018-02-22 21:31:32 +01:00
|
|
|
set(KEEPASSXC_VERSION ${OVERRIDE_VERSION})
|
|
|
|
elseif(OVERRIDE_VERSION MATCHES "^[\\.0-9]+$")
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_BUILD_TYPE Release)
|
2018-02-22 21:31:32 +01:00
|
|
|
set(KEEPASSXC_VERSION ${OVERRIDE_VERSION})
|
2018-02-17 17:46:19 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2018-02-22 21:31:32 +01:00
|
|
|
if(KEEPASSXC_BUILD_TYPE STREQUAL "PreRelease" AND NOT OVERRIDE_VERSION)
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION}-preview")
|
|
|
|
elseif(KEEPASSXC_BUILD_TYPE STREQUAL "Snapshot")
|
2017-11-27 22:46:03 -05:00
|
|
|
set(KEEPASSXC_VERSION "${KEEPASSXC_VERSION}-snapshot")
|
|
|
|
endif()
|
|
|
|
|
2018-02-17 17:46:19 +01:00
|
|
|
if(KEEPASSXC_BUILD_TYPE STREQUAL "Release")
|
|
|
|
set(KEEPASSXC_BUILD_TYPE_RELEASE ON)
|
|
|
|
elseif(KEEPASSXC_BUILD_TYPE STREQUAL "PreRelease")
|
|
|
|
set(KEEPASSXC_BUILD_TYPE_PRE_RELEASE ON)
|
|
|
|
else()
|
|
|
|
set(KEEPASSXC_BUILD_TYPE_SNAPSHOT ON)
|
|
|
|
endif()
|
|
|
|
|
2017-11-27 22:46:03 -05:00
|
|
|
message(STATUS "Setting up build for KeePassXC v${KEEPASSXC_VERSION}\n")
|
|
|
|
|
2017-10-16 17:47:19 +02:00
|
|
|
# Distribution info
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_DIST ON)
|
|
|
|
set(KEEPASSXC_DIST_TYPE "Other" CACHE STRING "KeePassXC Distribution Type")
|
2017-10-16 17:47:19 +02:00
|
|
|
set_property(CACHE KEEPASSXC_DIST_TYPE PROPERTY STRINGS Snap AppImage Other)
|
2017-10-17 12:56:42 +02:00
|
|
|
if(KEEPASSXC_DIST_TYPE STREQUAL "Snap")
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_DIST_SNAP ON)
|
2017-10-17 12:56:42 +02:00
|
|
|
elseif(KEEPASSXC_DIST_TYPE STREQUAL "AppImage")
|
2018-02-17 17:46:19 +01:00
|
|
|
set(KEEPASSXC_DIST_APPIMAGE ON)
|
2017-10-17 12:56:42 +02:00
|
|
|
elseif(KEEPASSXC_DIST_TYPE STREQUAL "Other")
|
|
|
|
unset(KEEPASSXC_DIST)
|
2017-10-16 17:47:19 +02:00
|
|
|
endif()
|
2017-10-03 12:29:39 -04:00
|
|
|
|
2018-05-09 06:47:34 -04:00
|
|
|
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "4")
|
|
|
|
set(IS_32BIT TRUE)
|
|
|
|
endif()
|
|
|
|
|
2012-04-21 19:47:39 +02:00
|
|
|
if("${CMAKE_C_COMPILER}" MATCHES "clang$" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
2012-04-18 16:10:40 +02:00
|
|
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-21 19:47:39 +02:00
|
|
|
|
|
|
|
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-18 16:10:40 +02:00
|
|
|
|
2012-04-21 19:47:39 +02:00
|
|
|
macro(add_gcc_compiler_cxxflags FLAGS)
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-21 19:47:39 +02:00
|
|
|
endmacro(add_gcc_compiler_cxxflags)
|
|
|
|
|
|
|
|
macro(add_gcc_compiler_cflags FLAGS)
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-21 19:47:39 +02:00
|
|
|
endmacro(add_gcc_compiler_cflags)
|
|
|
|
|
|
|
|
macro(add_gcc_compiler_flags FLAGS)
|
|
|
|
add_gcc_compiler_cxxflags("${FLAGS}")
|
|
|
|
add_gcc_compiler_cflags("${FLAGS}")
|
|
|
|
endmacro(add_gcc_compiler_flags)
|
2012-04-18 16:10:40 +02:00
|
|
|
|
2016-11-02 21:01:02 -04:00
|
|
|
add_definitions(-DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII)
|
2011-11-20 10:14:50 +01:00
|
|
|
|
2017-05-06 01:49:52 +08:00
|
|
|
if(WITH_APP_BUNDLE)
|
|
|
|
add_definitions(-DWITH_APP_BUNDLE)
|
|
|
|
endif()
|
|
|
|
|
2017-03-10 18:09:46 +01:00
|
|
|
add_gcc_compiler_flags("-fno-common")
|
2018-03-03 14:19:51 +01:00
|
|
|
add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long")
|
2012-05-21 20:33:33 +02:00
|
|
|
add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute")
|
2013-04-05 21:04:02 +02:00
|
|
|
add_gcc_compiler_flags("-fvisibility=hidden")
|
|
|
|
add_gcc_compiler_cxxflags("-fvisibility-inlines-hidden")
|
2012-04-18 16:10:40 +02:00
|
|
|
|
2018-03-03 14:19:51 +01:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
add_gcc_compiler_flags("-Werror")
|
|
|
|
endif()
|
|
|
|
|
2017-03-10 18:09:46 +01:00
|
|
|
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8.999) OR CMAKE_COMPILER_IS_CLANGXX)
|
|
|
|
add_gcc_compiler_flags("-fstack-protector-strong")
|
|
|
|
else()
|
|
|
|
add_gcc_compiler_flags("-fstack-protector --param=ssp-buffer-size=4")
|
|
|
|
endif()
|
|
|
|
|
2012-04-21 19:47:39 +02:00
|
|
|
add_gcc_compiler_cxxflags("-fno-exceptions -fno-rtti")
|
|
|
|
add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual")
|
2012-05-21 20:33:33 +02:00
|
|
|
add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings")
|
2017-10-15 06:54:27 -06:00
|
|
|
|
2017-03-14 14:29:09 +01:00
|
|
|
if(WITH_ASAN)
|
2017-10-15 16:27:07 -06:00
|
|
|
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE))
|
|
|
|
message(FATAL_ERROR "WITH_ASAN is only supported on Linux / macOS at the moment.")
|
2017-03-14 21:24:32 +01:00
|
|
|
endif()
|
|
|
|
|
2017-03-14 15:32:48 +01:00
|
|
|
add_gcc_compiler_flags("-fsanitize=address -DWITH_ASAN")
|
2017-03-14 14:53:29 +01:00
|
|
|
|
2017-10-15 16:27:07 -06:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
2017-10-15 06:54:27 -06:00
|
|
|
if(NOT (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9))
|
|
|
|
add_gcc_compiler_flags("-fsanitize=leak -DWITH_LSAN")
|
|
|
|
endif()
|
2017-03-14 14:53:29 +01:00
|
|
|
endif()
|
2017-10-15 06:54:27 -06:00
|
|
|
|
2017-03-14 14:29:09 +01:00
|
|
|
endif()
|
2012-05-21 20:33:33 +02:00
|
|
|
|
2013-11-24 21:40:19 +01:00
|
|
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
|
2017-03-10 13:23:46 +01:00
|
|
|
if (CMAKE_BUILD_TYPE_LOWER MATCHES "(release|relwithdebinfo|minsizerel)")
|
2018-01-03 20:18:45 +01:00
|
|
|
add_gcc_compiler_flags("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2")
|
2013-11-24 21:40:19 +01:00
|
|
|
endif()
|
|
|
|
|
2012-05-21 20:33:33 +02:00
|
|
|
check_c_compiler_flag("-Werror=format-security -Werror=implicit-function-declaration" WERROR_C_AVAILABLE)
|
|
|
|
check_cxx_compiler_flag("-Werror=format-security" WERROR_CXX_AVAILABLE)
|
|
|
|
if(WERROR_C_AVAILABLE AND WERROR_CXX_AVAILABLE)
|
|
|
|
add_gcc_compiler_flags("-Werror=format-security")
|
|
|
|
add_gcc_compiler_cflags("-Werror=implicit-function-declaration")
|
|
|
|
endif()
|
2010-11-22 14:57:19 +01:00
|
|
|
|
2013-04-30 18:24:41 +02:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align")
|
2016-11-04 00:47:04 -04:00
|
|
|
|
2016-11-04 00:52:00 -04:00
|
|
|
if(WITH_COVERAGE)
|
|
|
|
# Include code coverage, use with -DCMAKE_BUILD_TYPE=Coverage
|
|
|
|
include(CodeCoverage)
|
|
|
|
setup_target_for_coverage(kp_coverage "make test" coverage)
|
|
|
|
endif()
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-21 19:47:39 +02:00
|
|
|
|
2013-04-30 18:24:41 +02:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2010-09-23 23:36:25 +02:00
|
|
|
|
2012-04-21 19:47:39 +02:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
2017-03-10 13:23:46 +01:00
|
|
|
if (CMAKE_COMPILER_IS_CLANGXX)
|
|
|
|
add_gcc_compiler_flags("-Qunused-arguments")
|
|
|
|
endif()
|
|
|
|
add_gcc_compiler_flags("-pie -fPIE")
|
2012-04-21 19:47:39 +02:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed -Wl,--no-undefined")
|
2017-03-10 13:23:46 +01:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now")
|
2012-07-12 22:33:20 +02:00
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed")
|
2017-03-10 13:23:46 +01:00
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,relro,-z,now")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2018-01-27 08:11:59 -05:00
|
|
|
add_gcc_compiler_cflags("-std=c99")
|
2015-09-12 16:16:18 +02:00
|
|
|
add_gcc_compiler_cxxflags("-std=c++11")
|
2012-04-18 20:18:48 +02:00
|
|
|
|
2015-07-24 18:28:12 +02:00
|
|
|
if(APPLE)
|
|
|
|
add_gcc_compiler_cxxflags("-stdlib=libc++")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2012-04-18 20:18:48 +02:00
|
|
|
|
2015-10-13 22:51:31 +02:00
|
|
|
if(WITH_DEV_BUILD)
|
|
|
|
add_definitions(-DQT_DEPRECATED_WARNINGS -DGCRYPT_NO_DEPRECATED)
|
2012-06-29 14:14:58 +02:00
|
|
|
endif()
|
|
|
|
|
2012-10-23 14:52:59 +02:00
|
|
|
if(MINGW)
|
|
|
|
set(CMAKE_RC_COMPILER_INIT windres)
|
|
|
|
enable_language(RC)
|
|
|
|
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
|
2017-04-09 18:52:54 -04:00
|
|
|
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
|
|
|
|
# Enable DEP and ASLR
|
2018-05-09 06:47:34 -04:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase")
|
|
|
|
# Enable high entropy ASLR for 64-bit builds
|
|
|
|
if(NOT IS_32BIT)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--high-entropy-va")
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--high-entropy-va")
|
|
|
|
endif()
|
2017-04-09 18:52:54 -04:00
|
|
|
endif()
|
2012-10-23 14:52:59 +02:00
|
|
|
endif()
|
|
|
|
|
2017-05-06 01:49:52 +08:00
|
|
|
if(APPLE AND WITH_APP_BUNDLE OR MINGW)
|
2016-11-03 00:05:30 -04:00
|
|
|
set(PROGNAME KeePassXC)
|
2012-05-21 23:37:29 +02:00
|
|
|
else()
|
2016-11-03 00:05:30 -04:00
|
|
|
set(PROGNAME keepassxc)
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2017-05-06 01:49:52 +08:00
|
|
|
if(APPLE AND WITH_APP_BUNDLE AND "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
|
2012-05-21 20:24:06 +02:00
|
|
|
set(CMAKE_INSTALL_PREFIX "/Applications")
|
2017-10-06 00:15:23 -03:00
|
|
|
set(CMAKE_INSTALL_MANDIR "/usr/local/share/man")
|
2012-05-21 20:24:06 +02:00
|
|
|
endif()
|
|
|
|
|
2011-12-29 23:50:22 +01:00
|
|
|
if(MINGW)
|
2017-02-04 14:52:43 -05:00
|
|
|
set(CLI_INSTALL_DIR ".")
|
2017-12-12 10:15:23 +02:00
|
|
|
set(PROXY_INSTALL_DIR ".")
|
2012-07-18 20:58:49 +02:00
|
|
|
set(BIN_INSTALL_DIR ".")
|
|
|
|
set(PLUGIN_INSTALL_DIR ".")
|
|
|
|
set(DATA_INSTALL_DIR "share")
|
2017-05-06 01:49:52 +08:00
|
|
|
elseif(APPLE AND WITH_APP_BUNDLE)
|
2017-02-04 14:52:43 -05:00
|
|
|
set(CLI_INSTALL_DIR "/usr/local/bin")
|
2017-12-12 10:15:23 +02:00
|
|
|
set(PROXY_INSTALL_DIR "/usr/local/bin")
|
2012-07-18 20:58:49 +02:00
|
|
|
set(BIN_INSTALL_DIR ".")
|
2016-11-08 22:13:57 +01:00
|
|
|
set(PLUGIN_INSTALL_DIR "${PROGNAME}.app/Contents/PlugIns")
|
2012-07-18 20:58:49 +02:00
|
|
|
set(DATA_INSTALL_DIR "${PROGNAME}.app/Contents/Resources")
|
2012-05-21 23:37:29 +02:00
|
|
|
else()
|
2013-04-29 22:17:31 +02:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2017-02-04 14:52:43 -05:00
|
|
|
set(CLI_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
|
2017-12-12 10:15:23 +02:00
|
|
|
set(PROXY_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
|
2015-05-12 22:20:42 +02:00
|
|
|
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
|
2016-11-03 00:05:30 -04:00
|
|
|
set(PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/keepassxc")
|
|
|
|
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/keepassxc")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2011-12-29 23:50:22 +01:00
|
|
|
|
2012-05-21 23:37:29 +02:00
|
|
|
if(WITH_TESTS)
|
|
|
|
enable_testing()
|
|
|
|
endif(WITH_TESTS)
|
2010-08-13 18:08:06 +02:00
|
|
|
|
2017-10-15 16:27:07 -06:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
find_package(Qt5 COMPONENTS Core Network Concurrent Widgets Test LinguistTools DBus REQUIRED)
|
|
|
|
elseif(APPLE)
|
2017-10-15 17:28:26 -06:00
|
|
|
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
|
2017-10-15 16:27:07 -06:00
|
|
|
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")
|
2017-02-09 15:28:52 +01:00
|
|
|
endif()
|
2017-10-15 16:27:07 -06:00
|
|
|
|
2018-02-21 23:01:02 +01:00
|
|
|
get_filename_component(Qt5_PREFIX ${Qt5_DIR}/../../.. REALPATH)
|
|
|
|
|
2015-07-22 16:59:38 +02:00
|
|
|
set(CMAKE_AUTOMOC ON)
|
2017-10-15 16:27:07 -06:00
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_MACOSX_RPATH TRUE)
|
2018-02-26 10:21:35 +01:00
|
|
|
find_program(MACDEPLOYQT_EXE macdeployqt HINTS ${Qt5_PREFIX}/bin ENV PATH)
|
2017-10-15 16:27:07 -06:00
|
|
|
if(NOT MACDEPLOYQT_EXE)
|
2017-10-15 17:28:26 -06:00
|
|
|
message(FATAL_ERROR "macdeployqt is required to build in macOS")
|
2017-10-15 16:27:07 -06:00
|
|
|
else()
|
|
|
|
message(STATUS "Using macdeployqt: ${MACDEPLOYQT_EXE}")
|
|
|
|
endif()
|
|
|
|
endif()
|
2012-05-26 16:20:32 +02:00
|
|
|
|
2014-11-04 18:50:07 +01:00
|
|
|
# Debian sets the the build type to None for package builds.
|
|
|
|
# Make sure we don't enable asserts there.
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_NONE QT_NO_DEBUG)
|
2010-08-07 15:10:44 +02:00
|
|
|
|
2017-01-26 02:58:46 +01:00
|
|
|
find_package(LibGPGError REQUIRED)
|
2017-11-13 02:23:01 +08:00
|
|
|
find_package(Gcrypt 1.7.0 REQUIRED)
|
2018-01-01 13:21:02 -05:00
|
|
|
find_package(Argon2 REQUIRED)
|
2010-09-11 19:49:30 +02:00
|
|
|
|
2010-09-23 22:27:59 +02:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
|
2017-08-13 18:07:05 +08:00
|
|
|
set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
|
|
|
|
|
2017-10-15 06:02:34 -06:00
|
|
|
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")
|
2012-05-21 23:37:29 +02:00
|
|
|
endif()
|
2010-09-24 13:32:05 +02:00
|
|
|
|
2014-05-26 00:41:54 -07:00
|
|
|
# Optional
|
2017-02-21 01:06:32 +01:00
|
|
|
if(WITH_XC_YUBIKEY)
|
|
|
|
find_package(YubiKey REQUIRED)
|
2014-05-26 00:41:54 -07:00
|
|
|
|
|
|
|
include_directories(SYSTEM ${YUBIKEY_INCLUDE_DIRS})
|
|
|
|
endif()
|
|
|
|
|
2012-10-13 11:05:50 +02:00
|
|
|
if(UNIX)
|
|
|
|
check_cxx_source_compiles("#include <sys/prctl.h>
|
|
|
|
int main() { prctl(PR_SET_DUMPABLE, 0); return 0; }"
|
|
|
|
HAVE_PR_SET_DUMPABLE)
|
|
|
|
|
|
|
|
check_cxx_source_compiles("#include <sys/resource.h>
|
|
|
|
int main() {
|
|
|
|
struct rlimit limit;
|
|
|
|
limit.rlim_cur = 0;
|
|
|
|
limit.rlim_max = 0;
|
|
|
|
setrlimit(RLIMIT_CORE, &limit);
|
|
|
|
return 0;
|
|
|
|
}" HAVE_RLIMIT_CORE)
|
|
|
|
|
|
|
|
if(APPLE)
|
2012-10-23 17:06:50 +02:00
|
|
|
check_cxx_source_compiles("#include <sys/types.h>
|
|
|
|
#include <sys/ptrace.h>
|
2012-10-13 11:05:50 +02:00
|
|
|
int main() { ptrace(PT_DENY_ATTACH, 0, 0, 0); return 0; }"
|
|
|
|
HAVE_PT_DENY_ATTACH)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-02-16 00:44:20 +01:00
|
|
|
include_directories(SYSTEM ${GCRYPT_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
2011-11-12 14:30:16 +01:00
|
|
|
|
2015-07-22 16:59:38 +02:00
|
|
|
include(FeatureSummary)
|
2013-06-30 14:07:25 +02:00
|
|
|
|
2010-08-07 15:10:44 +02:00
|
|
|
add_subdirectory(src)
|
2011-12-29 23:50:22 +01:00
|
|
|
add_subdirectory(share)
|
2012-05-21 23:37:29 +02:00
|
|
|
if(WITH_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif(WITH_TESTS)
|
2013-06-30 14:07:25 +02:00
|
|
|
|
|
|
|
if(PRINT_SUMMARY)
|
2016-12-04 19:57:24 +01:00
|
|
|
# This will print ENABLED, REQUIRED and DISABLED
|
2013-06-30 14:07:25 +02:00
|
|
|
feature_summary(WHAT ALL)
|
2016-12-04 19:57:24 +01:00
|
|
|
else()
|
|
|
|
# This will only print ENABLED and DISABLED feature
|
2017-04-10 22:05:53 +02:00
|
|
|
feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:")
|
|
|
|
feature_summary(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:")
|
2013-06-30 14:07:25 +02:00
|
|
|
endif()
|