-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
177 lines (156 loc) · 5.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
project(CodeGeneration)
set(COMPILE_FLAGS)
if(MSVC)
set(COMPILE_FLAGS
/EHsc
/Zc:__cplusplus
/Zc:preprocessor
/utf-8
)
endif()
option(USE_EXTENSIVE_WARNINGS "Enable additional compiler warnings" ON)
if(MSVC)
string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(WARN_FLAGS /W4 /permissive-)
else()
set(WARN_FLAGS -Wall -Wextra -Wpedantic)
endif()
if(USE_EXTENSIVE_WARNINGS)
if(MSVC)
list(APPEND WARN_FLAGS
/w14242 # possible loss of data: conversion from `type1` to `type2`
/w14254 # possible loss of data: conversion from `type1:field_bits`
# to `type2:field_bits`
/w14263 # member function does not override any base class virtual
# member function
/w14265 # class has virtual functions, but destructor is not
# virtual; instances of this class may not be destructed
# correctly
/w14287 # unsigned/negative constant mismatch
/we4289 # loop control variable declared in the for-loop is used
# outside the for-loop scope
/w14296 # expression is always [true | false]
/w14311 # pointer truncation from `type1` to `type2`
/w14545 # expression before comma evaluates to a function which is
# missing an argument list
/w14546 # function call before comma missing argument list
/w14547 # operator before comma has no effect; expected operator
# with side-effect
/w14549 # operator before comma has no effect; did you intend
# 'operator'?
/w14555 # expression has no effect; expected expression with
# side-effect
/w14619 # pragma warning: there is no warning number `number`
/w14640 # thread un-safe static member initialization
/w14826 # conversion from 'type1' to 'type_2' is sign-extended which
# may cause unexpected runtime behavior
/w14928 # illegal copy-initialization; more than one user-defined
# conversion has been implicitly applied
)
else()
list(APPEND WARN_FLAGS
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Wunused
-Woverloaded-virtual
-Wconversion
-Wsign-conversion
-Wnull-dereference
-Wformat=2
-Wfloat-equal
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND WARN_FLAGS
-Wshadow=compatible-local
-Wduplicated-cond
-Wduplicated-branches
-Wlogical-op
-Wuseless-cast
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
list(APPEND WARN_FLAGS
-Wshadow-uncaptured-local
-Wshorten-64-to-32
)
endif()
endif()
if(WIN32)
set(ADDITIONAL_COMPILE_DEFINITIONS
WIN32_LEAN_AND_MEAN
NOMINMAX
)
endif()
option(USE_ADDRESS_SANITIZER "Enable AddressSanitizer runtime checks" ON)
if(CMAKE_BUILD_TYPE_UPPER STREQUAL "RELEASE")
set(USE_ADDRESS_SANITIZER OFF)
endif()
if(WIN32 AND NOT MSVC AND USE_ADDRESS_SANITIZER)
message(WARNING "USE_ADDRESS_SANITIZER set but not yet supported on Windows non-MSVC compilers. Disabling.")
set(USE_ADDRESS_SANITIZER OFF)
endif()
if(USE_ADDRESS_SANITIZER)
if(MSVC)
# Shared CRT (/MDd) requires clang_rt.asan_* libraries to be in PATH. Setting static CRT as a workaround.
set(MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
set(ADDRESS_SANITIZER_FLAGS
/fsanitize=address
)
else()
set(ADDRESS_SANITIZER_FLAGS
-fsanitize=address
)
set(ADDRESS_SANITIZER_LINK_FLAGS ${ADDRESS_SANITIZER_FLAGS})
endif()
endif()
find_package(fmt CONFIG REQUIRED)
add_executable(codegen
src/main.cpp
src/ast/tree_printer.cpp
src/ast/visitor.cpp
src/cgn/generator.cpp
src/hir/generator.cpp
src/hir/printer.cpp
)
set_target_properties(codegen PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED TRUE
CXX_EXTENSIONS FALSE
)
set(VS_STARTUP_PROJECT codegen)
target_include_directories(codegen
PRIVATE
src
)
target_compile_definitions(codegen
PRIVATE
${ADDITIONAL_COMPILE_DEFINITIONS}
)
target_link_libraries(codegen
PRIVATE
fmt::fmt-header-only
)
target_compile_options(codegen
PRIVATE
${COMPILE_FLAGS}
${WARN_FLAGS}
$<$<NOT:$<CONFIG:Release>>:${ADDRESS_SANITIZER_FLAGS}>
)
target_link_options(codegen
PRIVATE
$<$<NOT:$<CONFIG:Release>>:${ADDRESS_SANITIZER_LINK_FLAGS}>
)
if(MSVC AND USE_ADDRESS_SANITIZER)
set_target_properties(codegen PROPERTIES
MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY}
)
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED)
set_target_properties(codegen PROPERTIES
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
)
endif()