aheinecke@405: # Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@405: # Software engineering by Intevation GmbH aheinecke@405: # aheinecke@405: # This file is Free Software under the GNU GPL (v>=2) aheinecke@405: # and comes with ABSOLUTELY NO WARRANTY! aheinecke@405: # See LICENSE.txt for details. aheinecke@405: aheinecke@0: cmake_minimum_required(VERSION 2.8.8) aheinecke@409: project(trustbridge) aheinecke@0: andre@34: option(DO_RELEASE_BUILD "Build for a public release." OFF) aheinecke@37: option(ENABLE_PROFILING "Set to enable profiling." OFF) andre@952: option(USE_CURL "Use libcurl to download updates and certificate lists." ON) andre@1264: option(USE_CLANG "Use clang to compile trustbridge." OFF) andre@34: andre@1088: set(DOWNLOAD_SERVER "https://tb-devel.intevation.de:443" CACHE STRING "Used as download server" ) andre@26: set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") andre@26: aheinecke@74: #Old qtmain linking behavior to be compatible with cmake versions < 2.8.11 aheinecke@106: aheinecke@106: if(POLICY CMP0020) aheinecke@106: cmake_policy(SET CMP0020 OLD) aheinecke@106: endif() aheinecke@74: andre@1264: if (USE_CLANG) andre@1264: message (STATUS "Using clang options to build trustbridge.") andre@1264: endif() andre@1264: aheinecke@24: include(CTest) andre@26: include(GenerateCppcheck) aheinecke@495: include(HGVersion) aheinecke@495: aheinecke@495: if(HG_REVISION) andre@1129: If(HG_REVISION_DIST STREQUAL "0") andre@1129: add_definitions(-DIS_TAG_BUILD) andre@1129: endif() aheinecke@495: set(PROJECT_VERSION ${HG_REVISION}) aheinecke@495: else() aheinecke@495: set(PROJECT_VERSION unknown) aheinecke@495: endif() aheinecke@495: aheinecke@495: add_definitions(-DVERSION="${PROJECT_VERSION}") aheinecke@0: andre@34: find_package(PolarSSL) aheinecke@104: include_directories(${POLARSSL_INCLUDE_DIR}) aheinecke@104: aheinecke@104: find_package(Qt5Widgets) andre@34: andre@1071: find_program(OSSLSIGNCODE_EXECUTABLE osslsigncode) andre@1071: andre@1071: if (WIN32 AND NOT OSSLSIGNCODE_EXECUTABLE) andre@1071: message (STATUS "WARNING: osslsigncode not found. Code verification and code verification tests will fail.") andre@1071: endif() andre@1071: andre@834: if (NOT WIN32) andre@834: find_package(NSS) andre@834: else () andre@834: # Use static NSS for Windows andre@834: if (NOT EXISTS "${CMAKE_SOURCE_DIR}/nss-cmake-static") andre@834: MESSAGE(FATAL_ERROR "Could not find nss-cmake-static checkout. Please run: \n hg clone https://wald.intevation.org/hg/trustbridge/nss-cmake-static '${CMAKE_SOURCE_DIR}/nss-cmake-static'") andre@834: endif() andre@834: set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/nss-cmake-static/") andre@834: set(NSS_STATIC_PATH "${CMAKE_SOURCE_DIR}/nss-cmake-static") andre@834: include (nss-cmake-static) andre@834: endif() andre@307: aheinecke@0: # Use cmake's automoc and make sure the generated files are included aheinecke@0: set(CMAKE_AUTOMOC ON) aheinecke@0: set(CMAKE_INCLUDE_CURRENT_DIR ON) aheinecke@0: andre@34: if(DO_RELEASE_BUILD) andre@34: if (NOT CMAKE_BUILD_TYPE) andre@34: set (CMAKE_BUILD_TYPE RELEASE) andre@34: endif (NOT CMAKE_BUILD_TYPE) wilde@171: add_definitions (-DRELEASE_BUILD) andre@1093: set(USE_REAL_RESOURCES ON) andre@34: else() aheinecke@7: # Default to debug build andre@34: if (NOT CMAKE_BUILD_TYPE) andre@34: set (CMAKE_BUILD_TYPE Debug) aheinecke@58: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") aheinecke@58: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") andre@34: endif (NOT CMAKE_BUILD_TYPE) andre@34: endif() aheinecke@7: andre@1093: if(USE_REAL_RESOURCES) andre@1093: add_definitions (-DUSE_REAL_RESOURCES) andre@1093: endif() andre@1093: andre@1264: if (NOT USE_CLANG) aheinecke@1: # Warn level to be used for privileged parts andre@1264: set(WARN_HARDENING_FLAGS " -Wextra -Wconversion -Wformat-security") aheinecke@1: aheinecke@1: # Hardening flags andre@1264: set(HARDENING_FLAGS " -Wall -fstack-protector-all -fno-exceptions") andre@1264: set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wstack-protector") andre@1264: set(HARDENING_FLAGS " ${HARDENING_FLAGS} --param ssp-buffer-size=4") andre@1264: set(HARDENING_FLAGS " ${HARDENING_FLAGS} -D_FORTIFY_SOURCE=2 -O0") andre@1264: endif() aheinecke@24: aheinecke@37: if(ENABLE_PROFILING) aheinecke@37: set(PROFILING_FLAGS "-fprofile-arcs -ftest-coverage") aheinecke@37: set(PROFILING_LIBS gcov) aheinecke@37: endif() andre@26: aheinecke@363: if(WIN32) aheinecke@363: add_definitions(-D_WIN32_WINNT=0x0600) # Windows vista aheinecke@363: add_definitions(-DWINVER=0x0600) aheinecke@363: add_definitions(-DMINGW_HAS_SECURE_API) # for _s functions aheinecke@363: endif(WIN32) aheinecke@363: andre@1264: if(UNIX AND NOT USE_CLANG) aheinecke@4: set(HARDENING_FLAGS " ${HARDENING_FLAGS} -pie -fPIE -ftrapv") aheinecke@4: set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,-z,relro,-z,now") andre@1264: elseif(WIN32 AND NOT USE_CLANG) aheinecke@4: set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat") aheinecke@0: endif() aheinecke@0: aheinecke@75: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}") aheinecke@75: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_HARDENING_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}") aheinecke@1: aheinecke@37: add_custom_target(static_check) aheinecke@37: aheinecke@1: # FlawFinder aheinecke@1: find_program(FLAWFINDER_PATH flawfinder DOC "flawfinder path") aheinecke@1: if (FLAWFINDER_PATH) aheinecke@1: add_custom_target(flawfinder COMMENT "FlawFinder" VERBATIM COMMAND ${FLAWFINDER_PATH} aheinecke@1: ${CMAKE_SOURCE_DIR}/ui aheinecke@18: ${CMAKE_SOURCE_DIR}/cinst aheinecke@25: ${CMAKE_SOURCE_DIR}/common aheinecke@1: ) aheinecke@1: add_dependencies(static_check flawfinder) aheinecke@1: endif (FLAWFINDER_PATH) aheinecke@1: andre@834: if(WIN32) andre@834: add_subdirectory(nss-cmake-static) andre@834: add_definitions(-D_WIN32_WINNT=0x0600) # Windows vista. NSS defines its own winver. andre@834: endif() andre@834: andre@834: # No chance to compile nss with -Werror andre@834: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") andre@834: set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") andre@834: andre@1220: # Cmake does not correctly identify gcc windres when cross compiling andre@1220: # making this line neccessary to set the correct flags for it. andre@1220: # See: http://public.kitware.com/Bug/view.php?id=11773 andre@1220: SET(CMAKE_RC_COMPILE_OBJECT andre@1220: " -Ocoff ") andre@1220: andre@618: add_subdirectory(common) andre@618: aheinecke@25: add_subdirectory(cinst) aheinecke@104: if(Qt5Widgets_FOUND) aheinecke@104: add_subdirectory(ui) aheinecke@104: else() aheinecke@104: message(STATUS "WARNING: Could not find qt. GUI parts will not be built.") aheinecke@104: endif() aheinecke@104: aheinecke@24: # Documentation andre@1185: configure_file (doc/apidoc/Doxyfile.in doc/apidoc/Doxyfile) andre@1185: add_subdirectory(doc/apidoc) aheinecke@495: andre@933: find_package(Sphinx) andre@933: andre@933: if (NOT SPHINX_FOUND) andre@933: message (STATUS "WARNING could not find sphinx (Package python-sphinx). Manuals will not be built.") andre@933: else() andre@1185: add_subdirectory(doc/help) andre@933: endif() andre@933: andre@1010: add_subdirectory(packaging) aheinecke@557: aheinecke@557: if (ENABLE_PROFILING) aheinecke@557: configure_file (make-coverage.sh.in make-coverage.sh) aheinecke@557: add_custom_target(lcov COMMENT "Lcov coverage report" VERBATIM COMMAND /bin/bash aheinecke@557: ${CMAKE_CURRENT_BINARY_DIR}/make-coverage.sh aheinecke@557: ) aheinecke@557: endif()