-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
85 lines (74 loc) · 3.3 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
cmake_minimum_required(VERSION 2.8)
project(rtnode C)
if(NOT DEFINED JS_ROOT)
message(FATAL_ERROR "missing js root")
endif()
set(JS_USER_CODE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${JS_ROOT})
if(NOT EXISTS "${JS_USER_CODE_DIR}/app.js")
message(FATAL_ERROR "missing app.js in ${JS_USER_CODE_DIR}")
endif()
set(JS_INTERNAL_CODE_DIR ${CMAKE_SOURCE_DIR}/src/js)
# set jerry build options
set(ENABLE_LTO OFF CACHE BOOL "Enable LTO")
set(JERRY_CMDLINE OFF CACHE BOOL "Build jerry 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_LIBM ON CACHE BOOL "Build and use jerry-libm?")
set(JERRY_ERROR_MESSAGES ON CACHE BOOL "Enable error messages?")
set(JERRY_EXTERNAL_CONTEXT ON CACHE BOOL "Enable external context?")
set(JERRY_PARSER ON CACHE BOOL "Enable javascript-parser?")
set(JERRY_LINE_INFO ON CACHE BOOL "Enable line info?")
set(JERRY_MEM_STATS OFF CACHE BOOL "Enable memory statistics?")
set(JERRY_PROFILE "es2015-subset" CACHE STRING "Use default or other profile?")
set(JERRY_SNAPSHOT_EXEC ON CACHE BOOL "Enable executing snapshot files?")
set(JERRY_GLOBAL_HEAP_SIZE "(128)" CACHE STRING "Size of memory heap, in kilobytes")
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "xtensa")
# FIXME add platform flag to distinguish between different platforms
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlongcalls")
add_definitions(-D__ESP_IDF__=1)
endif()
# package src/js/*.js to src/rtnode-snapshots.c before build
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/src/js-snapshots.c ${CMAKE_SOURCE_DIR}/js-snapshots.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND bash ${CMAKE_SOURCE_DIR}/tools/js2c.sh ${JS_USER_CODE_DIR} ${JS_INTERNAL_CODE_DIR}
DEPENDS ${CMAKE_SOURCE_DIR}/tools/js2c.sh ${CMAKE_SOURCE_DIR}/tools/js2c.py)
# set header search path
set(INCLUDE_LIST
${CMAKE_SOURCE_DIR}/deps/jerryscript/jerry-core/include
${CMAKE_SOURCE_DIR}/deps/jerryscript/jerry-ext/include
${CMAKE_SOURCE_DIR}/deps/jerryscript/jerry-port/default/include
${CMAKE_SOURCE_DIR}/deps/rv/include
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src/internal
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/modules)
include_directories(${INCLUDE_LIST})
# set source list
aux_source_directory(src/ SRC_LIST)
aux_source_directory(src/napi NAPI_LIST)
aux_source_directory(src/modules MODULES_LIST)
set(SNAPSHOT_SRC src/js-snapshots.c)
# build deps
add_subdirectory(deps/jerryscript)
add_subdirectory(deps/rv)
# build library
add_library(rtnode ${SRC_LIST} ${NAPI_LIST} ${MODULES_LIST} ${SNAPSHOT_SRC})
target_link_libraries(rtnode
rv
jerry-core
jerry-ext
jerry-port-default-minimal)
# build sample
if(DEFINED SAMPLE)
if("${SAMPLE}" STREQUAL "unix")
add_subdirectory(samples/unix)
elseif("${SAMPLE}" STREQUAL "esp-idf")
include(ExternalProject)
externalproject_add(rtnode-esp-idf
SOURCE_DIR ${CMAKE_SOURCE_DIR}/samples/esp-idf/
BINARY_DIR ${CMAKE_BINARY_DIR}/rtnode-build
CMAKE_ARGS)
else()
message(FATAL_ERROR "unsupported platform ${SAMPLE}")
endif()
endif()