-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
142 lines (116 loc) · 4.17 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
IF(NOT "$ENV{RUFF_CMAKE_CC}" STREQUAL "")
SET(CMAKE_C_COMPILER $ENV{RUFF_CMAKE_CC})
IF("$ENV{RUFF_CMAKE_CC}" MATCHES "android")
SET(CMAKE_SYSTEM_NAME Android)
IF(NOT "$ENV{ANDROID_NDK_HOME}" STREQUAL "")
SET(ANDROID_NDK_HOME $ENV{ANDROID_NDK_HOME})
ELSE()
MESSAGE(FATAL_ERROR "You MUST set ANDROID_NDK_HOME for Android build")
ENDIF()
ELSE()
SET(CMAKE_SYSTEM_NAME Linux)
ENDIF()
ENDIF()
MESSAGE(STATUS "CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}")
PROJECT(ruff)
####################
# CONFIG
####################
SET(RUFF_PROJECT YES)
SET(LIBRARY_INCLUDE_DIR "include")
SET(MAKE_COMMAND make)
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/misc")
SET(RUFF_JS_MODULES_PATH "${PROJECT_SOURCE_DIR}/modules/ruff_modules")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRUFF_COMPILER_COMPONENT -fno-stack-check")
SET(SOCKLIB "")
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Android")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE -pie")
ENDIF()
IF(NOT "$ENV{RUFF_CMAKE_ARCH}" STREQUAL "")
string(TOUPPER "$ENV{RUFF_CMAKE_ARCH}" RUFF_CMAKE_ARCH)
IF(${RUFF_CMAKE_ARCH} STREQUAL "ARM" OR "${RUFF_CMAKE_ARCH}" STREQUAL "MIPS")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic -Os -fdata-sections -ffunction-sections -Wl,--gc-sections")
ELSEIF(${RUFF_CMAKE_ARCH} STREQUAL "X86")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
ENDIF()
ENDIF()
IF(MSVC)
SET(SOCKLIB "ws2_32")
ENDIF()
IF(NOT DEFINED RUFF_VERSION)
SET(RUFF_VERSION "0.8.0")
ENDIF(NOT DEFINED RUFF_VERSION)
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/src/ruff_config.h.in"
"${PROJECT_SOURCE_DIR}/src/ruff_config.h"
)
INCLUDE(duktape)
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Android")
INCLUDE(uv-android)
ELSE()
INCLUDE(uv-legacy)
ENDIF()
####################
# INCLUDE
####################
ADD_CUSTOM_COMMAND(
OUTPUT ruff_native.h
COMMAND node ${PROJECT_SOURCE_DIR}/tools/build-embed-js.js ${PROJECT_SOURCE_DIR}/modules/ruff_modules buildin_js.bin
COMMAND ${CMAKE_COMMAND} -E copy ${RUFF_JS_MODULES_PATH}/ruffjs/bootstrap.js bootstrap.js
COMMAND node ${PROJECT_SOURCE_DIR}/tools/xxd.js bootstrap.js bootstrap_js > ruff_native.h
COMMAND node ${PROJECT_SOURCE_DIR}/tools/xxd.js buildin_js.bin buildin_js > ruff_buildin_js.h
DEPENDS ${RUFF_JS_MODULES_PATH}/ruffjs/bootstrap.js
)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(
"${PROJECT_SOURCE_DIR}/${LIBRARY_INCLUDE_DIR}"
"${PROJECT_SOURCE_DIR}/lib/duktape/src"
"${PROJECT_SOURCE_DIR}/lib/duktape/examples/debug-trans-socket"
"${PROJECT_SOURCE_DIR}/lib/uv/include"
"${PROJECT_SOURCE_DIR}/lib/"
"${PROJECT_SOURCE_DIR}/tools/compiler"
)
####################
# LINT
####################
INCLUDE(Clint)
AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/src" ALL_SOURCES)
ADD_STYLE_CHECK_TARGET(check "${ALL_SOURCES}")
###################
# SUBDIR
###################
ADD_SUBDIRECTORY("${PROJECT_SOURCE_DIR}/src")
####################
# LIBRARY
####################
ADD_LIBRARY(dschema
src/schema.c
)
####################
# COPY FILES
####################
#FOREACH(JSMODULE console util timers buffer path)
# FILE(READ "${RUFF_JS_MODULES_PATH}/${JSMODULE}/src/index.js" contents)
# FILE(WRITE "${CMAKE_BINARY_DIR}/buildin-js/${JSMODULE}.js" "${contents}")
#endforeach(JSMODULE)
####################
# EXECUTABLE
####################
ADD_EXECUTABLE(${PROJECT_NAME} src/main.c src/ruff.c ruff_native.h tools/compiler/ruff_compiler.c)
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Android")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} duv dschema duktape ${UV_LIB} ${SOCKLIB})
ELSE()
TARGET_LINK_LIBRARIES(${PROJECT_NAME} duv dschema duktape uv ${SOCKLIB})
ENDIF()
#ADD_CUSTOM_COMMAND(
# TARGET ruff
# POST_BUILD
# COMMAND node ${PROJECT_SOURCE_DIR}/tools/build-embed-js.js ${PROJECT_SOURCE_DIR}/modules/ruff_modules embed-js.bin
# COMMAND node ${PROJECT_SOURCE_DIR}/tools/append.js ruff embed-js.bin
#
####################
# INSTALL
####################
INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${PROJECT_BINARY_DIR}/bin)
#INSTALL(TARGETS ruff DESTINATION ${CMAKE_BINARY_DIR}/bin)