forked from martijnthe/jerryscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
268 lines (221 loc) · 7.61 KB
/
CMakeLists.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# Copyright JS Foundation and other contributors, http://js.foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required (VERSION 2.8.12)
project (Jerry C ASM)
# Determining platform
set(PLATFORM "${CMAKE_SYSTEM_NAME}")
string(TOUPPER "${PLATFORM}" PLATFORM)
# Remove rdynamic option
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
# Components
set(JERRY_CMDLINE ON CACHE BOOL "Build jerry command line tool?")
set(JERRY_CMDLINE_MINIMAL OFF CACHE BOOL "Build jerry minimal command line tool?")
set(JERRY_PORT_DEFAULT ON CACHE BOOL "Build default jerry port implementation?")
set(JERRY_EXT ON CACHE BOOL "Build jerry-ext?")
set(JERRY_LIBC ON CACHE BOOL "Build and use jerry-libc?")
set(JERRY_LIBM ON CACHE BOOL "Build and use jerry-libm?")
set(UNITTESTS OFF CACHE BOOL "Build unit tests?")
# Optional build settings
set(ENABLE_ALL_IN_ONE OFF CACHE BOOL "Enable all-in-one build?")
set(ENABLE_LTO ON CACHE BOOL "Enable LTO build?")
set(ENABLE_STATIC_LINK ON CACHE BOOL "Enable static linking?")
set(ENABLE_STRIP ON CACHE BOOL "Enable stripping all symbols from release binary?")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel")
endif()
if(JERRY_CMDLINE OR JERRY_CMDLINE_MINIMAL)
set(JERRY_PORT_DEFAULT "ON")
set(JERRY_PORT_DEFAULT_MESSAGE " (FORCED BY CMDLINE)")
endif()
if(JERRY_CMDLINE)
set(JERRY_EXT "ON")
set(JERRY_EXT_MESSAGE " (FORCED BY CMDLINE)")
endif()
if("${PLATFORM}" STREQUAL "DARWIN")
set(JERRY_LIBC "OFF")
set(JERRY_LIBM "OFF")
set(ENABLE_ALL_IN_ONE "ON")
set(ENABLE_LTO "OFF")
set(ENABLE_STATIC_LINK "OFF")
set(ENABLE_STRIP "OFF")
set(JERRY_LIBC_MESSAGE " (FORCED BY PLATFORM)")
set(JERRY_LIBM_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_ALL_IN_ONE_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_LTO_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_STATIC_LINK_MESSAGE " (FORCED BY PLATFORM)")
set(ENABLE_STRIP_MESSAGE " (FORCED BY PLATFORM)")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(USING_GCC 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(USING_CLANG 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "TI")
set(USING_TI 1)
endif()
if(USING_TI)
set(ENABLE_STATIC_LINK "ON")
set(ENABLE_STRIP "OFF")
set(ENABLE_STATIC_LINK_MESSAGE " (FORCED BY COMPILER)")
set(ENABLE_STRIP_MESSAGE " (FORCED BY COMPILER)")
endif()
# Status messages
message(STATUS "CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
message(STATUS "CMAKE_SYSTEM_NAME " ${CMAKE_SYSTEM_NAME})
message(STATUS "CMAKE_SYSTEM_PROCESSOR " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "ENABLE_ALL_IN_ONE " ${ENABLE_ALL_IN_ONE} ${ENABLE_ALL_IN_ONE_MESSAGE})
message(STATUS "ENABLE_LTO " ${ENABLE_LTO} ${ENABLE_LTO_MESSAGE})
message(STATUS "ENABLE_STATIC_LINK " ${ENABLE_STATIC_LINK} ${ENABLE_STATIC_LINK_MESSAGE})
message(STATUS "ENABLE_STRIP " ${ENABLE_STRIP} ${ENABLE_STRIP_MESSAGE})
message(STATUS "JERRY_CMDLINE " ${JERRY_CMDLINE})
message(STATUS "JERRY_CMDLINE_MINIMAL " ${JERRY_CMDLINE_MINIMAL})
message(STATUS "JERRY_PORT_DEFAULT " ${JERRY_PORT_DEFAULT} ${JERRY_PORT_DEFAULT_MESSAGE})
message(STATUS "JERRY_EXT " ${JERRY_EXT} ${JERRY_EXT_MESSAGE})
message(STATUS "JERRY_LIBC " ${JERRY_LIBC} ${JERRY_LIBC_MESSAGE})
message(STATUS "JERRY_LIBM " ${JERRY_LIBM} ${JERRY_LIBM_MESSAGE})
message(STATUS "UNITTESTS " ${UNITTESTS})
# Setup directories
# Project binary dir
set(PROJECT_BINARY_DIR "${CMAKE_BINARY_DIR}")
# Library output directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/")
# Executable output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/")
# Archive targets output Directory
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/")
# Compile/link flags
# Helper macros
macro(jerry_add_flags VAR)
foreach(_flag ${ARGN})
set(${VAR} "${${VAR}} ${_flag}")
endforeach()
endmacro()
macro(jerry_add_compile_flags)
jerry_add_flags(CMAKE_C_FLAGS ${ARGV})
endmacro()
macro(jerry_add_compile_warnings)
foreach(_warning ${ARGV})
jerry_add_compile_flags(-W${_warning})
if(USING_GCC)
jerry_add_compile_flags(-Werror=${_warning})
endif()
endforeach()
endmacro()
macro(jerry_add_link_flags)
jerry_add_flags(LINKER_FLAGS_COMMON ${ARGV})
endmacro()
# Architecture-specific compile/link flags
jerry_add_compile_flags(${FLAGS_COMMON_ARCH})
jerry_add_flags(CMAKE_EXE_LINKER_FLAGS ${FLAGS_COMMON_ARCH})
# Enable static build
if(ENABLE_STATIC_LINK)
if (USING_GCC OR USING_CLANG)
jerry_add_link_flags("-static")
endif()
endif()
# LTO
if(ENABLE_LTO)
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-flto)
jerry_add_link_flags(-flto)
endif()
if(USING_GCC)
jerry_add_compile_flags(-fno-fat-lto-objects)
# Use gcc-ar and gcc-ranlib to support LTO
set(CMAKE_AR "gcc-ar")
set(CMAKE_RANLIB "gcc-ranlib")
endif()
if(USING_TI)
jerry_add_link_flags(-lto)
endif()
endif()
# Compiler / Linker flags
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-fno-builtin)
endif()
if(("${PLATFORM}" STREQUAL "DARWIN"))
jerry_add_link_flags(-lSystem)
else()
jerry_add_link_flags(-Wl,-z,noexecstack)
endif()
# Turn off linking to compiler's default libc, in case jerry-libc is used
if(JERRY_LIBC)
jerry_add_link_flags(-nostdlib)
endif()
# Turn off stack protector
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-fno-stack-protector)
endif()
if (USING_GCC OR USING_CLANG)
jerry_add_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations shadow strict-prototypes undef old-style-definition)
jerry_add_compile_flags(-Wno-stack-protector -Wno-attributes)
endif()
if(USING_GCC)
jerry_add_compile_warnings(logical-op)
elseif(USING_CLANG)
jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline)
endif()
if(JERRY_LIBC)
jerry_add_compile_flags(-Werror)
endif()
# C
if (USING_GCC OR USING_CLANG)
jerry_add_compile_flags(-std=c99 -pedantic)
elseif(USING_TI)
jerry_add_compile_flags(--c99)
endif()
# Strip binary
if(ENABLE_STRIP AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
jerry_add_link_flags(-s)
endif()
# External compiler & linker flags
if(DEFINED EXTERNAL_COMPILE_FLAGS)
jerry_add_compile_flags(${EXTERNAL_COMPILE_FLAGS})
endif()
if(DEFINED EXTERNAL_LINKER_FLAGS)
jerry_add_link_flags(${EXTERNAL_LINKER_FLAGS})
endif()
# Jerry's libc
if(JERRY_LIBC)
add_subdirectory(jerry-libc)
endif()
# Jerry's libm
if(JERRY_LIBM)
add_subdirectory(jerry-libm)
endif()
# Jerry's core
add_subdirectory(jerry-core)
# Jerry's default port implementation
if(JERRY_PORT_DEFAULT)
add_subdirectory(jerry-port/default)
endif()
# Jerry's extension tools
if(JERRY_EXT)
add_subdirectory(jerry-ext)
endif()
# Jerry command line tool
if(JERRY_CMDLINE OR JERRY_CMDLINE_MINIMAL)
add_subdirectory(jerry-main)
endif()
# Unittests
if(UNITTESTS)
add_subdirectory(tests/unit-core)
if(JERRY_LIBM)
add_subdirectory(tests/unit-libm)
endif()
if(JERRY_EXT)
add_subdirectory(tests/unit-ext)
endif()
endif()