-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
297 lines (278 loc) · 11.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
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
cmake_minimum_required(VERSION 3.18)
project(vis_avs VERSION 2.82)
include(CheckIncludeFiles)
include(CheckLinkerFlag)
include(ExternalProject)
file(GLOB SRC_FILES_EEL2
avs/3rdparty/WDL-EEL2/eel2/nseel-*.c
)
file(GLOB SRC_FILES_AVS_COMMON
avs/vis_avs/audio.cpp
avs/vis_avs/avs*.cpp
avs/vis_avs/blend.cpp
avs/vis_avs/e_*.cpp
avs/vis_avs/effect*.cpp
avs/vis_avs/*.c
avs/vis_avs/files.cpp
avs/vis_avs/handles.cpp
avs/vis_avs/image.cpp
avs/vis_avs/instance.cpp
avs/vis_avs/linedraw.cpp
avs/vis_avs/matrix.cpp
avs/vis_avs/preset_json_schema.cpp
avs/vis_avs/render_context.cpp
# avs/vis_avs/r_text.cpp
avs/vis_avs/r_transition.cpp
avs/vis_avs/text_win32.cpp
avs/vis_avs/video.cpp
avs/vis_avs/video_libav.cpp
avs/platform.c
avs/uuid.cpp
avs/3rdparty/md_fft.cpp
)
file(GLOB SRC_FILES_VIS_AVS
avs/vis_avs/g_*.cpp
avs/vis_avs/bpm.cpp
avs/vis_avs/cfgwin.cpp
avs/vis_avs/draw.cpp
avs/vis_avs/main.cpp
avs/vis_avs/render.cpp
avs/vis_avs/undo.cpp
avs/vis_avs/util.cpp
avs/vis_avs/wnd.cpp
avs/vis_avs/*.rc
)
if(WIN32)
list(APPEND SRC_FILES_AVS_COMMON
avs/platform_win32.c
avs/vis_avs/audio_in_windows_wasapi.cpp
)
elseif(LINUX)
list(APPEND SRC_FILES_AVS_COMMON
avs/platform_linux.c
avs/vis_avs/audio_in_linux_pipewire.cpp
avs/vis_avs/audio_libpipewire.cpp
avs/3rdparty/pevents.cpp
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(
/W4 # Warning level 4 (maximum)
/wd4458 # Ignore warning about overriding member with local
# parameter. Setters should be able to have a parameter
# named exactly the same as the member it's setting. The
# code style advocates for `this->` everywhere anyway.
/wd4244 # Ignore warning about type conversions with data loss.
# They are simply too many at the moment and obscure other
# warnings. TODO[cleanup]: Reenable and fix warnings.
/wd5051 # Ignore warning that [[fallthrough]] is ignored on C++<17.
# It's still useful for readability.
/MP # Multithreaded compilation
/std:c++14 # Pin to C++14 features
/Zc:__cplusplus # Define the actual C++ standard in __cplusplus, instead of
# a backwards-compatible "199711L".
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")
message(SEND_ERROR
"need GCC version >=8, for naked-function support for x86 target")
endif()
add_compile_options(
-g
-O2
-m32 # Compile for 32-bit x86.
-masm=intel # Use Intel instead of AT&T inline assembly syntax.
-march=native # Convolution-Filter uses inlined mmintrin.h functions, and
# a pentium4 arch seems to be roughly the minimum for that.
-fvisibility=hidden # Hide all symbols by default, only export API symbols.
# -flto # Link-time optimization. No performance gain, but halves
# binary size.
# -fprofile-generate # Profile-guided optimization, pass 1
# -fprofile-use # Profile-guided optimization, pass 2
-Wall -Wextra
-Wno-write-strings # Don't complain when converting string literals to char*.
# -fsanitize=address # Detect memory leaks & stack corruption at runtime.
# Doesn't work with some inline asm at the moment.
# -save-temps # Save intermediate assembly files created during
# compilation for debugging. The .s files will be output
# into the base build directory.
)
# C++-specific flags
set(AVS_CXX_COMPILER_FLAGS
-std=c++14 # Pin to C++14 features
)
# (CMake generator expressions cannot be multiline, hence the AVS_CXX_COMPILE_FLAGS
# variable in a foreach workaround.)
foreach(FLAG ${AVS_CXX_COMPILER_FLAGS})
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${FLAG}>)
endforeach()
else() # TODO: Clang option
message(SEND_ERROR "unsupported compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
add_compile_definitions(
WA2_EMBED # Enabling this shows the window decorations for AVS, at the
# cost of making the window resize a bit choppier. (Winamp2
# restricted window dimensions to certain multiples).
# NO_MMX # Use (usually slower) C equivalents for MMX assembly.
# (Initially enabled for quick porting but should be
# removed, now that all MMX sections are ported.)
WFMO # Enable `WaitForMultipleObjects()` in pevents.cpp.
_USE_MATH_DEFINES # Let math.h declare M_PI.
SIMD_MODE_X86_SSE # Use SSE & SSSE3 SIMD optimizations where possible.
# Plain C alternatives are provided and used if unset.
)
set(CMAKE_SHARED_LIBRARY_PREFIX "") # Remove "lib" prefix from output to get original
# filename "vis_avs.dll".
add_library(avs_eel OBJECT ${SRC_FILES_EEL2})
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(avs_eel PRIVATE -masm=att)
endif()
add_library(avs_common OBJECT ${SRC_FILES_AVS_COMMON})
add_library(libavs SHARED
$<TARGET_OBJECTS:avs_eel>
$<TARGET_OBJECTS:avs_common>
)
check_include_files(
"libavcodec/avcodec.h;libavformat/avformat.h;libswscale/swscale.h"
HAVE_FFMPEG
)
if(NOT HAVE_FFMPEG OR NO_FFMPEG)
add_compile_definitions(NO_FFMPEG)
message(WARNING "FFmpeg headers not found. Building without video support!")
endif()
if(WIN32)
target_sources(libavs PRIVATE libavs.def) # The function export list.
add_compile_definitions(
_WIN32_WINNT=_WIN32_WINNT_VISTA # Minimum WinNT version (needed for
# GetTickCount64()).
NOMINMAX # Don't define min()/max() in windows.h on
# MSVC. Use our own functions everywhere.
)
add_library(vis_avs SHARED
$<TARGET_OBJECTS:avs_eel>
$<TARGET_OBJECTS:avs_common>
${SRC_FILES_VIS_AVS}
)
target_compile_definitions(vis_avs PUBLIC CAN_TALK_TO_WINAMP)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
check_linker_flag(C "/NXCOMPAT:NO" HAS_DISABLE_NXCOMPAT)
set(NXCOMPAT_DISABLED_FLAG "/NXCOMPAT:NO")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
check_linker_flag(C "-Wl,--disable-nxcompat" HAS_DISABLE_NXCOMPAT)
set(NXCOMPAT_DISABLED_FLAG "-Wl,--disable-nxcompat")
endif()
if(HAS_DISABLE_NXCOMPAT)
add_executable(avs-cli avs/avs-cli.c)
target_link_libraries(avs-cli libavs)
target_link_options(avs-cli PUBLIC ${NXCOMPAT_DISABLED_FLAG})
else()
message(WARNING "Linker flag --disable-nxcompat not supported."
" No standalone Win32 C/C++ binaries possible (libs will work)."
" Needs binutils 2.36 or higher.")
endif()
target_link_libraries(vis_avs
ddraw # draw.cpp includes ddraw.h
# https://docs.microsoft.com/en-us/windows/win32/api/ddraw/nf-ddraw-directdrawcreate
rpcrt4 # UUIDs
)
target_link_libraries(libavs
rpcrt4 # UUIDs
)
get_filename_component(WINAMP_DIR "[HKEY_CURRENT_USER\\SOFTWARE\\Winamp]" ABSOLUTE)
if(WINAMP_DIR STREQUAL "")
set(WINAMP_DIR "" CACHE PATH "Winamp installation directory (contains winamp.exe)." FORCE)
endif()
if(EXISTS "${WINAMP_DIR}")
add_custom_command(TARGET vis_avs POST_BUILD
COMMENT "Copy AVS .dll to Winamp plugins directory"
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:vis_avs>" "${WINAMP_DIR}/Plugins"
)
else()
message(WARNING "Winamp installation directory ('${WINAMP_DIR}') not found or not set. Skipped creating debug task.")
endif()
#[[
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# These dependent DLLs are introduced by mingw32 and should be next to winamp.exe.
configure_file(${CROSS_CC_PREFIX}/bin/libgcc_s_dw2-1.dll . COPYONLY)
configure_file(${CROSS_CC_PREFIX}/bin/libssp-0.dll . COPYONLY)
configure_file(${CROSS_CC_PREFIX}/bin/libstdc++-6.dll . COPYONLY)
configure_file(${CROSS_CC_PREFIX}/bin/libwinpthread-1.dll . COPYONLY)
endif()
#]]#
if(NOT MSVC)
# googletest here because it doesn't work for MSVC
endif()
set(AVS_DYLIB_EXTENSION "dll")
elseif(LINUX)
include(FindPkgConfig)
pkg_search_module(PIPEWIRE REQUIRED libpipewire-0.3)
target_include_directories(avs_common PUBLIC ${PIPEWIRE_INCLUDE_DIRS})
target_link_libraries(libavs uuid)
target_link_options(libavs PUBLIC -Wl,-m elf_i386)
set(AVS_DYLIB_EXTENSION "so")
add_executable(avs-cli avs/avs-cli.c)
target_link_libraries(avs-cli libavs)
endif()
# Rust
if(WIN32)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(RUST_TARGET "i686-pc-windows-msvc")
else()
set(RUST_TARGET "i686-pc-windows-gnu")
endif()
elseif(LINUX)
set(RUST_TARGET "i686-unknown-linux-gnu")
endif()
find_program(RUSTC rustc)
find_program(CARGO cargo)
if(WIN32) # Disable experimental Rust build on Windows for now, to make the CI green.
set(SKIP_RUST ON)
elseif(NOT RUSTC)
message(WARNING "Rust compiler not found. Rust code skipped.")
set(SKIP_RUST ON)
elseif(NOT CARGO)
message(WARNING "Cargo not found. Rust code skipped.")
set(SKIP_RUST ON)
else()
execute_process(COMMAND ${RUSTC} --target ${RUST_TARGET} --print target-libdir
OUTPUT_VARIABLE RUST_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT IS_DIRECTORY ${RUST_LIBDIR})
message(WARNING "Rust toolchain for \"${RUST_TARGET}\" not found. Rust code skipped.")
set(SKIP_RUST ON)
endif()
endif()
if(NOT SKIP_RUST)
ExternalProject_Add(avsrs
DEPENDS libavs
SOURCE_DIR "${CMAKE_SOURCE_DIR}"
CONFIGURE_COMMAND "" # default configure looks for the toolchain file in parent dir
BINARY_DIR "${CMAKE_SOURCE_DIR}"
BUILD_COMMAND ${CMAKE_COMMAND} -E env
"RUSTFLAGS=-L ${CMAKE_BINARY_DIR} -l avs"
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}
PKG_CONFIG_SYSROOT_DIR=/usr/lib32/
cargo build
--target ${RUST_TARGET}
--release
--target-dir ${CMAKE_BINARY_DIR}
--bin avs-cli
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/${RUST_TARGET}/release/avs-cli
${CMAKE_BINARY_DIR}/avs
LOG_BUILD ON
)
endif()
if(NOT MSVC)
# # tests
# if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
# link_libraries(${GTEST_LIB_NAME})
# else()
# link_libraries(gtest)
# endif()
# file(GLOB test_src test/*.cpp test/*.hpp)
# add_executable(test test/test.cpp)
# configure_file(${CROSS_CC_PREFIX}/bin/libgtest.dll . COPYONLY)
endif()