comparison CMakeLists.txt @ 1264:3cd8dd706aaa

Add possibility to build with CLANG and document it. This only works for now with the c parts of the code.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 26 Sep 2014 17:59:49 +0200
parents 60927efa48cc
children a548dd9a5dbe
comparison
equal deleted inserted replaced
1263:827abc0923a8 1264:3cd8dd706aaa
9 project(trustbridge) 9 project(trustbridge)
10 10
11 option(DO_RELEASE_BUILD "Build for a public release." OFF) 11 option(DO_RELEASE_BUILD "Build for a public release." OFF)
12 option(ENABLE_PROFILING "Set to enable profiling." OFF) 12 option(ENABLE_PROFILING "Set to enable profiling." OFF)
13 option(USE_CURL "Use libcurl to download updates and certificate lists." ON) 13 option(USE_CURL "Use libcurl to download updates and certificate lists." ON)
14 option(USE_CLANG "Use clang to compile trustbridge." OFF)
14 15
15 set(DOWNLOAD_SERVER "https://tb-devel.intevation.de:443" CACHE STRING "Used as download server" ) 16 set(DOWNLOAD_SERVER "https://tb-devel.intevation.de:443" CACHE STRING "Used as download server" )
16 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") 17 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
17 18
18 #Old qtmain linking behavior to be compatible with cmake versions < 2.8.11 19 #Old qtmain linking behavior to be compatible with cmake versions < 2.8.11
19 20
20 if(POLICY CMP0020) 21 if(POLICY CMP0020)
21 cmake_policy(SET CMP0020 OLD) 22 cmake_policy(SET CMP0020 OLD)
23 endif()
24
25 if (USE_CLANG)
26 message (STATUS "Using clang options to build trustbridge.")
22 endif() 27 endif()
23 28
24 include(CTest) 29 include(CTest)
25 include(GenerateCppcheck) 30 include(GenerateCppcheck)
26 include(HGVersion) 31 include(HGVersion)
80 85
81 if(USE_REAL_RESOURCES) 86 if(USE_REAL_RESOURCES)
82 add_definitions (-DUSE_REAL_RESOURCES) 87 add_definitions (-DUSE_REAL_RESOURCES)
83 endif() 88 endif()
84 89
90 if (NOT USE_CLANG)
85 # Warn level to be used for privileged parts 91 # Warn level to be used for privileged parts
86 set(WARN_HARDENING_FLAGS " -Wextra -Wconversion -Wformat-security") 92 set(WARN_HARDENING_FLAGS " -Wextra -Wconversion -Wformat-security")
87 93
88 # Hardening flags 94 # Hardening flags
89 set(HARDENING_FLAGS " -Wall -fstack-protector-all -fno-exceptions") 95 set(HARDENING_FLAGS " -Wall -fstack-protector-all -fno-exceptions")
90 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wstack-protector") 96 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wstack-protector")
91 set(HARDENING_FLAGS " ${HARDENING_FLAGS} --param ssp-buffer-size=4") 97 set(HARDENING_FLAGS " ${HARDENING_FLAGS} --param ssp-buffer-size=4")
92 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -D_FORTIFY_SOURCE=2 -O0") 98 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -D_FORTIFY_SOURCE=2 -O0")
99 endif()
93 100
94 if(ENABLE_PROFILING) 101 if(ENABLE_PROFILING)
95 set(PROFILING_FLAGS "-fprofile-arcs -ftest-coverage") 102 set(PROFILING_FLAGS "-fprofile-arcs -ftest-coverage")
96 set(PROFILING_LIBS gcov) 103 set(PROFILING_LIBS gcov)
97 endif() 104 endif()
100 add_definitions(-D_WIN32_WINNT=0x0600) # Windows vista 107 add_definitions(-D_WIN32_WINNT=0x0600) # Windows vista
101 add_definitions(-DWINVER=0x0600) 108 add_definitions(-DWINVER=0x0600)
102 add_definitions(-DMINGW_HAS_SECURE_API) # for _s functions 109 add_definitions(-DMINGW_HAS_SECURE_API) # for _s functions
103 endif(WIN32) 110 endif(WIN32)
104 111
105 if(UNIX) 112 if(UNIX AND NOT USE_CLANG)
106 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -pie -fPIE -ftrapv") 113 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -pie -fPIE -ftrapv")
107 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,-z,relro,-z,now") 114 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,-z,relro,-z,now")
108 elseif(WIN32) 115 elseif(WIN32 AND NOT USE_CLANG)
109 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat") 116 set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat")
110 endif() 117 endif()
111 118
112 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}") 119 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}")
113 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_HARDENING_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}") 120 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_HARDENING_FLAGS} ${HARDENING_FLAGS} ${PROFILING_FLAGS}")

http://wald.intevation.org/projects/trustbridge/