-
Notifications
You must be signed in to change notification settings - Fork 586
/
CMakeLists.txt
323 lines (249 loc) · 9.68 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
cmake_minimum_required (VERSION 2.8)
project (KBD-Audio)
set(CMAKE_EXPORT_COMPILE_COMMANDS "on")
# options
option(BUILD_EXPERIMENTAL "Build experimental tools" OFF)
option(USE_FINDSDL2 "Use the FindSDL2.cmake script" OFF)
option(KBD_AUDIO_SANITIZE_THREAD "kbd-audio: enable thread sanitizer" OFF)
option(KBD_AUDIO_SANITIZE_ADDRESS "kbd-audio: enable address sanitizer" OFF)
option(KBD_AUDIO_SANITIZE_UNDEFINED "kbd-audio: enable undefined sanitizer" OFF)
# sanitizers
if (KBD_AUDIO_SANITIZE_THREAD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
endif()
if (KBD_AUDIO_SANITIZE_ADDRESS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
if (KBD_AUDIO_SANITIZE_UNDEFINED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
# sdl2
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if (USE_FINDSDL2)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2")
endif()
# build types
include(cmake/GitVars.cmake)
include(cmake/BuildTypes.cmake)
configure_file(${CMAKE_SOURCE_DIR}/build-vars.h.in ${CMAKE_SOURCE_DIR}/build-vars.h @ONLY)
# warnings
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
endif()
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
if (EMSCRIPTEN)
set (CMAKE_CXX_FLAGS " \
-s USE_SDL=2 \
-s USE_PTHREADS=1 \
")
#-s DISABLE_EXCEPTION_CATCHING=1 \
set(CMAKE_EXE_LINKER_FLAGS " \
--bind \
--use-preload-cache \
-s ASSERTIONS=1 \
-s NO_EXIT_RUNTIME=0 \
-s PTHREAD_POOL_SIZE=16 \
-s INITIAL_MEMORY=536870912 \
")
elseif(MINGW)
find_package(PkgConfig REQUIRED)
pkg_search_module(SDL2 REQUIRED sdl2)
set(OPENGL_INCLUDE_DIR "")
set(OPENGL_LIBRARIES "opengl32")
else()
find_package(OpenGL REQUIRED)
find_package(SDL2)
find_package(FFTW)
endif()
find_package(Threads REQUIRED)
if (NOT USE_FINDSDL2 AND NOT SDL2_FOUND AND NOT EMSCRIPTEN)
message(WARNING "Unable to find SDL2 library. It is either not installed or CMake cannot find it."
" In the latter case, setting the USE_FINDSDL2 variable might help:\n"
" $ cmake -D USE_FINDSDL2 .."
)
message(FATAL_ERROR "Aborting")
endif()
if (NOT FFTW_FOUND)
message(WARNING "FFTW library not available. Some targets will not be built")
endif()
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
if (APPLE)
find_library(COREGRAPHICS_LIBRARY CoreGraphics )
find_library(COREFOUNDATION_LIBRARY CoreFoundation )
else (APPLE)
unset(COREGRAPHICS_LIBRARY)
unset(COREFOUNDATION_LIBRARY)
endif (APPLE)
include_directories(imgui)
include_directories(imgui/examples)
include_directories(imgui/examples/libs/gl3w)
include_directories(${SDL2_INCLUDE_DIRS})
include_directories(${OPENGL_INCLUDE_DIR})
add_library(Core STATIC
common.cpp
audio-logger.cpp
)
target_include_directories(Core PRIVATE
)
target_link_libraries(Core PRIVATE
${CMAKE_THREAD_LIBS_INIT}
${SDL2_LIBRARIES}
${COREFOUNDATION_LIBRARY}
)
# todo : this is ugly, what's the proper way?
if (MINGW)
target_link_libraries(Core PRIVATE stdc++)
endif()
if (EMSCRIPTEN)
add_library(Gui STATIC
common-gui.cpp
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_demo.cpp
imgui/imgui_widgets.cpp
imgui/examples/imgui_impl_sdl.cpp
imgui/examples/imgui_impl_opengl3.cpp
)
target_compile_definitions(Gui PUBLIC
IMGUI_USER_CONFIG="../imconfig-vtx32.h"
)
else()
add_library(Gui STATIC
common-gui.cpp
imgui/imgui.cpp
imgui/imgui_draw.cpp
imgui/imgui_demo.cpp
imgui/imgui_widgets.cpp
imgui/examples/libs/gl3w/GL/gl3w.c
imgui/examples/imgui_impl_sdl.cpp
imgui/examples/imgui_impl_opengl3.cpp
)
# force GL3W loader
target_compile_definitions(Gui PUBLIC
IMGUI_IMPL_OPENGL_LOADER_GL3W=1
IMGUI_USER_CONFIG="../imconfig-vtx32.h"
)
target_link_libraries(Gui PRIVATE
${CMAKE_DL_LIBS}
${SDL2_LIBRARIES}
${OPENGL_LIBRARIES}
${COREFOUNDATION_LIBRARY}
)
endif()
add_executable(keytap-gui keytap-gui.cpp)
target_link_libraries(keytap-gui PRIVATE Core Gui)
add_executable(keytap2-gui keytap2-gui.cpp subbreak2.cpp)
target_link_libraries(keytap2-gui PRIVATE Core Gui)
add_executable(keytap3-gui keytap3-gui.cpp subbreak3.cpp)
target_link_libraries(keytap3-gui PRIVATE Core Gui)
add_executable(keytap3-app keytap3-app.cpp subbreak3.cpp)
target_link_libraries(keytap3-app PRIVATE Core)
add_executable(view-full-gui view-full-gui.cpp)
target_link_libraries(view-full-gui PRIVATE Core Gui)
if (EMSCRIPTEN)
# view-full-gui
set(TARGET view-full-gui)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
-s TOTAL_MEMORY=536870912 \
-s LZ4=1 \
--preload-file ${PROJECT_SOURCE_DIR}/chal/record@/chal/record/ \ \
")
## keytap-gui
set(TARGET keytap-gui)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
-s TOTAL_MEMORY=536870912 \
-s FORCE_FILESYSTEM=1 \
")
# keytap2-gui
set(TARGET keytap2-gui)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
-s TOTAL_MEMORY=536870912 \
-s FORCE_FILESYSTEM=1 \
-s LZ4=1 \
--preload-file ${PROJECT_SOURCE_DIR}/data/@/data/ \
")
configure_file(${CMAKE_SOURCE_DIR}/index-${TARGET}-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/index.html @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/style.css ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/style.css @ONLY)
# keytap3-app
set(TARGET keytap3-app)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
-s FORCE_FILESYSTEM=1 \
-s LZ4=1 \
--preload-file ${PROJECT_SOURCE_DIR}/data/ggwords-6-gram.dat.binary@/data/ \
")
configure_file(${CMAKE_SOURCE_DIR}/index-${TARGET}-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/index.html @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/style.css ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/style.css @ONLY)
# keytap3-gui
set(TARGET keytap3-gui)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${TARGET})
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " \
-s TOTAL_MEMORY=536870912 \
-s FORCE_FILESYSTEM=1 \
-s LZ4=1 \
--preload-file ${PROJECT_SOURCE_DIR}/data/ggwords-6-gram.dat.binary@/data/ \
")
configure_file(${CMAKE_SOURCE_DIR}/index-${TARGET}-tmpl.html ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/index.html @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/style.css ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/style.css @ONLY)
endif()
if (NOT EMSCRIPTEN)
add_executable(key-detector key-detector.cpp)
target_link_libraries(key-detector PRIVATE Core)
add_executable(keytap keytap.cpp)
target_link_libraries(keytap PRIVATE Core)
add_executable(keytap2 keytap2.cpp)
target_link_libraries(keytap2 PRIVATE Core)
add_executable(keytap3 keytap3.cpp subbreak3.cpp)
target_link_libraries(keytap3 PRIVATE Core)
add_executable(play play.cpp)
target_link_libraries(play PRIVATE Core)
add_executable(play-full play-full.cpp)
target_link_libraries(play-full PRIVATE Core)
if (NOT MINGW)
# todo : need to find termios.h alternative for Windows
add_executable(record record.cpp)
target_link_libraries(record PRIVATE Core)
endif()
add_executable(record-full record-full.cpp)
target_link_libraries(record-full PRIVATE Core)
add_executable(view-gui view-gui.cpp)
target_link_libraries(view-gui PRIVATE Core Gui)
add_executable(compress-n-grams compress-n-grams.cpp subbreak3.cpp)
target_link_libraries(compress-n-grams PRIVATE Core)
#
## Experimental stuff
if (BUILD_EXPERIMENTAL)
if (FFTW_FOUND)
add_executable(key-average-gui key-average-gui.cpp)
target_include_directories(key-average-gui PRIVATE ${FFTW_INCLUDE_DIRS})
target_link_libraries(key-average-gui PRIVATE Core Gui ${FFTW_LIBRARIES})
else()
message(WARNING "Skipping 'key-average-gui' target because FFTW is not available")
endif()
add_executable(keytap3-multi keytap3-multi.cpp subbreak3.cpp)
target_link_libraries(keytap3-multi PRIVATE Core)
add_executable(guess-qp guess-qp.cpp)
target_link_libraries(guess-qp PRIVATE Core)
add_executable(guess-qp2 guess-qp2.cpp)
target_link_libraries(guess-qp2 PRIVATE Core)
add_executable(scale scale.cpp)
target_link_libraries(scale PRIVATE Core)
add_executable(subbreak subbreak.cpp)
target_link_libraries(subbreak PRIVATE Core)
add_executable(non-exact-subbreak non-exact-subbreak.cpp subbreak2.cpp)
target_link_libraries(non-exact-subbreak PRIVATE Core)
add_executable(non-exact-subbreak2 non-exact-subbreak2.cpp subbreak2.cpp)
target_link_libraries(non-exact-subbreak2 PRIVATE Core)
add_executable(generate-clusters generate-clusters.cpp subbreak2.cpp)
target_link_libraries(generate-clusters PRIVATE Core)
add_executable(test-subbreak3 test-subbreak3.cpp subbreak3.cpp)
target_link_libraries(test-subbreak3 PRIVATE Core)
endif()
endif()