forked from bellard/quickjs
-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
71 lines (58 loc) · 2.11 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
cmake_minimum_required(VERSION 3.9.4)
project(QUICKJS)
set(C_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(MI_OVERRIDE OFF)
add_definitions(-DENABLE_MI_MALLOC)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if( supported )
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/vendor/mimalloc/include)
add_subdirectory(src)
add_subdirectory(vendor/mimalloc)
set(COMPILE_FLAGS -Wall -MMD -Wno-array-bounds -Wno-format-truncation)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(MI_ASAN ON)
set(COMPILE_FLAGS ${COMPILE_FLAGS} -g -fsanitize=address)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(COMPILE_FLAGS ${COMPILE_FLAGS} -O3)
endif()
if (UNIX)
set(LINK_LIBRARIES m pthread dl)
elseif(WIN32)
set(LINK_LIBRARIES m pthread)
endif()
add_compile_options(${COMPILE_FLAGS})
add_compile_definitions(
_GNU_SOURCE
CONFIG_BIGNUM
CONFIG_VERSION=${QUICKJS_VERSION}
)
set(QJSC_CONFIG -DCONFIG_PREFIX="/usr/local" -DCONFIG_LTO)
set(QJSC_EXE "${EXECUTABLE_OUTPUT_PATH}/qjsc")
if(UNIX OR WIN32)
set(QJS_CONFIG ${QJSC_CONFIG} -DCONFIG_CC="gcc")
else()
set(QJS_CONFIG ${QJSC_CONFIG} -DCONFIG_CC="clang")
endif()
if(WIN32)
set(QJSC_EXE "${QJSC_EXE}.exe")
endif()
add_executable(qjsc qjsc.c quickjs-libc.c)
target_link_libraries(qjsc quickjs ${LINK_LIBRARIES} mimalloc-static)
target_compile_definitions(qjsc PUBLIC ${QJSC_CONFIG})
add_custom_command(
TARGET qjsc POST_BUILD
COMMAND ${QJSC_EXE} -c -o ${PROJECT_SOURCE_DIR}/repl.c -m ${PROJECT_SOURCE_DIR}/repl.js
COMMAND ${QJSC_EXE} -fbignum -c -o ${PROJECT_SOURCE_DIR}/qjscalc.c ${PROJECT_SOURCE_DIR}/qjscalc.js
)
add_executable(qjs qjs.c quickjs-libc.c repl.c qjscalc.c)
target_link_libraries(qjs quickjs ${LINK_LIBRARIES} mimalloc-static)
add_executable(run-test262 run-test262.c quickjs-libc.c)
target_link_libraries(run-test262 quickjs ${LINK_LIBRARIES} mimalloc-static)