-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
152 lines (142 loc) · 6.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
152 lines (142 loc) · 6.2 KB
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
cmake_minimum_required(VERSION 3.20)
project(Zephyr LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ─── Build options ────────────────────────────────────────────────────────────
option(ZEPHYR_BUILD_CLI "Build zephyr_cli executable" ON)
option(ZEPHYR_BUILD_TESTS "Build zephyr_tests executable" ON)
option(ZEPHYR_BUILD_BENCH "Build zephyr_bench executable" ON)
option(ZEPHYR_BUILD_SAMPLES "Build sample executables" ON)
option(ZEPHYR_ENABLE_PGO "Enable PGO instrumentation (MSVC /GL+/LTCG)" OFF)
# ─── ZephyrRuntime (static library) ──────────────────────────────────────────
set(ZEPHYR_RUNTIME_SOURCES
src/zephyr.cpp
src/zephyr_parser.cpp
src/zephyr_gc_impl.cpp
)
# zephyr_vm_dispatch.c uses computed goto (GCC/Clang extension), not supported by MSVC
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
list(APPEND ZEPHYR_RUNTIME_SOURCES src/zephyr_vm_dispatch.c)
endif()
add_library(ZephyrRuntime STATIC ${ZEPHYR_RUNTIME_SOURCES})
target_include_directories(ZephyrRuntime
PUBLIC include
PRIVATE src
)
if(MSVC)
target_compile_options(ZephyrRuntime PRIVATE
/W3 /permissive- /bigobj /utf-8
$<$<CONFIG:Release>:/O2 /GL>
$<$<CONFIG:Debug>:/Od /RTC1>
)
target_link_options(ZephyrRuntime INTERFACE
$<$<CONFIG:Release>:/LTCG>
)
if(ZEPHYR_ENABLE_PGO)
target_compile_options(ZephyrRuntime PRIVATE /GL)
target_link_options(ZephyrRuntime INTERFACE /LTCG:PGI)
endif()
else()
target_compile_options(ZephyrRuntime PRIVATE
-Wall -Wextra
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Debug>:-O0 -g>
)
endif()
# ─── zephyr_cli ──────────────────────────────────────────────────────────────
if(ZEPHYR_BUILD_CLI)
add_executable(zephyr_cli
cli/main.cpp
cli/lsp_server.cpp
cli/dap_server.cpp
bench/bench_runner.cpp
)
target_link_libraries(zephyr_cli PRIVATE ZephyrRuntime)
target_include_directories(zephyr_cli PRIVATE include bench)
if(MSVC)
target_compile_options(zephyr_cli PRIVATE /W3 /permissive- /bigobj
$<$<CONFIG:Release>:/O2 /GL>)
target_link_options(zephyr_cli PRIVATE $<$<CONFIG:Release>:/LTCG>)
endif()
set_target_properties(zephyr_cli PROPERTIES OUTPUT_NAME "zephyr")
endif()
# ─── zephyr_tests ─────────────────────────────────────────────────────────────
if(ZEPHYR_BUILD_TESTS)
add_executable(zephyr_tests
tests/test_main.cpp
tests/test_lexer.cpp
tests/test_compiler.cpp
tests/test_vm.cpp
tests/test_gc.cpp
tests/test_host.cpp
tests/test_perf.cpp
tests/test_corpus.cpp
)
target_link_libraries(zephyr_tests PRIVATE ZephyrRuntime)
target_include_directories(zephyr_tests PRIVATE include tests bench)
if(MSVC)
target_compile_options(zephyr_tests PRIVATE /W3 /permissive- /bigobj
$<$<CONFIG:Release>:/O2>)
endif()
# Copy corpus to build dir so tests can find it
add_custom_command(TARGET zephyr_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/tests/corpus"
"$<TARGET_FILE_DIR:zephyr_tests>/corpus"
COMMENT "Copying corpus to test output directory"
)
endif()
# ─── zephyr_bench ────────────────────────────────────────────────────────────
if(ZEPHYR_BUILD_BENCH)
add_executable(zephyr_bench
bench/main.cpp
bench/bench_runner.cpp
)
target_link_libraries(zephyr_bench PRIVATE ZephyrRuntime)
target_include_directories(zephyr_bench PRIVATE include bench)
if(MSVC)
target_compile_options(zephyr_bench PRIVATE /W3 /permissive- /bigobj
$<$<CONFIG:Release>:/O2 /GL>)
target_link_options(zephyr_bench PRIVATE $<$<CONFIG:Release>:/LTCG>)
else()
target_compile_options(zephyr_bench PRIVATE
-Wall -Wextra
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Debug>:-O0 -g>)
endif()
# Copy bench scripts to build dir
add_custom_command(TARGET zephyr_bench POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_SOURCE_DIR}/bench/scripts"
"$<TARGET_FILE_DIR:zephyr_bench>/bench/scripts"
COMMENT "Copying bench scripts to output directory"
)
endif()
# ─── zephyr_engine_sample ─────────────────────────────────────────────────────
if(ZEPHYR_BUILD_SAMPLES)
add_executable(zephyr_engine_sample
samples/engine_sample/main.cpp
)
target_link_libraries(zephyr_engine_sample PRIVATE ZephyrRuntime)
target_include_directories(zephyr_engine_sample PRIVATE include)
if(MSVC)
target_compile_options(zephyr_engine_sample PRIVATE /W3 /permissive- /bigobj
$<$<CONFIG:Release>:/O2 /GL>)
target_link_options(zephyr_engine_sample PRIVATE $<$<CONFIG:Release>:/LTCG>)
else()
target_compile_options(zephyr_engine_sample PRIVATE
-Wall -Wextra
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Debug>:-O0 -g>)
endif()
set_target_properties(zephyr_engine_sample PROPERTIES OUTPUT_NAME "zephyr_engine_sample")
endif()
# ─── Install ──────────────────────────────────────────────────────────────────
install(TARGETS ZephyrRuntime
ARCHIVE DESTINATION lib
)
install(DIRECTORY include/zephyr DESTINATION include)
if(ZEPHYR_BUILD_CLI)
install(TARGETS zephyr_cli RUNTIME DESTINATION bin)
endif()