@@ -75,14 +75,36 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/")
75
75
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR} /lib/" )
76
76
77
77
# Compile/link flags
78
+ # Helper macros
79
+ macro (jerry_add_flags VAR )
80
+ foreach (_flag ${ARGN} )
81
+ set (${VAR} "${${VAR} } ${_flag} " )
82
+ endforeach ()
83
+ endmacro ()
84
+
85
+ macro (jerry_add_compile_flags )
86
+ jerry_add_flags (CMAKE_C_FLAGS ${ARGV} )
87
+ endmacro ()
88
+
89
+ macro (jerry_add_compile_warnings )
90
+ foreach (_warning ${ARGV} )
91
+ jerry_add_compile_flags (-W${_warning} )
92
+ if (CMAKE_COMPILER_IS_GNUCC )
93
+ jerry_add_compile_flags (-Werror=${_warning} )
94
+ endif ()
95
+ endforeach ()
96
+ endmacro ()
97
+
98
+ macro (jerry_add_link_flags )
99
+ jerry_add_flags (LINKER_FLAGS_COMMON ${ARGV} )
100
+ endmacro ()
101
+
78
102
# build mode specific compile/link flags
79
103
set (CMAKE_C_FLAGS_RELEASE "-Os" )
80
104
81
105
# Architecture-specific compile/link flags
82
- foreach (FLAG ${FLAGS_COMMON_ARCH} )
83
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG} " )
84
- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG} " )
85
- endforeach ()
106
+ jerry_add_compile_flags (${FLAGS_COMMON_ARCH} )
107
+ jerry_add_flags (CMAKE_EXE_LINKER_FLAGS ${FLAGS_COMMON_ARCH} )
86
108
87
109
# Use jerry libc
88
110
if (JERRY_LIBC AND COMPILER_DEFAULT_LIBC )
@@ -91,11 +113,11 @@ endif()
91
113
92
114
# LTO
93
115
if (ENABLE_LTO )
94
- set ( CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -flto" )
95
- set ( LINKER_FLAGS_COMMON " ${LINKER_FLAGS_COMMON} -flto" )
116
+ jerry_add_compile_flags ( -flto )
117
+ jerry_add_link_flags ( -flto )
96
118
if (CMAKE_COMPILER_IS_GNUCC )
97
119
if (NOT "${PLATFORM} " STREQUAL "DARWIN" )
98
- set ( CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fno-fat-lto-objects" )
120
+ jerry_add_compile_flags ( -fno-fat-lto-objects )
99
121
endif ()
100
122
# Use gcc-ar and gcc-ranlib to support LTO
101
123
set (CMAKE_AR "gcc-ar" )
@@ -134,69 +156,50 @@ else()
134
156
endif ()
135
157
136
158
# Compiler / Linker flags
137
- set ( CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fno-builtin" )
159
+ jerry_add_compile_flags ( -fno-builtin )
138
160
if (("${PLATFORM} " STREQUAL "DARWIN" ))
139
- set ( LINKER_FLAGS_COMMON " -lSystem" )
161
+ jerry_add_link_flags ( -lSystem )
140
162
else ()
141
- set ( LINKER_FLAGS_COMMON " -Wl,-z,noexecstack" )
163
+ jerry_add_link_flags ( -Wl,-z,noexecstack )
142
164
endif ()
143
165
144
166
# Turn off linking to compiler's default libc, in case jerry-libc or external is used
145
167
if (NOT COMPILER_DEFAULT_LIBC )
146
- set ( LINKER_FLAGS_COMMON " ${LINKER_FLAGS_COMMON} -nostdlib" )
168
+ jerry_add_link_flags ( -nostdlib )
147
169
endif ()
148
170
149
171
# Turn off stack protector
150
- set ( CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -fno-stack-protector" )
172
+ jerry_add_compile_flags ( -fno-stack-protector )
151
173
152
174
# Debug information
153
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -gdwarf-4" )
154
-
155
- macro (add_jerry_compile_flags )
156
- foreach (_flag ${ARGV} )
157
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag} " )
158
- endforeach ()
159
- endmacro ()
160
-
161
- macro (add_jerry_compile_warnings )
162
- foreach (_warning ${ARGV} )
163
- add_jerry_compile_flags (-W${_warning} )
164
- if (CMAKE_COMPILER_IS_GNUCC )
165
- add_jerry_compile_flags (-Werror=${_warning} )
166
- endif ()
167
- endforeach ()
168
- endmacro ()
175
+ jerry_add_compile_flags (-g -gdwarf-4 )
169
176
170
- add_jerry_compile_warnings (all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations )
171
- add_jerry_compile_flags (-Wno-stack-protector -Wno-attributes )
177
+ jerry_add_compile_warnings (all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations )
178
+ jerry_add_compile_flags (-Wno-stack-protector -Wno-attributes )
172
179
173
180
if (CMAKE_COMPILER_IS_GNUCC )
174
181
if (JERRY_LIBC )
175
- add_jerry_compile_flags (-Werror )
182
+ jerry_add_compile_flags (-Werror )
176
183
endif ()
177
- add_jerry_compile_warnings (logical-op )
184
+ jerry_add_compile_warnings (logical-op )
178
185
else ()
179
- add_jerry_compile_flags (-Wno-nested-anon-types )
186
+ jerry_add_compile_flags (-Wno-nested-anon-types )
180
187
endif ()
181
188
182
189
if (DEFINED EXTERNAL_COMPILE_FLAGS )
183
- foreach (FLAG ${EXTERNAL_COMPILE_FLAGS} )
184
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG} " )
185
- endforeach ()
190
+ jerry_add_compile_flags (${EXTERNAL_COMPILE_FLAGS} )
186
191
endif ()
187
192
188
193
if (DEFINED EXTERNAL_LINKER_FLAGS )
189
- foreach (FLAG ${EXTERNAL_LINKER_FLAGS} )
190
- set (LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} ${FLAG} " )
191
- endforeach ()
194
+ jerry_add_link_flags (${EXTERNAL_LINKER_FLAGS} )
192
195
endif ()
193
196
194
197
# C
195
- set ( CMAKE_C_FLAGS " ${CMAKE_C_FLAGS} -std=c99 -pedantic" )
198
+ jerry_add_compile_flags ( -std=c99 -pedantic )
196
199
197
200
# Strip binary
198
201
if (ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
199
- set ( LINKER_FLAGS_COMMON " ${LINKER_FLAGS_COMMON} -s" )
202
+ jerry_add_link_flags ( -s )
200
203
endif ()
201
204
202
205
# Jerry's libc
0 commit comments