-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
147 lines (130 loc) · 4.54 KB
/
CMakeLists.txt
File metadata and controls
147 lines (130 loc) · 4.54 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
cmake_minimum_required(VERSION 3.12)
set(CMAKE_C_COMPILER_NAMES clang)
set(CMAKE_CXX_COMPILER_NAMES clang++)
project(charly-vm)
# create build directories
file(MAKE_DIRECTORY cmake-build-debug cmake-build-release)
# osx check
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message("-- Detected apple installation")
add_compile_definitions(APPLE)
set(APPLE TRUE)
execute_process(COMMAND xcrun --show-sdk-path OUTPUT_VARIABLE OSXSDKPATH)
include_directories(BEFORE SYSTEM ${OSXSDKPATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include")
endif ()
# --- Detect Arch / Arch-based (EndeavourOS etc.) ---
set(IS_ARCH FALSE)
if (UNIX AND EXISTS "/etc/os-release")
file(READ "/etc/os-release" OS_RELEASE_RAW)
string(TOLOWER "${OS_RELEASE_RAW}" OS_RELEASE)
if (OS_RELEASE MATCHES "id=arch"
OR OS_RELEASE MATCHES "id=\"arch\""
OR OS_RELEASE MATCHES "id_like=.*arch.*")
set(IS_ARCH TRUE)
endif ()
endif ()
# --- Detect WSL (Windows Subsystem for Linux) ---
set(IS_WSL FALSE)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND EXISTS "/proc/version")
file(READ "/proc/version" PROC_VERSION)
if (PROC_VERSION MATCHES "Microsoft" OR PROC_VERSION MATCHES "WSL")
set(IS_WSL TRUE)
endif ()
endif ()
# --- Only build tests if NOT Arch and NOT WSL ---
if (NOT IS_ARCH AND NOT IS_WSL)
option(BUILD_TESTS "Build tests" ON)
else ()
set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
endif ()
add_compile_options(-Wno-nontrivial-memaccess -Wno-missing-field-initializers -Wno-missing-field-initializers)
# include directories
include_directories(src)
include_directories(include)
include_directories(libs)
# explicitly enable debug symbols in debug builds
set(CMAKE_CXX_FLAGS_DEBUG "-g")
# main executable
add_subdirectory(src)
add_executable(charly src/main.cpp)
target_compile_features(charly PRIVATE cxx_std_20)
target_link_libraries(charly libcharly)
target_compile_options(charly PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Wno-vla-extension
-Wno-c++20-designator
-Wno-missing-field-initializers
-Wno-gnu-zero-variadic-macro-arguments
-Wno-gnu-label-as-value
-Wno-c99-extensions
-Wno-register
-Wno-extra-semi
-Wno-shadow
-ftemplate-backtrace-limit=8
-mllvm -align-all-functions=3
)
# enable link-time-optimization for release builds
if (CMAKE_BUILD_TYPE MATCHES Release)
message("-- Enabling LTO for target 'charly'")
target_compile_options(charly PRIVATE -flto -O3)
endif ()
# install to global folder
install(TARGETS charly RUNTIME DESTINATION bin)
if (BUILD_TESTS)
# unit tests
add_subdirectory(libs/catch2)
file(GLOB tests_SRC
"test/runtime/core/compiler/diagnostic.cpp"
"test/runtime/core/compiler/module.cpp"
"test/runtime/core/compiler/parser.cpp"
"test/runtime/core/compiler/pass.cpp"
"test/runtime/core/compiler/semantic.cpp"
"test/runtime/utils/buffer.cpp"
"test/runtime/utils/cast.cpp"
"test/runtime/utils/cast.cpp"
"test/runtime/utils/random_device.cpp"
"test/runtime/utils/wait_flag.cpp"
"test/runtime/value.cpp"
)
add_executable(tests ${tests_SRC})
target_compile_features(tests PRIVATE cxx_std_20)
target_link_libraries(tests Catch2::Catch2WithMain)
target_link_libraries(tests libcharly)
target_compile_definitions(tests PUBLIC CATCH_CONFIG_PREFIX_ALL)
target_compile_options(tests PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror
-Wno-vla-extension
-Wno-c++20-designator
-Wno-missing-field-initializers
-Wno-gnu-zero-variadic-macro-arguments
-Wno-gnu-label-as-value
-Wno-c99-extensions
-Wno-register
-Wno-extra-semi
-Wno-shadow
-ftemplate-backtrace-limit=8
-mllvm -align-all-functions=3
)
# enable link-time-optimization for release builds
if (CMAKE_BUILD_TYPE MATCHES Release)
message("-- Enabling LTO for target 'tests'")
target_compile_options(tests PRIVATE -flto -O3)
endif ()
if (APPLE)
set_target_properties(tests PROPERTIES LINK_FLAGS -fuse-ld=ld)
else ()
set_target_properties(tests PROPERTIES LINK_FLAGS -fuse-ld=lld)
endif ()
endif ()
if (APPLE)
set_target_properties(charly PROPERTIES LINK_FLAGS -fuse-ld=ld)
else ()
set_target_properties(charly PROPERTIES LINK_FLAGS -fuse-ld=lld)
endif ()