forked from jerryscript-project/jerryscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
521 lines (431 loc) · 18.9 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
#
# 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)
# Compiler configuration
if(NOT (("${PLATFORM}" STREQUAL "DARWIN") OR ("${PLATFORM}" STREQUAL "EXTERNAL")))
if(NOT CMAKE_COMPILER_IS_GNUCC)
message(FATAL_ERROR "gcc compiler is required")
endif()
endif()
if(CMAKE_COMPILER_IS_GNUCC)
# Require gcc of version >= 4.7.0
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GNU_CC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${GNU_CC_VERSION} VERSION_LESS 4.7.0)
message(FATAL_ERROR "gcc compiler version 4.7.0 or higher required")
endif()
endif()
# Imported targets prefix
set(PREFIX_IMPORTED_LIB imported_)
# Architecture-specific compile/link flags
foreach(FLAG ${FLAGS_COMMON_ARCH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}")
endforeach()
# Remove rdynamic option
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )
# Defining options
option(ENABLE_VALGRIND "Enable valgrind helpers in memory allocators" OFF)
option(ENABLE_VALGRIND_FREYA "Enable valgrind-freya helpers in memory allocators" OFF)
option(ENABLE_LTO "Enable LTO build" ON)
option(ENABLE_LOG "Enable LOG build" OFF)
option(ENABLE_ALL_IN_ONE "Enable ALL_IN_ONE build" OFF)
option(ENABLE_ERROR_MESSAGES "Enable error messages for builtin error objects" OFF)
if("${PLATFORM}" STREQUAL "LINUX")
set(PLATFORM_EXT "LINUX")
set(EXTERNAL_BUILD FALSE)
option(STRIP_RELEASE_BINARY "Strip symbols from release binaries" ON)
elseif("${PLATFORM}" STREQUAL "DARWIN")
option(ENABLE_LTO "Enable LTO build" OFF)
option(ENABLE_ALL_IN_ONE "Enable ALL_IN_ONE build" ON)
set(PLATFORM_EXT "DARWIN")
set(EXTERNAL_BUILD FALSE)
option(STRIP_RELEASE_BINARY "Strip symbols from release binaries" ON)
elseif("${PLATFORM}" STREQUAL "MCU")
if (("${ENABLE_VALGRIND}" STREQUAL "ON") OR ("${ENABLE_VALGRIND_FREYA}" STREQUAL "ON"))
message(FATAL_ERROR "This target isn't supported with Valgrind.")
endif()
set(PLATFORM_EXT "MCU_${CMAKE_SYSTEM_VERSION}")
set(EXTERNAL_BUILD FALSE)
option(STRIP_RELEASE_BINARY "Strip symbols from release binaries" OFF)
set(MCU_SCRIPT_FILE "tests/blinky.js" CACHE STRING "Script to run on MCU")
elseif("${PLATFORM}" STREQUAL "EXTERNAL")
set(PLATFORM_EXT "EXTERNAL")
set(EXTERNAL_BUILD TRUE)
set(EXTERNAL_LIBC_INTERFACE "UNDEFINED" CACHE STRING "Path to external libc include directory")
set(EXTERNAL_LIBS_INTERFACE "UNDEFINED" CACHE STRING "Path to external libraries' include directory")
set(EXTERNAL_MEM_HEAP_SIZE_KB "256" CACHE STRING "Size of memory heap, in kilobytes")
elseif("${PLATFORM}" STREQUAL "OPENWRT")
set(PLATFORM_EXT "LINUX")
set(EXTERNAL_BUILD FALSE)
option(STRIP_RELEASE_BINARY "Strip symbols from release binaries" ON)
else()
message(FATAL_ERROR "Platform '${PLATFORM}' is not supported")
endif()
if(CMAKE_COMPILER_IS_GNUCC)
if("${ENABLE_LTO}" STREQUAL "ON")
# Use gcc-ar and gcc-ranlib to support LTO
get_filename_component(PATH_TO_GCC ${CMAKE_C_COMPILER} REALPATH)
get_filename_component(DIRECTORY_GCC ${PATH_TO_GCC} DIRECTORY)
get_filename_component(FILE_NAME_GCC ${PATH_TO_GCC} NAME)
string(REPLACE "gcc" "gcc-ar" CMAKE_AR ${FILE_NAME_GCC})
string(REPLACE "gcc" "gcc-ranlib" CMAKE_RANLIB ${FILE_NAME_GCC})
set(CMAKE_AR ${DIRECTORY_GCC}/${CMAKE_AR})
set(CMAKE_RANLIB ${DIRECTORY_GCC}/${CMAKE_RANLIB})
endif()
endif()
# Intermediate files
# Script to run on MCU
set(MCU_SCRIPT_GENERATED_HEADER ${CMAKE_BINARY_DIR}/generated.h)
# Should we use external libc?
if(DEFINED COMPILER_DEFAULT_LIBC AND COMPILER_DEFAULT_LIBC STREQUAL "ON")
if(DEFINED EXTERNAL_LIBC_INTERFACE AND NOT EXTERNAL_LIBC_INTERFACE STREQUAL "UNDEFINED")
message(FATAL_ERROR "EXTERNAL_LIBC_INTERFACE='${EXTERNAL_LIBC_INTERFACE}' should not be set in case compiler's default libc is used (COMPILER_DEFAULT_LIBC=ON)")
endif()
set(USE_JERRY_LIBC FALSE)
elseif(NOT DEFINED EXTERNAL_LIBC_INTERFACE OR EXTERNAL_LIBC_INTERFACE STREQUAL "UNDEFINED")
set(USE_JERRY_LIBC TRUE)
else()
set(USE_JERRY_LIBC FALSE)
if(NOT EXISTS "${EXTERNAL_LIBC_INTERFACE}/stdlib.h")
message(FATAL_ERROR "It seems that external libc interface '${EXTERNAL_LIBC_INTERFACE}' doesn't provide stdlib.h header")
endif()
set(INCLUDE_LIBC_INTERFACE ${EXTERNAL_LIBC_INTERFACE})
endif()
# Should we use external jerry-port.c?
if(DEFINED EXTERNAL_PORT_FILE AND NOT EXTERNAL_PORT_FILE STREQUAL "UNDEFINED")
set(SOURCE_PORT_IMPLEMENTATION ${EXTERNAL_PORT_FILE})
set(USE_DEFAULT_PORT FALSE)
else()
set(USE_DEFAULT_PORT TRUE)
endif()
# Are there any interfaces for external libraries, other than libc, that should be registered?
if(DEFINED EXTERNAL_LIBS_INTERFACE AND NOT EXTERNAL_LIBS_INTERFACE STREQUAL "UNDEFINED")
set(INCLUDE_EXTERNAL_LIBS_INTERFACE )
foreach(EXTERNAL_LIB_INTERFACE ${EXTERNAL_LIBS_INTERFACE})
if (NOT EXISTS "${EXTERNAL_LIB_INTERFACE}")
message(FATAL_ERROR "Interface directory of the external library doesn't exist: ${EXTERNAL_LIB_INTERFACE}")
endif()
set(INCLUDE_EXTERNAL_LIBS_INTERFACE ${INCLUDE_EXTERNAL_LIBS_INTERFACE} ${EXTERNAL_LIB_INTERFACE})
endforeach()
endif()
# Build modes
# Debug
set(BUILD_MODE_PREFIX_DEBUG debug)
# Release
set(BUILD_MODE_PREFIX_RELEASE release)
# Unit tests
set(BUILD_MODE_PREFIX_UNITTESTS unittests)
# Modifiers
# Profiles
# Full profile (default, so - no suffix)
set(MODIFIER_SUFFIX_FULL_PROFILE "")
# Compact profile
set(MODIFIER_SUFFIX_COMPACT_PROFILE -cp)
# Minimal compact profile
set(MODIFIER_SUFFIX_COMPACT_PROFILE_MINIMAL -cp_minimal)
# Memory statistics
set(MODIFIER_SUFFIX_MEMORY_STATISTICS -mem_stats)
# Memory management stress-test mode
set(MODIFIER_SUFFIX_MEM_STRESS_TEST -mem_stress_test)
# Modifier lists
# Linux
set(MODIFIERS_LISTS_LINUX
"FULL_PROFILE"
"FULL_PROFILE MEM_STRESS_TEST"
"COMPACT_PROFILE"
"COMPACT_PROFILE_MINIMAL"
"FULL_PROFILE MEMORY_STATISTICS"
"COMPACT_PROFILE_MINIMAL MEMORY_STATISTICS")
# Darwin
set(MODIFIERS_LISTS_DARWIN
"FULL_PROFILE"
"FULL_PROFILE MEM_STRESS_TEST"
"COMPACT_PROFILE"
"COMPACT_PROFILE_MINIMAL"
"FULL_PROFILE MEMORY_STATISTICS"
"COMPACT_PROFILE_MINIMAL MEMORY_STATISTICS")
# MCU
# stm32f3
set(MODIFIERS_LISTS_MCU_STM32F3
"FULL_PROFILE"
"COMPACT_PROFILE"
"COMPACT_PROFILE_MINIMAL")
# stm32f4
set(MODIFIERS_LISTS_MCU_STM32F4
"FULL_PROFILE"
"COMPACT_PROFILE"
"COMPACT_PROFILE_MINIMAL")
# External
set(MODIFIERS_LISTS_EXTERNAL
"FULL_PROFILE"
"COMPACT_PROFILE"
"COMPACT_PROFILE_MINIMAL"
"FULL_PROFILE MEMORY_STATISTICS"
"COMPACT_PROFILE MEMORY_STATISTICS")
# Compiler / Linker flags
set(COMPILE_FLAGS_JERRY "-fno-builtin")
if(NOT ("${PLATFORM}" STREQUAL "DARWIN"))
set(LINKER_FLAGS_COMMON "-Wl,-z,noexecstack")
endif()
set(LINKER_FLAGS_COMMON_DARWIN "-lSystem")
# Turn off linking to compiler's default libc, in case jerry-libc is used
if(${USE_JERRY_LIBC})
set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} -nostdlib")
endif()
# LTO
if("${ENABLE_LTO}" STREQUAL "ON")
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -flto")
if(NOT ("${PLATFORM}" STREQUAL "DARWIN"))
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -fno-fat-lto-objects")
endif()
set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} -flto")
endif()
# Generage map file
if("${PLATFORM}" STREQUAL "DARWIN")
set(MAP_FILE_FLAGS "-Xlinker -map -Xlinker jerry.map")
else()
set(MAP_FILE_FLAGS "-Xlinker -Map -Xlinker jerry.map")
endif()
set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} ${MAP_FILE_FLAGS}")
# Turn off stack protector
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -fno-stack-protector")
# Debug information
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} -g -gdwarf-4")
# Warnings
macro(append variable value)
set(${variable} "${${variable}} ${value}")
endmacro()
macro(add_jerry_compile_flags)
foreach(_flag ${ARGV})
append(COMPILE_FLAGS_JERRY ${_flag})
endforeach()
endmacro()
macro(add_jerry_compile_warnings)
foreach(_warning ${ARGV})
add_jerry_compile_flags(-W${_warning})
if(CMAKE_COMPILER_IS_GNUCC)
add_jerry_compile_flags(-Werror=${_warning})
endif()
endforeach()
endmacro()
add_jerry_compile_warnings(all extra format-nonliteral init-self conversion sign-conversion format-security missing-declarations pedantic)
add_jerry_compile_flags(-Wno-stack-protector -Wno-attributes)
if(CMAKE_COMPILER_IS_GNUCC)
if(${USE_JERRY_LIBC})
add_jerry_compile_flags(-Werror)
endif()
add_jerry_compile_warnings(logical-op)
else()
add_jerry_compile_flags(-Wno-nested-anon-types)
endif()
if(DEFINED EXTERNAL_COMPILE_FLAGS)
foreach(FLAG ${EXTERNAL_COMPILE_FLAGS})
set(COMPILE_FLAGS_JERRY "${COMPILE_FLAGS_JERRY} ${FLAG}")
endforeach()
endif()
# Static build
if(NOT ("${PLATFORM}" STREQUAL "DARWIN"))
set(LINKER_FLAGS_STATIC "-static")
endif()
# C
set(C_FLAGS_JERRY "-std=c99")
# Platform-specific
# MCU
# stm32f3
set(LINKER_FLAGS_COMMON_MCU_STM32F3 "-T${CMAKE_SOURCE_DIR}/third-party/STM32F3-Discovery_FW_V1.1.0/Project/Peripheral_Examples/FLASH_Program/TrueSTUDIO/FLASH_Program/STM32_FLASH.ld")
# stm32f4
set(LINKER_FLAGS_COMMON_MCU_STM32F4 "-T${CMAKE_SOURCE_DIR}/third-party/STM32F4-Discovery_FW_V1.1.0/Project/Peripheral_Examples/FLASH_Program/TrueSTUDIO/FLASH_Program/stm32_flash.ld")
# Debug
set(FLAGS_COMMON_DEBUG "")
# Release
set(FLAGS_COMMON_RELEASE "-Os")
# Unit tests
set(FLAGS_COMMON_UNITTESTS "-O3")
# Include directories
# Core interface
set(INCLUDE_CORE_INTERFACE
${CMAKE_SOURCE_DIR}/jerry-core)
# Sources
# Platform-specific
# Jerry standalone
# Linux
set(SOURCE_JERRY_STANDALONE_MAIN_LINUX main-unix.c)
# Darwin
set(SOURCE_JERRY_STANDALONE_MAIN_DARWIN main-unix.c)
# MCU
# stm32f3
set(SOURCE_JERRY_STANDALONE_MAIN_MCU_STM32F3 main-mcu.c)
# stm32f4
set(SOURCE_JERRY_STANDALONE_MAIN_MCU_STM32F4 main-mcu.c)
# Unit tests main modules
file(GLOB SOURCE_UNIT_TEST_MAIN_MODULES tests/unit/*.c)
# Imported libraries
if(("${PLATFORM}" STREQUAL "DARWIN") AND (NOT CMAKE_COMPILER_IS_GNUCC))
# libclang_rt.osx
add_library(${PREFIX_IMPORTED_LIB}libclang_rt.osx STATIC IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=
OUTPUT_VARIABLE IMPORTED_LIBCLANG_RT_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(IMPORTED_LIBCLANG_RT_LOCATION "${IMPORTED_LIBCLANG_RT_LOCATION}/lib/darwin/libclang_rt.osx.a")
set_property(TARGET ${PREFIX_IMPORTED_LIB}libclang_rt.osx
PROPERTY IMPORTED_LOCATION ${IMPORTED_LIBCLANG_RT_LOCATION})
else()
# libgcc
add_library(${PREFIX_IMPORTED_LIB}libgcc STATIC IMPORTED)
execute_process(COMMAND ${CMAKE_C_COMPILER} ${FLAGS_COMMON_ARCH} -print-file-name=libgcc.a
OUTPUT_VARIABLE IMPORTED_LIBGCC_LOCATION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set_property(TARGET ${PREFIX_IMPORTED_LIB}libgcc
PROPERTY IMPORTED_LOCATION ${IMPORTED_LIBGCC_LOCATION})
endif()
# Platform-specific configuration
set(MODIFIERS_LISTS ${MODIFIERS_LISTS_${PLATFORM_EXT}})
set(LINKER_FLAGS_COMMON "${LINKER_FLAGS_COMMON} ${LINKER_FLAGS_COMMON_${PLATFORM_EXT}}")
set(SOURCE_JERRY_STANDALONE_MAIN ${SOURCE_JERRY_STANDALONE_MAIN_${PLATFORM_EXT}})
# Component targets
# Jerry's libc
if(${USE_JERRY_LIBC})
add_subdirectory(jerry-libc)
endif()
# Jerry's libm
add_subdirectory(jerry-libm)
# Jerry's Core
add_subdirectory(jerry-core)
# Targets declaration
string(TOLOWER "${PLATFORM_EXT}" PLATFORM_L)
function(declare_targets_for_build_mode BUILD_MODE)
set(TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.${PLATFORM_L})
if (${USE_JERRY_LIBC})
set(LIBC_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.jerry-libc.${PLATFORM_L}.lib)
endif()
function(declare_target_with_modifiers) # modifiers are passed in ARGN implicit argument
set(CORE_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}})
foreach(MODIFIER ${ARGN})
set(TARGET_NAME ${TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}})
set(CORE_TARGET_NAME ${CORE_TARGET_NAME}${MODIFIER_SUFFIX_${MODIFIER}})
endforeach()
set(LIBM_TARGET_NAME ${CORE_TARGET_NAME}.jerry-libm.lib)
set(CORE_TARGET_NAME ${CORE_TARGET_NAME}.jerry-core)
set(DEFINES_JERRY )
if(NOT ${EXTERNAL_BUILD})
add_executable(${TARGET_NAME} ${SOURCE_JERRY_STANDALONE_MAIN})
if("${PLATFORM}" STREQUAL "MCU")
set(MCU_SCRIPT_GENERATED_HEADER ${MCU_SCRIPT_GENERATED_HEADER}.${TARGET_NAME})
add_custom_command(OUTPUT ${MCU_SCRIPT_GENERATED_HEADER}
COMMAND ${CMAKE_SOURCE_DIR}/tools/generator.sh "${CMAKE_SOURCE_DIR}/${MCU_SCRIPT_FILE}" ${MCU_SCRIPT_GENERATED_HEADER}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_custom_target(mcu_header_with_script_to_run.${TARGET_NAME} DEPENDS ${MCU_SCRIPT_GENERATED_HEADER})
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_MCU_SCRIPT_HEADER="${MCU_SCRIPT_GENERATED_HEADER}")
elseif(("${PLATFORM}" STREQUAL "LINUX") OR ("${PLATFORM}" STREQUAL "DARWIN"))
if("${ENABLE_LOG}" STREQUAL "ON")
set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_ENABLE_LOG)
endif()
endif()
set_property(TARGET ${TARGET_NAME}
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_JERRY} ${FLAGS_COMMON_${BUILD_MODE}} ${C_FLAGS_JERRY}")
set_property(TARGET ${TARGET_NAME}
PROPERTY LINK_FLAGS "${COMPILE_FLAGS_JERRY} ${FLAGS_COMMON_${BUILD_MODE}} ${LINKER_FLAGS_COMMON} ${LINKER_FLAGS_STATIC}")
target_compile_definitions(${TARGET_NAME} PRIVATE ${DEFINES_JERRY})
target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDE_CORE_INTERFACE})
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDE_LIBC_INTERFACE})
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDE_EXTERNAL_LIBS_INTERFACE})
if(("${PLATFORM}" STREQUAL "DARWIN") AND (NOT (CMAKE_COMPILER_IS_GNUCC)))
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${LIBC_TARGET_NAME}
${LIBM_TARGET_NAME} ${PREFIX_IMPORTED_LIB}libclang_rt.osx)
else()
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${LIBC_TARGET_NAME}
${LIBM_TARGET_NAME} ${PREFIX_IMPORTED_LIB}libgcc)
endif()
if("${PLATFORM}" STREQUAL "MCU")
add_dependencies(${TARGET_NAME} mcu_header_with_script_to_run.${TARGET_NAME})
add_custom_target(${TARGET_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${TARGET_NAME}> $<TARGET_FILE:${TARGET_NAME}>.bin
DEPENDS ${TARGET_NAME})
add_custom_target(${TARGET_NAME}.flash
COMMAND st-flash write $<TARGET_FILE:${TARGET_NAME}>.bin 0x08000000
DEPENDS ${TARGET_NAME}.bin)
endif()
if("${BUILD_MODE}" STREQUAL "RELEASE")
if(${STRIP_RELEASE_BINARY} STREQUAL "ON")
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${TARGET_NAME}>)
endif()
endif()
else()
add_custom_target(${TARGET_NAME} ALL)
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/${TARGET_NAME}
COMMAND echo $<TARGET_FILE:${LIBM_TARGET_NAME}> > ${CMAKE_BINARY_DIR}/${TARGET_NAME}/list
COMMAND echo $<TARGET_FILE:${CORE_TARGET_NAME}> >> ${CMAKE_BINARY_DIR}/${TARGET_NAME}/list)
if(DEFINED EXTERNAL_BUILD_ENTRY_FILE)
add_library(${TARGET_NAME}-entry STATIC ${EXTERNAL_BUILD_ENTRY_FILE})
set_property(TARGET ${TARGET_NAME}-entry
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_JERRY} ${FLAGS_COMMON_${BUILD_MODE}}")
target_compile_definitions(${TARGET_NAME}-entry PRIVATE ${DEFINES_JERRY})
target_include_directories(${TARGET_NAME}-entry PRIVATE ${INCLUDE_CORE_INTERFACE})
target_include_directories(${TARGET_NAME}-entry SYSTEM PRIVATE ${CMAKE_SOURCE_DIR})
target_include_directories(${TARGET_NAME}-entry SYSTEM PRIVATE ${INCLUDE_LIBC_INTERFACE})
target_include_directories(${TARGET_NAME}-entry SYSTEM PRIVATE ${INCLUDE_EXTERNAL_LIBS_INTERFACE})
add_dependencies(${TARGET_NAME} ${TARGET_NAME}-entry)
endif()
if(${USE_JERRY_LIBC})
add_custom_command(TARGET ${TARGET_NAME}
POST_BUILD
COMMAND echo $<TARGET_FILE:${LIBC_TARGET_NAME}> >> ${CMAKE_BINARY_DIR}/${TARGET_NAME}/list)
endif()
endif()
endfunction()
foreach(MODIFIERS_LIST ${MODIFIERS_LISTS})
separate_arguments(MODIFIERS_LIST)
declare_target_with_modifiers(${MODIFIERS_LIST})
endforeach()
endfunction()
declare_targets_for_build_mode(DEBUG)
declare_targets_for_build_mode(RELEASE)
# Unit tests declaration
if(("${PLATFORM}" STREQUAL "LINUX") OR ("${PLATFORM}" STREQUAL "DARWIN"))
add_custom_target(unittests)
foreach(SOURCE_UNIT_TEST_MAIN ${SOURCE_UNIT_TEST_MAIN_MODULES})
get_filename_component(TARGET_NAME ${SOURCE_UNIT_TEST_MAIN} NAME_WE)
set(TARGET_NAME unit-${TARGET_NAME})
set(CORE_TARGET_NAME unittests.jerry-core)
if (${USE_JERRY_LIBC})
set(LIBC_TARGET_NAME unittests.jerry-libc.${PLATFORM_L}.lib)
endif ()
set(LIBM_TARGET_NAME unittests.jerry-libm.lib)
add_executable(${TARGET_NAME} ${SOURCE_UNIT_TEST_MAIN})
set_property(TARGET ${TARGET_NAME}
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY} ${FLAGS_COMMON_UNITTESTS}")
set_property(TARGET ${TARGET_NAME}
PROPERTY LINK_FLAGS "${COMPILE_FLAGS_JERRY} ${FLAGS_COMMON_UNITTESTS} ${LINKER_FLAGS_COMMON}")
target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDE_CORE_INTERFACE})
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDE_LIBC_INTERFACE})
if(("${PLATFORM}" STREQUAL "DARWIN") AND (NOT (CMAKE_COMPILER_IS_GNUCC)))
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${LIBC_TARGET_NAME} ${LIBM_TARGET_NAME}
${PREFIX_IMPORTED_LIB}libclang_rt.osx)
else()
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${LIBC_TARGET_NAME} ${LIBM_TARGET_NAME}
${PREFIX_IMPORTED_LIB}libgcc)
endif()
add_dependencies(unittests ${TARGET_NAME})
endforeach()
endif()