File: SetDefaultGccFlags.cmake

package info (click to toggle)
scantailor 0.9.12.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,564 kB
  • ctags: 9,057
  • sloc: cpp: 71,264; ansic: 481; sh: 121; makefile: 10
file content (135 lines) | stat: -rw-r--r-- 4,272 bytes parent folder | download | duplicates (2)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
INCLUDE(TestCXXAcceptsFlag)

MACRO(ST_SET_DEFAULT_GCC_FLAGS)
	IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX
	   AND CMAKE_C_FLAGS MATCHES "\\s*" AND CMAKE_CXX_FLAGS MATCHES "\\s*")
		SET(dead_strip_ldflags_ "")
		SET(gc_sections_cflags_ "")
		SET(gc_sections_ldflags_ "")
		SET(no_inline_dllexport_cflags_ "")
		
		CHECK_CXX_ACCEPTS_FLAG(
			"-ffunction-sections -fdata-sections -Wl,--gc-sections"
			gc_sections_supported_
		)
		IF(gc_sections_supported_)
			SET(gc_sections_cflags_ "-ffunction-sections -fdata-sections")
			SET(gc_sections_ldflags_ "-Wl,--gc-sections")
		ENDIF(gc_sections_supported_)

		CHECK_CXX_ACCEPTS_FLAG("-fno-keep-inline-dllexport" no_inline_dllexport_supported_)
		IF(no_inline_dllexport_supported_)
			SET(no_inline_dllexport_cflags_ "-fno-keep-inline-dllexport")
		ENDIF()
		
		IF(MINGW)
			CHECK_CXX_ACCEPTS_FLAG("-shared-libgcc -static-libstdc++" supported_)
			IF(supported_)
				# This is the configuration we want for 32-bit MinGW.
				# Note that the default for libstdc++ recently changed
				# from static to shared. We don't want to bundle
				# another DLL, so we force it back.
				# For 64-bit MinGW, such configuration is invalid and
				# fortunately gets rejected.
				SET(stdlibs_shared_static_ "-shared-libgcc -static-libstdc++")
			ELSE()
				# This configuration is used for 64-bit MinGW.
				SET(stdlibs_shared_static_ "")
			ENDIF()
		ENDIF()	
		
		# GCC on Windows doesn't support -fvisibility, but doesn't reject it either,
		# printing warnings instead.
		IF(NOT WIN32)
			CHECK_CXX_ACCEPTS_FLAG("-fvisibility=hidden" visibility_supported_)
			IF(visibility_supported_)
				SET(visibility_cflags_ "-fvisibility=hidden")
			ELSE(visibility_supported_)
				SET(visibility_cflags_ "")
			ENDIF(visibility_supported_)
		ENDIF()
		
		IF(NOT COMPILER_FLAGS_OVERRIDDEN)
			SET(default_flags_ "-Wall -Wno-unused -ffast-math ${no_inline_dllexport_cflags_}")
			# Flags common for all build configurations.
			SET(
				CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${default_flags_}"
				CACHE STRING "Common C flags for all build configurations."
			)
			SET(
				CMAKE_CXX_FLAGS
				"${CMAKE_CXX_FLAGS} ${default_flags_} ${stdlibs_shared_static_}"
				CACHE STRING "Common C++ flags for all build configurations."
			)
		
			# Release
			SET(
				CMAKE_C_FLAGS_RELEASE
				"-DNDEBUG -O2 ${visibility_cflags_} ${gc_sections_cflags_}"
				CACHE STRING "C flags for Release builds."
			)
			SET(
				CMAKE_CXX_FLAGS_RELEASE
				"-DNDEBUG -O2 ${visibility_cflags_} ${gc_sections_cflags_}"
				CACHE STRING "C++ flags for Release builds."
			)
			SET(
				CMAKE_EXE_LINKER_FLAGS_RELEASE
				"${gc_sections_ldflags_} ${dead_strip_ldflags_}"
				CACHE STRING "Link flags for Release builds."
			)
			
			# MinSizeRel
			SET(
				CMAKE_C_FLAGS_MINSIZEREL
				"-DNDEBUG -Os ${visibility_cflags_} ${gc_sections_cflags_}"
				CACHE STRING "C flags for MinSizeRel builds."
			)
			SET(
				CMAKE_CXX_FLAGS_MINSIZEREL
				"-DNDEBUG -Os ${visibility_cflags_} ${gc_sections_cflags_}"
				CACHE STRING "C++ flags for MinSizeRel builds."
			)
			SET(
				CMAKE_EXE_LINKER_FLAGS_MINSIZEREL
				"${gc_sections_ldflags_} ${dead_strip_ldflags_}"
				CACHE STRING "Link flags for MinSizeRel builds."
			)
			
			# RelWithDebInfo
			SET(
				CMAKE_C_FLAGS_RELWITHDEBINFO
				"-DNDEBUG -g -O2 ${visibility_cflags_}"
				CACHE STRING "C flags for RelWithDebInfo builds."
			)
			SET(
				CMAKE_CXX_FLAGS_RELWITHDEBINFO
				"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG -g -O2 ${visibility_cflags_}"
				CACHE STRING "C++ flags for RelWithDebInfo builds."
			)
			SET(
				CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ""
				CACHE STRING "Link flags for RelWithDebInfo builds."
			)
			
			# Debug
			SET(
				CMAKE_C_FLAGS_DEBUG "-DDEBUG -g" CACHE STRING
				"C flags for Debug builds."
			)
			SET(
				CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g" CACHE STRING
				"C++ flags for Debug builds."
			)
			SET(
				CMAKE_EXE_LINKER_FLAGS_DEBUG ""
				CACHE STRING "Link flags for Debug builds."
			)
			
			SET(COMPILER_FLAGS_OVERRIDDEN YES CACHE INTERNAL "")
		
		ENDIF(NOT COMPILER_FLAGS_OVERRIDDEN)
		
	ENDIF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX
	      AND CMAKE_C_FLAGS MATCHES "\\s*" AND CMAKE_CXX_FLAGS MATCHES "\\s*")
ENDMACRO(ST_SET_DEFAULT_GCC_FLAGS)