-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
168 lines (143 loc) · 5.3 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
cmake_minimum_required(VERSION 3.27)
project(xkbdisplay VERSION 0.1.0 LANGUAGES CXX)
## ============================================================================
## Global CMake Variables.
## ============================================================================
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## ============================================================================
## Global compiler options.
## ============================================================================
## Turn on diagnostics colours.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()
## Use mold as the default linker, if it exists.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
find_program(MOLD_LINKER "mold")
if (MOLD_LINKER)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fuse-ld=mold)
endif()
add_link_options(-fuse-ld=mold)
endif()
endif()
## ============================================================================
## Compiler options.
## ============================================================================
add_library(options INTERFACE)
## Flags for Clang and GCC.
target_compile_options(options INTERFACE
## Warnings.
-Wall -Wextra # Enable ‘all’ warnings.
-Wundef # Invalid #undef or undefined macro in #if.
-Wcast-align # Casting that changes alignment.
-Wconversion # Implicit conversions.
-Wsign-conversion # Implicit sign conversions.
-Wformat=2 # Stricter format checking.
## Disabled warnings.
-Wno-unused-function
-Wno-unused-local-typedefs
## NULL Errors.
-Werror=nonnull # Passing NULL to nonnull parameter.
## Memory Errors.
-Werror=address # Suspicious use of addresses.
-Werror=init-self # Initialization of a variable with itself.
-Werror=uninitialized
## Return type.
-Werror=return-type
-Wmissing-noreturn
## C/C++.
-Werror=implicit-fallthrough
-Werror=pointer-arith # Disallow void* and function pointer arithmetic.
-Werror=string-compare # Nonsensical string comparisons.
-Werror=switch # Missing switch cases.
# -Werror=switch-enum # Switch on enum (even if there is a default case).
-Werror=write-strings # Strings in C should be const char*.
## C++.
-Werror=missing-field-initializers
-Werror=non-virtual-dtor
-Werror=pessimizing-move
)
## Additional flags for GCC.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(options INTERFACE
-Wlogical-op # Duplicate or unintended logical operators.
-Werror=invalid-memory-model # For atomics.
-Werror=maybe-uninitialized
-Werror=missing-requires
-Werror=return-local-addr
)
endif()
## Additional flags for Clang.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(options INTERFACE
-Werror=dangling
-Werror=return-stack-address
)
endif()
## Address Sanitiser.
if (ENABLE_ASAN)
target_compile_options(options INTERFACE -fsanitize=address)
target_link_options(options INTERFACE -fsanitize=address)
endif()
## Debug/Release flags.
target_compile_options(options INTERFACE
$<$<CONFIG:DEBUG>:-O0 -g3 -ggdb3>
$<$<CONFIG:RELEASE>:-O3 -march=native>
)
target_link_options(options INTERFACE
$<$<CONFIG:DEBUG>:-O0 -g3 -ggdb3 -rdynamic>
$<$<CONFIG:RELEASE>:-O3 -march=native>
)
## ============================================================================
## Dependencies.
## ============================================================================
include(FetchContent)
FetchContent_Declare(clopts
GIT_REPOSITORY https://github.com/Sirraide/clopts
GIT_TAG v2.2.1
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/libs/clopts"
)
FetchContent_Declare(stream
GIT_REPOSITORY https://github.com/Sirraide/libstream
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/libs/stream"
)
FetchContent_Declare(
libassert
GIT_REPOSITORY https://github.com/jeremy-rifkin/libassert.git
GIT_TAG v2.0.2
)
FetchContent_MakeAvailable(libassert)
FetchContent_MakeAvailable(clopts)
FetchContent_MakeAvailable(stream)
target_include_directories(options INTERFACE
"${clopts_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/include"
/usr/include/freetype2/ # Required by Xft.
)
target_link_libraries(options INTERFACE
libstream
libassert::assert
X11 Xft xkbcommon
)
## ============================================================================
## Executables and libraries.
## ============================================================================
add_library(xkb++ STATIC
src/diacritics.cc
src/layout.cc
src/main.cc
src/utils.cc
)
file(GLOB_RECURSE headers include/*.hh)
target_sources(xkb++ PUBLIC FILE_SET HEADERS FILES ${headers})
add_executable(xkbdisplay src/xkbdisplay.cc)
add_executable(xkbgen src/xkbgen.cc)
target_link_libraries(xkb++ PRIVATE options)
target_link_libraries(xkbdisplay PRIVATE options xkb++)
target_link_libraries(xkbgen PRIVATE options xkb++)