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-04-18 07:50:15 -04:00
|
|
|
cmake_minimum_required(VERSION 2.8.0)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-09-11 13:49:30 -04:00
|
|
|
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
|
|
|
|
|
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)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
set( KEEPASSX_VERSION "0.9.0" )
|
|
|
|
|
2012-04-18 10:10:40 -04:00
|
|
|
if("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
set(CMAKE_COMPILER_IS_CLANG 1)
|
|
|
|
endif("${CMAKE_CXX_COMPILER}" MATCHES "clang(\\+\\+)?$" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
|
|
|
|
macro(add_compiler_flags FLAGS)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS}")
|
|
|
|
endmacro(add_compiler_flags)
|
|
|
|
|
2011-11-20 04:14:50 -05:00
|
|
|
add_definitions(-DQT_NO_KEYWORDS -DQT_NO_EXCEPTIONS -DQT_NO_STL -DQT_STRICT_ITERATORS)
|
|
|
|
|
2012-04-18 10:10:40 -04:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
|
|
|
|
add_compiler_flags("-ansi -fno-common -fstack-protector -D_FORTIFY_SOURCE=2")
|
|
|
|
add_compiler_flags("-Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long")
|
|
|
|
add_compiler_flags("-Wformat=2 -Werror=format-security -Wmissing-format-attribute")
|
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wchar-subscripts -Wwrite-strings -Werror=implicit-function-declaration")
|
2010-11-22 08:57:19 -05:00
|
|
|
|
2012-04-18 10:10:40 -04:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
add_compiler_flags("-Wcast-align --param=ssp-buffer-size=4")
|
|
|
|
else()
|
|
|
|
add_compiler_flags("-mllvm -stack-protector-buffer-size=4")
|
|
|
|
endif(CMAKE_COMPILER_IS_GNUCXX)
|
2010-09-23 17:36:25 -04:00
|
|
|
|
2011-11-11 19:48:49 -05:00
|
|
|
if( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
|
2012-04-14 12:45:16 -04:00
|
|
|
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")
|
2011-11-11 19:48:49 -05:00
|
|
|
endif( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
|
2012-04-18 10:10:40 -04:00
|
|
|
endif(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
|
2010-08-07 09:10:44 -04:00
|
|
|
|
2012-04-18 14:18:48 -04:00
|
|
|
if(WITH_LTO)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
check_cxx_compiler_flag("-flto -fuse-linker-plugin" LTO_AVAILABLE)
|
|
|
|
|
|
|
|
if(LTO_AVAILABLE)
|
|
|
|
add_compiler_flags("-flto -fuse-linker-plugin")
|
|
|
|
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")
|
|
|
|
endif(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
endif(WITH_LTO)
|
|
|
|
|
2010-08-07 09:10:44 -04:00
|
|
|
if( APPLE OR MINGW )
|
|
|
|
set( PROGNAME KeePassX )
|
|
|
|
else( APPLE OR MINGW )
|
|
|
|
set( PROGNAME keepassx )
|
|
|
|
endif( APPLE OR MINGW )
|
|
|
|
|
2011-12-29 17:50:22 -05:00
|
|
|
if(MINGW)
|
|
|
|
set(BIN_INSTALL_DIR "")
|
|
|
|
set(DATA_INSTALL_DIR "share")
|
|
|
|
elseif(APPLE)
|
|
|
|
set(BIN_INSTALL_DIR "")
|
|
|
|
set(DATA_INSTALL_DIR "Contents/Resources")
|
|
|
|
else(MINGW)
|
|
|
|
set(BIN_INSTALL_DIR "bin")
|
|
|
|
set(DATA_INSTALL_DIR "share/keepassx")
|
|
|
|
endif( MINGW )
|
|
|
|
|
2010-08-13 12:08:06 -04:00
|
|
|
if( WITH_TESTS )
|
|
|
|
enable_testing()
|
|
|
|
endif( WITH_TESTS )
|
|
|
|
|
2011-11-20 04:12:49 -05:00
|
|
|
find_package(Qt4 4.6.0 REQUIRED QtCore QtGui QtTest)
|
|
|
|
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)
|
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
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
check_cxx_source_compiles("
|
|
|
|
#include <zlib.h>
|
|
|
|
|
|
|
|
#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")
|
|
|
|
endif(NOT ZLIB_SUPPORTS_GZIP)
|
|
|
|
|
2011-11-20 04:12:49 -05:00
|
|
|
include_directories(${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)
|
2010-08-13 12:08:06 -04:00
|
|
|
if( WITH_TESTS )
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif( WITH_TESTS )
|