File: BuildType.cmake

package info (click to toggle)
innoextract 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 964 kB
  • ctags: 1,421
  • sloc: cpp: 8,061; python: 1,544; makefile: 8
file content (86 lines) | stat: -rw-r--r-- 2,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

include(CompileCheck)

option(DEBUG_EXTRA "Expensive debug options" OFF)
option(SET_WARNING_FLAGS "Adjust compiler warning flags" ON)
option(SET_OPTIMIZATION_FLAGS "Adjust compiler optimization flags" ON)

if(CMAKE_BUILD_TYPE STREQUAL "")
	set(CMAKE_BUILD_TYPE "Release")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
	add_definitions(-DDEBUG)
	set(DEBUG 1)
endif()

if(MSVC)
	
	if(SET_WARNING_FLAGS)
		add_definitions(/wd4996) # 'unsafe' stdlib functions used by Boost
	endif()
	
else(MSVC)
	
	if(SET_WARNING_FLAGS)
		
		# GCC (and compatible)
		add_cxxflag("-Wall")
		add_cxxflag("-Wextra")
		add_cxxflag("-Wformat=2")
		add_cxxflag("-Wundef")
		add_cxxflag("-Wpointer-arith")
		add_cxxflag("-Wcast-qual")
		add_cxxflag("-Woverloaded-virtual")
		add_cxxflag("-Wlogical-op")
		add_cxxflag("-Woverflow")
		add_cxxflag("-Wconversion")
		add_cxxflag("-Wsign-conversion")
		add_cxxflag("-Wmissing-declarations")
		add_cxxflag("-Wredundant-decls")
		
		# clang
		add_cxxflag("-Wliteral-conversion")
		add_cxxflag("-Wshift-overflow")
		add_cxxflag("-Wbool-conversions")
		
		# icc
		if(NOT DEBUG_EXTRA)
			add_cxxflag("-wd1418") # 'external function definition with no prior declaration'
		endif()
		
	endif(SET_WARNING_FLAGS)
	
	if(DEBUG_EXTRA)
		add_cxxflag("-ftrapv") # to add checks for (undefined) signed integer overflow
		add_cxxflag("-fbounds-checking")
		add_cxxflag("-fcatch-undefined-behavior")
		add_cxxflag("-Wstrict-aliasing=1")
	endif(DEBUG_EXTRA)
	
	if(SET_OPTIMIZATION_FLAGS)
		
		# Link as few libraries as possible
		# This is much easier than trying to decide which libraries are needed for each system
		# Specifically, the need for libboost_system depends on the Boost version
		add_ldflag("-Wl,--as-needed")
		
		if(CMAKE_BUILD_TYPE STREQUAL "Debug")
			
			# set debug symbol level to -g3
			check_compiler_flag(RESULT "-g3")
			if(NOT RESULT STREQUAL "")
				string(REGEX REPLACE "-g(|[0-9]|gdb)" "" CMAKE_CXX_FLAGS_DEBUG
							"${CMAKE_CXX_FLAGS_DEBUG}")
				set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}")
			endif()
			
			# disable optimizations
			check_compiler_flag(RESULT "-O0")
			string(REGEX REPLACE "-O[0-9]" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
			set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${RESULT}")
			
		endif()
		
	endif(SET_OPTIMIZATION_FLAGS)
	
endif(MSVC)