-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
159 lines (140 loc) · 4.76 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
cmake_minimum_required(VERSION 3.10)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
project(sela VERSION 2.0.2)
INCLUDE(CheckIncludeFiles)
include(generate_product_version)
# Verbose toggle
set(CMAKE_VERBOSE_MAKEFILE OFF)
# Use C++11
set(CMAKE_CXX_STANDARD 11)
# Require (at least) it
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Don't use e.g. GNU extension (like -std=gnu++11) for portability
set(CMAKE_CXX_EXTENSIONS OFF)
# Add support for threading library
find_package(Threads REQUIRED)
# Check if ao/ao.h is available or not
CHECK_INCLUDE_FILES(ao/ao.h HAVE_AO_H)
if(NOT HAVE_AO_H)
CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILES(sys/audio.h HAVE_SYS_AUDIO_H)
endif()
# Enable CTest
include(CTest)
enable_testing()
add_test(NAME tests COMMAND selatests)
# CPack config
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
# Build libao from source if not found in headers
if(NOT HAVE_AO_H)
set(
LIBAO_SOURCES
external/libao/src/ao_aixs.c
external/libao/src/ao_au.c
external/libao/src/ao_null.c
external/libao/src/ao_raw.c
external/libao/src/ao_wav.c
external/libao/src/audio_out.c
external/libao/src/config.c
)
if (WIN32)
list(APPEND LIBAO_SOURCES external/libao/src/ao_wmm.c)
endif ()
if(HAVE_ALSA_ASOUNDLIB_H)
list(APPEND LIBAO_SOURCES external/libao/src/plugins/alsa/ao_alsa.c)
endif()
add_library(ao ${LIBAO_SOURCES})
target_include_directories(ao PUBLIC external/libao/include)
target_include_directories(ao PRIVATE external/libao/include/ao)
target_compile_definitions(ao PRIVATE AO_BUILDING_LIBAO)
if (WIN32)
target_compile_definitions(ao PRIVATE HAVE_WMM)
target_link_libraries(ao PRIVATE Winmm.lib ksuser)
endif ()
if (HAVE_SYS_AUDIO_H)
target_compile_definitions(ao PRIVATE HAVE_SYS_AUDIO_H)
endif ()
endif()
#---------------------------------------------------
# Make sela executable -----------------
set(SELA_INCLUDE_DIR src/include)
set(SOURCES
src/main.cpp
src/lpc/linear_predictor.cpp
src/lpc/residue_generator.cpp
src/lpc/sample_generator.cpp
src/rice/rice_encoder.cpp
src/rice/rice_decoder.cpp
src/frame/frame_encoder.cpp
src/frame/frame_decoder.cpp
src/file/sela_file.cpp
src/file/wav_file.cpp
src/sela/encoder.cpp
src/sela/decoder.cpp
src/sela/player.cpp
)
generate_product_version(
VersionFilesOutputVariable
NAME "SimplE Lossless Audio - SELA"
VERSION_MAJOR 2
VERSION_MINOR 0
VERSION_PATCH 2
VERSION_REVISION ${BUILD_REVISION}
)
add_executable(sela ${SOURCES} ${VersionFilesOutputVariable})
target_include_directories(sela PUBLIC ${SELA_INCLUDE_DIR})
if(NOT HAVE_AO_H)
target_include_directories(sela PRIVATE external/libao/include)
endif()
#Generate static build on Mingw and Windows
if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(sela INTERFACE -static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES})
target_link_libraries(sela ${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive ao)
else()
target_link_libraries(sela Threads::Threads ao)
endif()
# Enable Warnings for MSVC/GCC/Clang on Debug Mode
if(CMAKE_BUILD_TYPE MATCHES "Debug")
if(MSVC)
target_compile_options(sela PUBLIC /W4 /WX)
else()
target_compile_options(sela PUBLIC -Wall -Wextra -pedantic -Werror)
endif()
endif()
# --------------------------------------------
# Prepare "Catch" library for other executables
set(CATCH_INCLUDE_DIR external/catch2/include)
add_library(Catch INTERFACE)
#--------------------------------------------
# Make test executable------------------------
set(TEST_SOURCES
src/frame/frame_decoder.cpp
src/frame/frame_encoder.cpp
test/frametests.cpp
src/lpc/linear_predictor.cpp
src/lpc/residue_generator.cpp
src/lpc/sample_generator.cpp
test/lpctests.cpp
src/rice/rice_encoder.cpp
src/rice/rice_decoder.cpp
test/ricetests.cpp
test/main.cpp
)
add_executable(selatests ${TEST_SOURCES} ${VersionFilesOutputVariable})
target_include_directories(selatests PRIVATE ${CATCH_INCLUDE_DIR})
option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(selatests PUBLIC
-O0 # no optimization
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(selatests PUBLIC --coverage)
else()
target_link_libraries(selatests PUBLIC --coverage)
endif()
endif()
#---------------------------------------------------------------