forked from matanui159/ReplaySorcery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
193 lines (178 loc) · 6.16 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
cmake_minimum_required(VERSION 3.0)
project(ReplaySorcery VERSION 0.2.7)
include(CheckCCompilerFlag)
include(ExternalProject)
set(binary replay-sorcery)
set(sources
src/util/log.c
src/util/memory.c
src/util/buffer.c
src/util/circle.c
src/util/circle_static.c
src/util/path.c
src/util/string.c
src/util/frame.c
src/system/system.c
src/system/framerate.c
src/system/xlib.c
src/audio_input/audio.c
src/audio_input/audio_encoder.c
src/config.c
src/compress.c
src/mp4.c
src/output.c
src/main.c
)
set(headers
src/std.h
src/util/log.h
src/util/memory.h
src/util/buffer.h
src/util/circle.h
src/util/circle_static.h
src/util/path.h
src/util/string.h
src/util/frame.h
src/system/system.h
src/system/framerate.h
src/system/xlib.h
src/audio_input/audio.h
src/audio_input/audio_encoder.h
src/config.h
src/compress.h
src/output.h
)
add_executable(${binary} ${sources})
set_property(TARGET ${binary} PROPERTY C_STANDARD 99)
function(target_c_flag target flag var)
check_c_compiler_flag(${flag} ${var})
if (${var})
target_compile_options(${target} PRIVATE ${flag})
target_link_options(${target} PRIVATE ${flag})
endif()
endfunction()
# We always need debug info for libbacktrace
target_c_flag(${binary} -g HAVE_G_FLAG)
# Check for various warning flags
target_c_flag(${binary} -Wall HAVE_ALL_WARN)
target_c_flag(${binary} -Wextra HAVE_EXTRA_WARN)
target_c_flag(${binary} -Wpedantic HAVE_PEDANTIC_WARN)
target_c_flag(${binary} -Wconversion HAVE_CONVERSION_WARN)
target_c_flag(${binary} -Wstrict-prototypes HAVE_STRICT_PROTOTYPES_WARN)
target_c_flag(${binary} -Wmissing-prototypes HAVE_MISSING_PROTOTYPES_WARN)
# Used for CI. I do not like warnings in my code but during development its fine
option(RS_WARN_ERROR "Fail on compiler warning" OFF)
if (RS_WARN_ERROR)
target_c_flag(${binary} -Werror HAVE_WARN_ERROR)
endif()
option(RS_PROFILE "Enable code profiling" OFF)
if (RS_PROFILE)
target_c_flag(${binary} -pg HAVE_PG_FLAG)
endif()
# Pthreads
find_package(Threads REQUIRED)
target_link_libraries(${binary} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
# X11 with Xutil and MIT-SHM
find_package(X11 REQUIRED)
if (NOT X11_FOUND OR NOT X11_Xutil_FOUND OR NOT X11_XShm_FOUND)
message(SEND_ERROR "Failed to find X11 with util and shm extensions")
endif()
target_include_directories(${binary} SYSTEM PRIVATE ${X11_INCLUDE_DIRS})
target_link_libraries(${binary} PRIVATE ${X11_LIBRARIES})
# libbacktrace git submodule
ExternalProject_Add(backtrace
STEP_TARGETS backtrace
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/libbacktrace"
CONFIGURE_COMMAND <SOURCE_DIR>/configure
--prefix=<INSTALL_DIR>
CFLAGS=-O3
)
add_dependencies(${binary} backtrace)
ExternalProject_Get_Property(backtrace INSTALL_DIR)
target_include_directories(${binary} SYSTEM PRIVATE "${INSTALL_DIR}/include")
target_link_libraries(${binary} PRIVATE "${INSTALL_DIR}/lib/libbacktrace.a")
# libjpeg-turbo git submodule
ExternalProject_Add(jpeg
STEP_TARGETS jpeg
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/libjpeg-turbo"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_INSTALL_LIBDIR=<INSTALL_DIR>/lib
-DENABLE_SHARED=OFF
-DWITH_TURBOJPEG=OFF
-DCMAKE_C_FLAGS=-O3
)
add_dependencies(${binary} jpeg)
ExternalProject_Get_Property(jpeg INSTALL_DIR)
target_include_directories(${binary} SYSTEM PRIVATE "${INSTALL_DIR}/include")
target_link_libraries(${binary} PRIVATE "${INSTALL_DIR}/lib/libjpeg.a")
# x264 git submodule
ExternalProject_Add(x264
STEP_TARGETS x264
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/x264"
CONFIGURE_COMMAND <SOURCE_DIR>/configure
--prefix=<INSTALL_DIR>
--enable-static
--disable-cli
--disable-opencl
--extra-cflags=-O3
)
add_dependencies(${binary} x264)
ExternalProject_Get_Property(x264 INSTALL_DIR)
target_include_directories(${binary} SYSTEM PRIVATE "${INSTALL_DIR}/include")
target_link_libraries(${binary} PRIVATE "${INSTALL_DIR}/lib/libx264.a" m)
# sdl2 git submodule
ExternalProject_Add(sdl2
STEP_TARGETS sdl2
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/sdl2"
CONFIGURE_COMMAND <SOURCE_DIR>/configure
--prefix=<INSTALL_DIR>
--enable-static=yes
--enable-timers=yes
--enable-audio=yes
--enable-shared=no
--enable-video=no
--enable-render=no
--enable-joystick=no
--enable-haptic=no
--enable-sensor=no
--enable-power=no
--enable-filesystem=no
--enable-file=no
)
add_dependencies(${binary} sdl2)
ExternalProject_Get_Property(sdl2 INSTALL_DIR)
target_include_directories(${binary} SYSTEM PRIVATE "${INSTALL_DIR}/include")
target_link_libraries(${binary} PRIVATE "${INSTALL_DIR}/lib/libSDL2.a" dl)
# fdk-aac git submodule
ExternalProject_Add(fdk-aac
STEP_TARGETS fdk-aac
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dep/fdk-aac"
CONFIGURE_COMMAND cd <SOURCE_DIR> && ./autogen.sh && cd <BINARY_DIR> && <SOURCE_DIR>/configure
--prefix=<INSTALL_DIR>
--enable-static=yes
--enable-shared=no
)
add_dependencies(${binary} fdk-aac)
ExternalProject_Get_Property(fdk-aac INSTALL_DIR)
target_include_directories(${binary} SYSTEM PRIVATE "${INSTALL_DIR}/include")
target_link_libraries(${binary} PRIVATE "${INSTALL_DIR}/lib/libfdk-aac.a")
# Minimp4 header-only git submodule
target_include_directories(${binary} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dep/minimp4")
set_property(SOURCE src/mp4.c PROPERTY COMPILE_FLAGS -w)
# Clang format target to make formatting easy
add_custom_target(clang-format
COMMAND clang-format -i ${sources} ${headers}
SOURCES ${sources}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
# Installation
install(TARGETS ${binary} DESTINATION bin)
set(service replay-sorcery.service)
# We cannot use CMAKE_INSTALL_PREFIX since the default is /usr/local
set(RS_SYSTEMD_DIR /usr/lib/systemd/user CACHE STRING "Where to install the systemd service")
configure_file(${service}.in ${service})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${service}" DESTINATION "${RS_SYSTEMD_DIR}")
# Similar for here since we need to use the XDG path /etc/xdg
set(RS_CONFIG_DIR /etc/xdg CACHE STRING "Where to install the default config")
install(FILES replay-sorcery.default.conf DESTINATION "${RS_CONFIG_DIR}" RENAME replay-sorcery.conf)