-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
108 lines (88 loc) · 3.96 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
cmake_minimum_required(VERSION 3.10)
project(lit C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include_directories(include/)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_C_FLAGS "-no-pie -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-strict-aliasing -Wno-unused-result -Wno-sequence-point ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-g ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "-O3 ${CMAKE_C_FLAGS_RELEASE}")
option(LIT_DEFINE_TEST "Build code for testing (disables debug output)" OFF)
option(LIT_STANDALONE "Build in standalone mode" OFF)
option(LIT_BUILD_BINARY "Build the binary" ON)
if (EMSCRIPTEN)
set(CMAKE_AR "emcc")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <LINK_FLAGS> <OBJECTS>")
ADD_DEFINITIONS(-DEMSCRIPTEN)
endif()
if (DEFINE_TEST)
message("Adding Testing flag...")
add_definitions(-DTESTING)
else()
message("Adding release flag...")
add_definitions(-DRELEASE)
endif(DEFINE_TEST)
if (COVERAGE)
message("Adding coverage flag...")
set(CMAKE_C_FLAGS "--coverage ${CMAKE_C_FLAGS}")
endif(COVERAGE)
add_library(lit STATIC
src/lit/mem/lit_mem.c src/lit/state/lit_state.c src/lit/vm/lit_chunk.c
src/lit/debug/lit_debug.c src/lit/vm/lit_value.c src/lit/vm/lit_vm.c src/lit/scanner/lit_scanner.c
src/lit/parser/lit_parser.c src/lit/parser/lit_ast.c src/lit/emitter/lit_emitter.c src/lit/vm/lit_object.c
src/lit/util/lit_table.c src/lit/util/lit_array.c src/lit/util/lit_fs.c src/lit/api/lit_api.c src/lit/api/lit_calls.c
src/lit/std/lit_core.c src/lit/std/lit_math.c src/lit/std/lit_file.c src/lit/std/lit_gc.c src/lit/parser/lit_error.c
src/lit/optimizer/lit_optimizer.c src/lit/util/lit_utf.c src/lit/preprocessor/lit_preprocessor.c
src/lit/event/lit_event.c
src/lit/std/lit_json.c src/lit/std/lit_time.c src/lit/std/lit_network.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lit/std/compiled/lit_promise.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lit/std/compiled/lit_http.c)
add_custom_command(
OUTPUT src/lit/std/compiled/lit_promise.c
COMMAND embedfile lit_promise include/lit/std/raw/promise.lit
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS include/lit/std/raw/promise.lit)
add_custom_command(
OUTPUT src/lit/std/compiled/lit_http.c
COMMAND embedfile lit_http include/lit/std/raw/http.lit
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS include/lit/std/raw/http.lit)
if (UNIX)
target_link_libraries(lit LINK_PUBLIC dl m)
elseif (WIN32)
target_link_libraries(lit LINK_PUBLIC wsock32 ws2_32 m)
endif()
if (LIT_BUILD_ANDROID)
set_target_properties(lit PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist/${CMAKE_ANDROID_ARCH_ABI}")
else()
set_target_properties(lit PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
endif()
add_subdirectory(util/embed-file/)
install(TARGETS lit DESTINATION lib)
install(DIRECTORY include/lit/ DESTINATION include/lit)
if (LIT_BUILD_BINARY)
if (STANDALONE)
message("Adding standalone flag...")
add_executable(litc src/lit/standalone/main.c bytecode.c)
else()
message("Building regular binary...")
add_executable(litc src/lit/cli/main.c)
endif()
target_link_libraries(litc lit)
if(NOT EMSCRIPTEN AND NOT STANDALONE AND UNIX)
target_link_libraries(litc readline)
endif()
if (LIT_BUILD_ANDROID)
set_target_properties(litc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist/${CMAKE_ANDROID_ARCH_ABI}")
set_target_properties(litc PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist/${CMAKE_ANDROID_ARCH_ABI}")
else()
set_target_properties(litc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
set_target_properties(litc PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/dist")
endif()
set_target_properties(litc PROPERTIES OUTPUT_NAME "lit")
install(TARGETS litc DESTINATION bin)
endif()