2010-08-07 09:10:44 -04:00
|
|
|
# Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
project(KeePassX)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-09 14:29:21 -04:00
|
|
|
cmake_minimum_required(VERSION 2.6.4)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-21 17:37:29 -04:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
2010-09-11 13:49:30 -04:00
|
|
|
|
2012-05-21 14:33:33 -04:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
option(WITH_TESTS "Enable building of unit tests" ON)
|
2011-12-26 13:18:21 -05:00
|
|
|
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
|
2012-04-18 14:18:48 -04:00
|
|
|
option(WITH_LTO "Enable Link Time Optimization (LTO)" OFF)
|
2012-04-23 10:26:15 -04:00
|
|
|
option(WITH_PIE "Build as Position-independent executable (PIE)" OFF)
|
2012-06-29 08:14:58 -04:00
|
|
|
option(WITH_CXX11 "Build with the C++ 11 standard" OFF)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-07-02 16:23:20 -04:00
|
|
|
set(KEEPASSX_VERSION "2.0 alpha 2")
|
|
|
|
set(KEEPASSX_VERSION_NUM "1.9.81")
|
2010-08-13 12:08:06 -04:00
|
|
|
|
2012-04-21 13:47:39 -04:00
|
|
|
if("${CMAKE_C_COMPILER}" MATCHES "clang$" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
2012-04-18 10:10:40 -04:00
|
|
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2012-04-21 13:47:39 -04:00
|
|
|
|
|
|
|
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
set(CMAKE_COMPILER_IS_CLANGXX 1)
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2012-04-18 10:10:40 -04:00
|
|
|
|
2012-04-21 13:47:39 -04: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 17:37:29 -04:00
|
|
|
endif()
|
2012-04-21 13:47:39 -04: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 17:37:29 -04:00
|
|
|
endif()
|
2012-04-21 13:47:39 -04: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 10:10:40 -04:00
|
|
|
|
2012-04-21 18:55:52 -04:00
|
|
|
add_definitions(-DQT_NO_KEYWORDS -DQT_NO_EXCEPTIONS -DQT_NO_STL -DQT_STRICT_ITERATORS -DQT_NO_CAST_TO_ASCII)
|
2011-11-20 04:14:50 -05:00
|
|
|
|
2012-07-02 13:52:06 -04:00
|
|
|
add_gcc_compiler_flags("-fno-common -fstack-protector -D_FORTIFY_SOURCE=2")
|
2012-04-21 13:47:39 -04:00
|
|
|
add_gcc_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long")
|
2012-05-21 14:33:33 -04:00
|
|
|
add_gcc_compiler_flags("-Wformat=2 -Wmissing-format-attribute")
|
2012-04-18 10:10:40 -04:00
|
|
|
|
2012-04-21 13:47:39 -04:00
|
|
|
add_gcc_compiler_cxxflags("-fno-exceptions -fno-rtti")
|
|
|
|
add_gcc_compiler_cxxflags("-Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual")
|
2012-05-21 14:33:33 -04:00
|
|
|
add_gcc_compiler_cflags("-Wchar-subscripts -Wwrite-strings")
|
|
|
|
|
|
|
|
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 08:57:19 -05:00
|
|
|
|
2012-04-21 13:47:39 -04:00
|
|
|
if(CMAKE_COMPILER_IS_CLANGXX)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -stack-protector-buffer-size=4")
|
|
|
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align --param=ssp-buffer-size=4")
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2012-04-21 13:47:39 -04:00
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_CLANG)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mllvm -stack-protector-buffer-size=4")
|
|
|
|
elseif(CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align --param=ssp-buffer-size=4")
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2010-09-23 17:36:25 -04:00
|
|
|
|
2012-04-21 13:47:39 -04:00
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed -Wl,--no-undefined")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro")
|
2012-07-12 16:33:20 -04:00
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-add-needed -Wl,--as-needed")
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,relro")
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-18 14:18:48 -04:00
|
|
|
if(WITH_LTO)
|
2012-07-02 13:22:26 -04:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
|
2012-04-18 14:18:48 -04:00
|
|
|
check_cxx_compiler_flag("-flto -fuse-linker-plugin" LTO_AVAILABLE)
|
|
|
|
|
|
|
|
if(LTO_AVAILABLE)
|
2012-04-21 13:47:39 -04:00
|
|
|
add_gcc_compiler_flags("-flto -fuse-linker-plugin")
|
2012-04-18 14:18:48 -04:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "This version of gcc doesn't support LTO")
|
|
|
|
endif(LTO_AVAILABLE)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "LTO is only supported with gcc")
|
2012-07-02 13:22:26 -04:00
|
|
|
endif()
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2012-04-18 14:18:48 -04:00
|
|
|
|
2012-04-23 10:26:15 -04:00
|
|
|
if(WITH_PIE)
|
|
|
|
if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX))
|
|
|
|
add_gcc_compiler_flags("-fPIE")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "PIE is only supported with gcc and clang")
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
|
|
|
endif()
|
2012-04-23 10:26:15 -04:00
|
|
|
|
2012-06-29 08:14:58 -04:00
|
|
|
if (WITH_CXX11)
|
|
|
|
add_gcc_compiler_cxxflags("-std=c++0x")
|
2012-07-02 13:52:06 -04:00
|
|
|
add_gcc_compiler_cflags("-ansi")
|
|
|
|
else()
|
|
|
|
add_gcc_compiler_flags("-ansi")
|
2012-06-29 08:14:58 -04:00
|
|
|
endif()
|
|
|
|
|
2012-05-21 17:37:29 -04:00
|
|
|
if(APPLE OR MINGW)
|
|
|
|
set(PROGNAME KeePassX)
|
|
|
|
else()
|
|
|
|
set(PROGNAME keepassx)
|
|
|
|
endif()
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-05-21 14:24:06 -04:00
|
|
|
if(APPLE AND "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
|
|
|
|
set(CMAKE_INSTALL_PREFIX "/Applications")
|
|
|
|
endif()
|
|
|
|
|
2011-12-29 17:50:22 -05:00
|
|
|
if(MINGW)
|
2012-07-18 14:58:49 -04:00
|
|
|
set(BIN_INSTALL_DIR ".")
|
|
|
|
set(PLUGIN_INSTALL_DIR ".")
|
|
|
|
set(DATA_INSTALL_DIR "share")
|
2011-12-29 17:50:22 -05:00
|
|
|
elseif(APPLE)
|
2012-07-18 14:58:49 -04:00
|
|
|
set(BIN_INSTALL_DIR ".")
|
|
|
|
set(PLUGIN_INSTALL_DIR ".")
|
|
|
|
set(DATA_INSTALL_DIR "${PROGNAME}.app/Contents/Resources")
|
2012-05-21 17:37:29 -04:00
|
|
|
else()
|
2012-07-18 14:58:49 -04:00
|
|
|
set(BIN_INSTALL_DIR "bin")
|
|
|
|
set(PLUGIN_INSTALL_DIR "lib/keepassx")
|
|
|
|
set(DATA_INSTALL_DIR "share/keepassx")
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2011-12-29 17:50:22 -05:00
|
|
|
|
2012-05-21 17:37:29 -04:00
|
|
|
if(WITH_TESTS)
|
|
|
|
enable_testing()
|
|
|
|
endif(WITH_TESTS)
|
2010-08-13 12:08:06 -04:00
|
|
|
|
2012-05-26 10:20:32 -04:00
|
|
|
set(QT_REQUIRED_MODULES QtCore QtGui QtTest)
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
set(QT_REQUIRED_MODULES ${QT_REQUIRED_MODULES} QtDBus)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(Qt4 4.6.0 REQUIRED ${QT_REQUIRED_MODULES})
|
2011-11-20 04:12:49 -05:00
|
|
|
add_definitions(${QT_DEFINITIONS} -DQT_CORE_LIB -DQT_GUI_LIB)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG)
|
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG)
|
2012-05-21 17:37:29 -04:00
|
|
|
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
2012-04-25 10:50:39 -04:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS QT_NO_DEBUG)
|
2012-05-21 17:37:29 -04:00
|
|
|
endif()
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2011-11-12 06:00:49 -05:00
|
|
|
find_package(Gcrypt REQUIRED)
|
2010-09-11 13:49:30 -04:00
|
|
|
|
2010-09-23 16:27:59 -04:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
|
2010-09-24 07:32:05 -04:00
|
|
|
check_cxx_source_compiles("
|
2012-05-21 17:37:29 -04:00
|
|
|
#include <zlib.h>
|
2010-09-24 07:32:05 -04:00
|
|
|
|
2012-05-21 17:37:29 -04:00
|
|
|
#if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1200)
|
|
|
|
#error zlib 1.2.x or higher is required to use the gzip format
|
|
|
|
#endif
|
2010-09-24 07:32:05 -04:00
|
|
|
|
2012-05-21 17:37:29 -04:00
|
|
|
int main() { return 0; }" ZLIB_SUPPORTS_GZIP)
|
2010-09-24 07:32:05 -04:00
|
|
|
|
|
|
|
if(NOT ZLIB_SUPPORTS_GZIP)
|
2012-05-21 17:37:29 -04:00
|
|
|
message(FATAL_ERROR "zlib 1.2.x or higher is required to use the gzip format")
|
|
|
|
endif()
|
2010-09-24 07:32:05 -04:00
|
|
|
|
2012-04-26 06:18:38 -04:00
|
|
|
include_directories(SYSTEM ${QT_INCLUDE_DIR} ${GCRYPT_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
|
2011-11-12 08:30:16 -05:00
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
add_subdirectory(src)
|
2011-12-29 17:50:22 -05:00
|
|
|
add_subdirectory(share)
|
2011-07-06 14:23:29 -04:00
|
|
|
add_subdirectory(utils)
|
2012-05-21 17:37:29 -04:00
|
|
|
if(WITH_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif(WITH_TESTS)
|