forked from brainboxdotcc/DPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
228 lines (176 loc) · 7.73 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
#
# D++ (DPP), The Lightweight C++ Discord Library
#
# Copyright 2021 Craig Edwards <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required (VERSION 3.12)
set(BUILD_SHARED_LIBS TRUE)
add_compile_definitions(DPP_BUILD)
if(WIN32)
message("-- Building for windows with precompiled packaged dependencies")
#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(ZLIB_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib")
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/win32/include")
set(OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/win32/include")
set(OPENSSL_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib")
ADD_DEFINITIONS(/bigobj)
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libssl.lib")
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libcrypto.lib")
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/zlib.lib")
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libsodium.lib")
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/opus.lib")
set(OPUS_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/win32/include")
set(OPUS_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/opus.lib")
set(sodium_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/win32/include")
set(sodium_LIBRARY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libsodium.lib")
set(sodium_LIBRARY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libsodium.lib")
set(HAVE_OPUS_OPUS_H "${CMAKE_CURRENT_SOURCE_DIR}/win32/include/opus/opus.h")
set(OPUS_FOUND 1)
SET(sodium_VERSION_STRING "win32 bundled")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/win32/include")
add_compile_definitions(OPENSSL_SYS_WIN32)
add_compile_definitions(_WINSOCK_DEPRECATED_NO_WARNINGS)
add_compile_definitions(WIN32_LEAN_AND_MEAN)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
endif()
#if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
# set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
#endif()
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/dpp/version.h" version_h)
if(NOT version_h MATCHES "DPP_VERSION_SHORT ([0-9][0-9])([0-9][0-9])([0-9][0-9])")
message(FATAL_ERROR "Cannot get DPP_VERSION_SHORT from version.h")
endif()
math(EXPR DPP_VERSION_MAJOR ${CMAKE_MATCH_1})
math(EXPR DPP_VERSION_MINOR ${CMAKE_MATCH_2})
math(EXPR DPP_VERSION_PATCH ${CMAKE_MATCH_3})
string(CONCAT DPP_VERSION ${DPP_VERSION_MAJOR}.${DPP_VERSION_MINOR}.${DPP_VERSION_PATCH})
project(libdpp VERSION ${DPP_VERSION} LANGUAGES CXX)
if(NOT BUILD_SHARED_LIBS)
if(UNIX)
message("-- Building static library.")
if(UNIX AND NOT APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
set(OPENSSL_USE_STATIC_LIBS ON)
set(sodium_USE_STATIC_LIBS ON)
set(OPUS_USE_STATIC_LIBS TRUE)
else()
message(WARNING "-- Building of static library not supported on non UNIX systems.")
endif()
endif()
include("cmake/colour.cmake")
if (NOT WIN32)
include("cmake/FindSodium.cmake")
include("cmake/FindOpus.cmake")
endif()
if(DEFINED OPUS_FOUND)
if(DEFINED sodium_VERSION_STRING)
add_compile_definitions(HAVE_VOICE)
message("-- Sodium ${Green}${sodium_VERSION_STRING}${ColourReset}")
set(HAVE_VOICE 1)
endif()
endif()
if(HAVE_VOICE)
message("-- Detected ${Green}libsodium${ColourReset} and ${Green}libopus${ColourReset}. VOICE support will be ${Green}enabled${ColourReset}")
else(HAVE_VOICE)
message("-- Could not detect ${Green}libsodium${ColourReset} and/or ${Green}libopus${ColourReset}. VOICE support will be ${Red}disabled${ColourReset}")
endif(HAVE_VOICE)
aux_source_directory("src" coresrc)
add_executable(test ${coresrc})
string(ASCII 27 Esc)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(NOT WIN32)
find_package(ZLIB REQUIRED)
endif(NOT WIN32)
if(APPLE)
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl")
find_package(OpenSSL REQUIRED)
else()
if(NOT WIN32)
find_package(OpenSSL REQUIRED)
endif()
endif()
include_directories(${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
target_compile_features(test PRIVATE cxx_std_17)
include_directories("include")
find_package(Git QUIET)
if(NOT GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(FATAL_ERROR "You are using a git version of D++ but do not have git installed. Install git (not 'gh') and try again.")
endif()
if(EXISTS "${PROJECT_SOURCE_DIR}/.git")
message("-- Building ${Green}git${ColourReset} version. ${Green}Be aware git versions may be unstable!${ColourReset}")
else()
message("-- Building ${Green}stable${ColourReset} version ${Green}${DPP_VERSION}${ColourReset}")
endif()
if(UNIX OR MSYS)
find_program(LDCONFIG_EXECUTABLE "ldconfig")
endif()
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Od /DEBUG /Zi /sdl /MP")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /O2 /Oi /Oy /GL /Gy /sdl /MP")
endif()
string(REGEX REPLACE "/W[1|2|3|4]" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread -g -O3 -fPIC")
add_link_options("-rdynamic")
endif()
set(modules_dir "src")
file(GLOB subdirlist ${modules_dir}/dpp)
foreach (fullmodname ${subdirlist})
get_filename_component(modname ${fullmodname} NAME)
set (modsrc "")
file(GLOB modsrc "${modules_dir}/dpp/*.cpp" "${modules_dir}/dpp/events/*.cpp")
if(BUILD_SHARED_LIBS)
add_library(${modname} SHARED ${modsrc})
else()
add_library(${modname} STATIC ${modsrc})
endif()
if (WIN32)
target_link_libraries(${modname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libssl.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libcrypto.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/libsodium.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/opus.lib"
"${CMAKE_CURRENT_SOURCE_DIR}/win32/lib/zlib.lib")
else()
target_link_libraries(${modname} PUBLIC ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} ${ZLIB_LIBRARIES})
endif()
if (HAVE_VOICE)
target_link_libraries(${modname} PUBLIC ${sodium_LIBRARY_RELEASE} ${OPUS_LIBRARIES})
include_directories(${OPUS_INCLUDE_DIRS} ${sodium_INCLUDE_DIR})
endif()
endforeach()
target_compile_features(dpp PRIVATE cxx_std_17)
target_link_libraries(test PUBLIC ${modname})
if(WIN32)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/bin/zlib1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/bin/libcrypto-1_1-x64.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/bin/libssl-1_1-x64.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/bin/libsodium.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/bin/opus.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY)
endif()
if(NOT WIN32)
# Installation
include(GNUInstallDirs)
install(TARGETS dpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DLDCONFIG_EXECUTABLE=${LDCONFIG_EXECUTABLE} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/PostInstall.cmake)")
endif()
include("cmake/CPackSetup.cmake") # Setup information for packaging and distribution
# CPack initialization for distribution
include(CPack)