-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
234 lines (188 loc) · 6.09 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
if((CMAKE_MAJOR_VERSION EQUAL 3) AND (CMAKE_MINOR_VERSION LESS 5))
cmake_minimum_required(VERSION 3.0)
else()
cmake_minimum_required(VERSION 3.5)
endif()
if((CMAKE_MAJOR_VERSION GREATER 3) OR
((CMAKE_MAJOR_VERSION EQUAL 3) AND NOT (CMAKE_MINOR_VERSION LESS 24)))
cmake_policy(SET CMP0135 NEW)
endif()
if("$ENV{CI}")
set(USE_LOGFILES OFF)
else()
set(USE_LOGFILES ON)
endif()
project(roc_pulse C CXX)
include("cmake/define_option.cmake")
define_option(TOOLCHAIN_PREFIX "" STRING "target host triplet, e.g. aarch64-linux-gnu")
include("cmake/setup_toolchain.cmake")
define_option(DOWNLOAD_PULSEAUDIO ON BOOL "automatically download pulseaudio")
define_option(DOWNLOAD_LIBTOOL ON BOOL "automatically download libtool (ltdl)")
define_option(DOWNLOAD_ROC ON BOOL "automatically download and build roc-toolkit")
define_option(PULSEAUDIO_VERSION "" STRING "pulseaudio version")
define_option(PULSEAUDIO_DIR "" STRING "directory with pulseaudio source code")
define_option(PULSEAUDIO_MODULE_DIR "" STRING "directory where to install pulseaudio modules")
define_option(LIBTOOL_VERSION "2.4.6" STRING "libtool version")
define_option(LIBTOOL_DIR "" STRING "directory with libtool source code")
define_option(ROC_REVISION "" STRING "roc toolkit revision to download")
define_option(ROC_INCLUDE_DIR "" STRING "roc toolkit include directory")
define_option(ROC_LIB_DIR "" STRING "roc toolkit library directory")
if(NOT PULSEAUDIO_VERSION)
if(NOT PULSEAUDIO_DIR)
if(NOT CMAKE_CROSSCOMPILING)
include("cmake/detect_system_pulseaudio_version.cmake")
if(SYSTEM_PULSEAUDIO_VERSION)
set(PULSEAUDIO_VERSION "${SYSTEM_PULSEAUDIO_VERSION}")
endif()
endif()
else()
include("cmake/detect_source_pulseaudio_version.cmake")
if(SOURCE_PULSEAUDIO_VERSION)
set(PULSEAUDIO_VERSION "${SOURCE_PULSEAUDIO_VERSION}")
endif()
endif()
endif()
if(NOT PULSEAUDIO_VERSION)
message(FATAL_ERROR "Can't auto-detect PULSEAUDIO_VERSION, define it manually")
else()
message(STATUS "Using PULSEAUDIO_VERSION - ${PULSEAUDIO_VERSION}")
endif()
string(REPLACE "." ";" PULSEAUDIO_VERSION_PARTS ${PULSEAUDIO_VERSION})
list(GET PULSEAUDIO_VERSION_PARTS 0 PULSEAUDIO_VERSION_MAJOR)
list(GET PULSEAUDIO_VERSION_PARTS 1 PULSEAUDIO_VERSION_MINOR)
if(NOT PULSEAUDIO_MODULE_DIR)
if(CMAKE_CROSSCOMPILING OR NOT SYSTEM_PULSEAUDIO_MODULE_DIR)
set(PULSEAUDIO_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/lib/pulse-${PULSEAUDIO_VERSION}/modules")
else()
set(PULSEAUDIO_MODULE_DIR "${SYSTEM_PULSEAUDIO_MODULE_DIR}")
endif()
message(STATUS "Using PULSEAUDIO_MODULE_DIR - ${PULSEAUDIO_MODULE_DIR}")
endif()
if(DOWNLOAD_PULSEAUDIO)
include("cmake/download_pulseaudio.cmake")
else()
if(PULSEAUDIO_DIR STREQUAL "")
message(FATAL_ERROR "If DOWNLOAD_PULSEAUDIO is OFF, PULSEAUDIO_DIR should be defined")
endif()
get_filename_component(PULSEAUDIO_DIR "${PULSEAUDIO_DIR}" ABSOLUTE)
message(STATUS "Using PULSEAUDIO_DIR - ${PULSEAUDIO_DIR}")
include_directories(SYSTEM
"${PULSEAUDIO_DIR}/src"
)
endif()
if(DOWNLOAD_LIBTOOL)
if(LIBTOOL_VERSION STREQUAL "")
message(FATAL_ERROR "If DOWNLOAD_LIBTOOL is ON, LIBTOOL_VERSION should be defined")
else()
message(STATUS "Using LIBTOOL_VERSION - ${LIBTOOL_VERSION}")
endif()
include("cmake/download_libtool.cmake")
elseif(NOT LIBTOOL_DIR STREQUAL "")
get_filename_component(LIBTOOL_DIR "${LIBTOOL_DIR}" ABSOLUTE)
message(STATUS "Using LIBTOOL_DIR - ${LIBTOOL_DIR}")
include_directories(SYSTEM
"${LIBTOOL_DIR}/libltdl"
)
endif()
if(DOWNLOAD_ROC)
if(NOT ROC_REVISION)
set(ROC_REVISION "master")
endif()
message(STATUS "Using ROC_REVISION - ${ROC_REVISION}")
include("cmake/download_roc.cmake")
else()
if(NOT ROC_INCLUDE_DIR STREQUAL "")
get_filename_component(ROC_INCLUDE_DIR "${ROC_INCLUDE_DIR}" ABSOLUTE)
message(STATUS "Using ROC_INCLUDE_DIR - ${ROC_INCLUDE_DIR}")
include_directories(SYSTEM "${ROC_INCLUDE_DIR}")
endif()
if(NOT ROC_LIB_DIR STREQUAL "")
get_filename_component(ROC_LIB_DIR "${ROC_LIB_DIR}" ABSOLUTE)
message(STATUS "Using ROC_LIB_DIR - ${ROC_LIB_DIR}")
link_directories("${ROC_LIB_DIR}")
endif()
link_libraries(
"roc"
)
endif()
if((PULSEAUDIO_VERSION_MAJOR GREATER 14) OR
((PULSEAUDIO_VERSION_MAJOR EQUAL 14) AND
NOT (PULSEAUDIO_VERSION_MINOR LESS 99)))
set(SETUP_PULSEAUDIO 1)
include("cmake/setup_pulseaudio.cmake")
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bin")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
add_compile_options(
"-Wall"
"-Wextra"
"-Wno-unused-variable"
"-fPIC"
"-pthread"
)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -pthread -lstdc++"
)
add_definitions(
-DROC_PULSEAUDIO_VERSION=${PULSEAUDIO_VERSION}
)
include_directories("src")
add_library(rocpulse_helpers OBJECT
"src/rocpulse_helpers.c"
)
if(SETUP_PULSEAUDIO)
add_dependencies(rocpulse_helpers
pulsebuild
)
endif()
if(DOWNLOAD_PULSEAUDIO)
add_dependencies(rocpulse_helpers
pulseaudio
)
endif()
if(DOWNLOAD_LIBTOOL)
add_dependencies(rocpulse_helpers
libtool
)
endif()
if(DOWNLOAD_ROC)
add_dependencies(rocpulse_helpers
roc
)
endif()
add_library(module-roc-sink SHARED
$<TARGET_OBJECTS:rocpulse_helpers>
"src/module-roc-sink.c"
)
add_library(module-roc-sink-input SHARED
$<TARGET_OBJECTS:rocpulse_helpers>
"src/module-roc-sink-input.c"
)
set(ALL_MODULES
module-roc-sink
module-roc-sink-input
)
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY ON)
foreach(MODULE IN LISTS ALL_MODULES)
install(
FILES $<TARGET_FILE:${MODULE}>
DESTINATION "${PULSEAUDIO_MODULE_DIR}"
)
endforeach()
if(NOT CMAKE_CROSSCOMPILING)
add_custom_command(
COMMENT "Copying compile_commands.json to project root"
DEPENDS ${ALL_MODULES}
OUTPUT "${PROJECT_SOURCE_DIR}/compile_commands.json"
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json"
"${PROJECT_SOURCE_DIR}/compile_commands.json"
)
add_custom_target(compile_commands ALL
DEPENDS "${PROJECT_SOURCE_DIR}/compile_commands.json"
)
endif()