forked from slomkowski/mumlib
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
230 lines (178 loc) · 5.36 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
#
# CMake/Global Settings
#
set(MUMLIB2_VERSION "1.0.0")
cmake_minimum_required(VERSION 3.13)
project(mumlib2 LANGUAGES CXX VERSION ${MUMLIB2_VERSION})
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
include(GNUInstallDirs)
#
# Dependencies
#
find_package(asio REQUIRED)
find_package(Protobuf REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Opus CONFIG REQUIRED)
#
# Variabls
#
set(MUMLIB2_STANDALONE OFF)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(MUMLIB2_STANDALONE ON)
endif()
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
#
# Options
#
if(MUMLIB2_STANDALONE AND NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
option(MUMLIB2_BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ${BUILD_SHARED_LIBS})
option(MUMLIB2_BUILD_EXAMPLE "Build example" ${MUMLIB2_STANDALONE})
if(MUMLIB2_BUILD_SHARED_LIBS)
set(MUMLIB2_LIBRARY_TYPE SHARED)
set(MUMLIB2_DEPS_VISIBLITY PRIVATE)
else()
set(MUMLIB2_LIBRARY_TYPE STATIC)
set(MUMLIB2_DEPS_VISIBLITY PUBLIC)
endif()
#
# Protobuf
#
protobuf_generate_cpp(MUMLIB2_SOURCES_PROTO MUMLIB2_HEADERS_PROTO "src_proto/mumble.proto")
#
# Library
#
add_library(mumlib2 ${MUMLIB2_LIBRARY_TYPE})
# Library/Sources
set(MUMLIB2_SOURCES
src/audio_decoder.cpp
src/audio_decoder_session.cpp
src/audio_encoder.cpp
src/audio_packet.cpp
src/crypto_state.cpp
src/logger.cpp
src/mumlib2.cpp
src/mumlib2_private.cpp
src/transport.cpp
src/varint.cpp
)
set(MUMLIB2_HEADERS
include/mumlib2.h
include/mumlib2/callback.h
include/mumlib2/constants.h
include/mumlib2/enums.h
include/mumlib2/exceptions.h
include/mumlib2/logger.h
include/mumlib2/structs.h
include/mumlib2_private/audio_decoder.h
include/mumlib2_private/audio_decoder_session.h
include/mumlib2_private/audio_encoder.h
include/mumlib2_private/audio_packet.h
include/mumlib2_private/crypto_state.h
include/mumlib2_private/mumlib2_private.h
include/mumlib2_private/transport.h
include/mumlib2_private/transport_ssl_context.h
include/mumlib2_private/varint.h
)
target_sources(mumlib2 PRIVATE
${MUMLIB2_SOURCES}
${MUMLIB2_SOURCES_PROTO}
${MUMLIB2_HEADERS}
${MUMLIB2_HEADERS_PROTO}
)
if(MSVC)
target_compile_options(mumlib2 PUBLIC /wd4244 /wd4251 /wd6001 /wd6031 /wd6255 /wd6258 /wd6385 /wd6386 /wd6387 /wd26439 /wd26451 /wd26495 /wd26812 /wd26819)
endif()
target_compile_definitions(mumlib2 PUBLIC _USE_MATH_DEFINES)
if(WIN32)
target_compile_definitions(mumlib2 PUBLIC _WIN32_WINNT=0x0601)
target_compile_definitions(mumlib2 PUBLIC _CRT_SECURE_NO_WARNINGS)
endif()
target_include_directories(mumlib2
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>"
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(mumlib2 ${MUMLIB2_DEPS_VISIBLITY} asio::asio)
target_link_libraries(mumlib2 ${MUMLIB2_DEPS_VISIBLITY} OpenSSL::SSL)
target_link_libraries(mumlib2 ${MUMLIB2_DEPS_VISIBLITY} Opus::opus)
target_link_libraries(mumlib2 ${MUMLIB2_DEPS_VISIBLITY} protobuf::libprotobuf)
if(WIN32)
target_link_libraries(mumlib2 ${MUMLIB2_DEPS_VISIBLITY} Crypt32)
endif()
set_target_properties(mumlib2 PROPERTIES CXX_STANDARD 20)
set_target_properties(mumlib2 PROPERTIES CXX_STANDARD_REQUIRED ON)
generate_export_header(mumlib2 EXPORT_FILE_NAME "mumlib2/export.h")
configure_package_config_file(
cmake/mumlib2-config.cmake.in
mumlib2-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
)
write_basic_package_version_file(
mumlib2-config-version.cmake
VERSION ${SENTRY_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
TARGETS mumlib2
EXPORT mumlib2
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
install(
FILES "include/mumlib2.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
DIRECTORY "include/mumlib2"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
FILES "${PROJECT_BINARY_DIR}/mumlib2/export.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mumlib2"
)
install(
EXPORT mumlib2
NAMESPACE mumlib2::
FILE mumlib2-targets.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)
install(
FILES
"${PROJECT_BINARY_DIR}/mumlib2-config.cmake"
"${PROJECT_BINARY_DIR}/mumlib2-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_CMAKEDIR}"
)
if(MSVC AND MUMLIB2_LIBRARY_TYPE STREQUAL "SHARED")
install(
FILES "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:$<TARGET_PDB_FILE:mumlib2>>"
DESTINATION "bin"
)
endif()
#
# Example
#
if(MUMLIB2_BUILD_EXAMPLE)
add_executable(mumlib2_example)
target_sources(mumlib2_example PRIVATE "src_example/mumlib2_example.cpp")
target_link_libraries(mumlib2_example PRIVATE mumlib2)
set_target_properties(mumlib2_example PROPERTIES CXX_STANDARD 20)
set_target_properties(mumlib2_example PROPERTIES CXX_STANDARD_REQUIRED ON)
install(
TARGETS mumlib2_example
RUNTIME DESTINATION "bin"
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
if(MSVC)
install(
FILES "$<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:$<TARGET_PDB_FILE:mumlib2_example>>"
DESTINATION "bin"
)
endif()
endif()