| 1 |
# |
| 2 |
# D++ (DPP), The Lightweight C++ Discord Library |
| 3 |
# |
| 4 |
# Copyright 2021 Craig Edwards <[email protected]> |
| 5 |
# |
| 6 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
# you may not use this file except in compliance with the License. |
| 8 |
# You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, software |
| 13 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
# See the License for the specific language governing permissions and |
| 16 |
# limitations under the License. |
| 17 |
|
| 18 |
# Check for various C functions |
| 19 |
check_cxx_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL) |
| 20 |
check_cxx_symbol_exists(pthread_setname_np "pthread.h" HAVE_PTHREAD_SETNAME_NP) |
| 21 |
|
| 22 |
# Go into more detail here and identify the valid signature of pthread_setname_np, |
| 23 |
# because different systems have different forms of this function (ugh). |
| 24 |
if (HAVE_PTHREAD_SETNAME_NP) |
| 25 |
include(CheckCXXSourceCompiles) |
| 26 |
check_cxx_source_compiles(" |
| 27 |
#include <thread> |
| 28 |
int main() { |
| 29 |
pthread_setname_np(\"ThreadName\"); |
| 30 |
return 0; |
| 31 |
}" HAVE_SINGLE_PARAMETER_SETNAME_NP) |
| 32 |
check_cxx_source_compiles(" |
| 33 |
#include <thread> |
| 34 |
int main() { |
| 35 |
pthread_setname_np(pthread_self(), \"ThreadName\"); |
| 36 |
return 0; |
| 37 |
}" HAVE_TWO_PARAMETER_SETNAME_NP) |
| 38 |
endif() |
| 39 |
|
| 40 |
add_compile_definitions(DPP_OS=${CMAKE_SYSTEM_NAME}) |
| 41 |
|
| 42 |
if(${AVX_TYPE} STREQUAL "OFF") |
| 43 |
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/DetectArchitecture.cmake") |
| 44 |
else() |
| 45 |
message("-- AVX type overridden by configuration: ${AVX_TYPE}") |
| 46 |
endif() |
| 47 |
STRING(REPLACE "AVX" "" AVX_TYPE ${AVX_TYPE}) |
| 48 |
add_compile_definitions(AVX_TYPE=${AVX_TYPE}) |
| 49 |
add_compile_options(${AVX_FLAG}) |
| 50 |
|
| 51 |
if(NOT BUILD_SHARED_LIBS) |
| 52 |
if(UNIX) |
| 53 |
message("-- Building ${Green}static${ColourReset} library.") |
| 54 |
|
| 55 |
if(UNIX AND NOT APPLE) |
| 56 |
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") |
| 57 |
message("-- INFO: Changed lib suffix to ${CMAKE_FIND_LIBRARY_SUFFIXES}") |
| 58 |
endif() |
| 59 |
|
| 60 |
set(OPENSSL_USE_STATIC_LIBS TRUE) |
| 61 |
set(OPUS_USE_STATIC_LIBS TRUE) |
| 62 |
|
| 63 |
else() |
| 64 |
message(WARNING "-- Building of static library not supported on non UNIX systems.") |
| 65 |
endif() |
| 66 |
else() |
| 67 |
message("-- Building ${Green}dynamic${ColourReset} library.") |
| 68 |
endif() |
| 69 |
|
| 70 |
if (CONAN_EXPORTED) |
| 71 |
message("-- INFO: ${Green}Conan detected${ColourReset}... finding packages...") |
| 72 |
find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto) |
| 73 |
find_package(ZLIB REQUIRED) |
| 74 |
find_package(Opus) |
| 75 |
find_package(Threads REQUIRED) |
| 76 |
find_package(Git QUIET) |
| 77 |
endif() |
| 78 |
|
| 79 |
if(WIN32 AND NOT MINGW) |
| 80 |
# Fake an ssl version number to satisfy MLSPP |
| 81 |
set(OPENSSL_VERSION "1.1.1f") |
| 82 |
if (NOT WINDOWS_32_BIT) |
| 83 |
message("-- Building for windows with precompiled packaged dependencies") |
| 84 |
#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
| 85 |
if (NOT CONAN_EXPORTED) |
| 86 |
set(ZLIB_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib") |
| 87 |
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../win32/include") |
| 88 |
set(OPENSSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../win32/include") |
| 89 |
set(OPENSSL_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib") |
| 90 |
|
| 91 |
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/libssl.lib") |
| 92 |
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/libcrypto.lib") |
| 93 |
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/zlib.lib") |
| 94 |
link_libraries("${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/opus.lib") |
| 95 |
|
| 96 |
set(OPUS_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../win32/include") |
| 97 |
set(OPUS_LIBRARIES "${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/opus.lib") |
| 98 |
set(HAVE_OPUS_OPUS_H "${CMAKE_CURRENT_SOURCE_DIR}/../win32/include/opus/opus.h") |
| 99 |
|
| 100 |
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../win32/include") |
| 101 |
endif() |
| 102 |
|
| 103 |
set(OPUS_FOUND 1) |
| 104 |
|
| 105 |
add_compile_options("/bigobj") |
| 106 |
add_compile_definitions(OPENSSL_SYS_WIN32) |
| 107 |
add_compile_definitions(_WINSOCK_DEPRECATED_NO_WARNINGS) |
| 108 |
add_compile_definitions(WIN32_LEAN_AND_MEAN) |
| 109 |
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) |
| 110 |
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) |
| 111 |
|
| 112 |
endif() |
| 113 |
endif() |
| 114 |
|
| 115 |
if (UNIX) |
| 116 |
message("-- Checking for ability to update autogenerated files") |
| 117 |
execute_process( |
| 118 |
COMMAND which php |
| 119 |
RESULT_VARIABLE HAS_PHP |
| 120 |
OUTPUT_QUIET |
| 121 |
) |
| 122 |
|
| 123 |
if (${HAS_PHP} STREQUAL "0") |
| 124 |
message("-- Checking for update to autogenerated files") |
| 125 |
# target for unicode_emojis.h |
| 126 |
execute_process( |
| 127 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." |
| 128 |
COMMAND php buildtools/emojis.php |
| 129 |
) |
| 130 |
set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/unicode_emojis.h" PROPERTIES GENERATED TRUE ) |
| 131 |
|
| 132 |
if (NOT DPP_NO_CORO) |
| 133 |
execute_process( |
| 134 |
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." |
| 135 |
COMMAND php buildtools/make_struct.php "\\Dpp\\Generator\\CoroGenerator" |
| 136 |
) |
| 137 |
endif() |
| 138 |
else() |
| 139 |
message("-- Autogeneration is not available") |
| 140 |
endif() |
| 141 |
endif() |
| 142 |
|
| 143 |
if (BUILD_VOICE_SUPPORT) |
| 144 |
if (MINGW OR NOT WIN32) |
| 145 |
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/FindOpus.cmake") |
| 146 |
endif() |
| 147 |
|
| 148 |
if(HAVE_OPUS_OPUS_H) |
| 149 |
message("-- Found Opus ${Green}${OPUS_LIBRARIES}${ColourReset}") |
| 150 |
add_compile_definitions(HAVE_VOICE) |
| 151 |
set(HAVE_VOICE 1) |
| 152 |
endif() |
| 153 |
|
| 154 |
if(HAVE_VOICE) |
| 155 |
message("-- Detected ${Green}libopus${ColourReset}. VOICE support will be ${Green}enabled${ColourReset}") |
| 156 |
else(HAVE_VOICE) |
| 157 |
message("-- Could not detect ${Green}libopus${ColourReset}. VOICE support will be ${Red}disabled${ColourReset}") |
| 158 |
endif(HAVE_VOICE) |
| 159 |
else() |
| 160 |
message("-- Voice support disabled by cmake option") |
| 161 |
endif() |
| 162 |
|
| 163 |
string(ASCII 27 Esc) |
| 164 |
|
| 165 |
set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 166 |
|
| 167 |
if (NOT CONAN_EXPORTED) |
| 168 |
find_package(Threads REQUIRED) |
| 169 |
endif() |
| 170 |
if(MINGW OR NOT WIN32) |
| 171 |
if (NOT CONAN_EXPORTED) |
| 172 |
find_package(ZLIB REQUIRED) |
| 173 |
endif() |
| 174 |
message("-- ZLIB: ${Green}${ZLIB_LIBRARIES}${ColourReset}") |
| 175 |
endif(MINGW OR NOT WIN32) |
| 176 |
|
| 177 |
if (NOT CONAN_EXPORTED) |
| 178 |
if(APPLE) |
| 179 |
if(CMAKE_APPLE_SILICON_PROCESSOR EQUAL arm64) |
| 180 |
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl") |
| 181 |
else() |
| 182 |
set(OPENSSL_ROOT_DIR "/usr/local/opt/openssl") |
| 183 |
endif() |
| 184 |
find_package(OpenSSL REQUIRED) |
| 185 |
else() |
| 186 |
if(MINGW OR NOT WIN32) |
| 187 |
if(NOT BUILD_SHARED_LIBS) |
| 188 |
set(OPENSSL_USE_STATIC_LIBS TRUE) |
| 189 |
endif() |
| 190 |
find_package(OpenSSL REQUIRED) |
| 191 |
endif() |
| 192 |
endif() |
| 193 |
endif() |
| 194 |
|
| 195 |
include_directories(${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS}) |
| 196 |
|
| 197 |
if (NOT CONAN_EXPORTED) |
| 198 |
find_package(Git QUIET) |
| 199 |
endif() |
| 200 |
|
| 201 |
if(NOT GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.git") |
| 202 |
message(FATAL_ERROR "You are using a git version of D++ but do not have git installed. Install git (not 'gh') and try again.") |
| 203 |
endif() |
| 204 |
|
| 205 |
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.git") |
| 206 |
message("-- Building ${Green}git${ColourReset} version. ${Green}Be aware git versions may be unstable!${ColourReset}") |
| 207 |
else() |
| 208 |
message("-- Building ${Green}stable${ColourReset} version ${Green}${DPP_VERSION}${ColourReset}") |
| 209 |
endif() |
| 210 |
|
| 211 |
if(UNIX OR MSYS) |
| 212 |
find_program(LDCONFIG_EXECUTABLE "ldconfig") |
| 213 |
endif() |
| 214 |
|
| 215 |
if(MSVC) |
| 216 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /sdl /DFD_SETSIZE=1024") |
| 217 |
if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 218 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /Od /DEBUG /Zi") |
| 219 |
else() |
| 220 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Oi /Oy /Gy") |
| 221 |
endif() |
| 222 |
if(NOT DPP_CLANG_CL) |
| 223 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zc:preprocessor") |
| 224 |
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 225 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL") |
| 226 |
endif() |
| 227 |
endif() |
| 228 |
string(REGEX REPLACE "/W[1|2|3|4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 229 |
else() |
| 230 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-unused-private-field -Wno-psabi -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -Wshift-negative-value -pthread") |
| 231 |
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g") |
| 232 |
|
| 233 |
if (NOT MINGW) |
| 234 |
add_link_options("-rdynamic") |
| 235 |
endif () |
| 236 |
endif() |
| 237 |
|
| 238 |
set(modules_dir "../src") |
| 239 |
|
| 240 |
file(GLOB subdirlist ${modules_dir}/dpp) |
| 241 |
|
| 242 |
if (HAVE_VOICE) |
| 243 |
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../mlspp" "mlspp") |
| 244 |
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../mlspp/include") |
| 245 |
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../mlspp/lib/bytes/include") |
| 246 |
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../mlspp/lib/hpke/include") |
| 247 |
endif() |
| 248 |
|
| 249 |
foreach (fullmodname ${subdirlist}) |
| 250 |
get_filename_component(modname ${fullmodname} NAME) |
| 251 |
set (modsrc "") |
| 252 |
|
| 253 |
if (HAVE_VOICE) |
| 254 |
file(GLOB modsrc "${modules_dir}/dpp/*.cpp" "${modules_dir}/dpp/voice/enabled/*.cpp" "${modules_dir}/dpp/dave/*.cpp" "${modules_dir}/dpp/events/*.cpp" "${modules_dir}/dpp/cluster/*.cpp" "${modules_dir}/dpp/*.rc") |
| 255 |
else() |
| 256 |
file(GLOB modsrc "${modules_dir}/dpp/*.cpp" "${modules_dir}/dpp/voice/stub/*.cpp" "${modules_dir}/dpp/events/*.cpp" "${modules_dir}/dpp/cluster/*.cpp" "${modules_dir}/dpp/*.rc") |
| 257 |
endif() |
| 258 |
|
| 259 |
if(BUILD_SHARED_LIBS) |
| 260 |
add_library(${modname} SHARED ${modsrc}) |
| 261 |
else() |
| 262 |
add_library(${modname} STATIC ${modsrc}) |
| 263 |
endif() |
| 264 |
set_target_properties(${modname} |
| 265 |
PROPERTIES |
| 266 |
VERSION ${CMAKE_PROJECT_VERSION} |
| •267 |
SOVERSION ${DPP_VERSION_MAJOR}.${DPP_VERSION_MINOR} |
| 268 |
POSITION_INDEPENDENT_CODE true |
| 269 |
) |
| 270 |
target_include_directories(${modname} PUBLIC |
| 271 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> |
| 272 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp> |
| 273 |
) |
| 274 |
|
| 275 |
if (DPP_USE_PCH) |
| 276 |
target_precompile_headers(${modname} PRIVATE |
| 277 |
"${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/cluster.h" |
| 278 |
"${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/json.h" |
| 279 |
"${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/utility.h" |
| 280 |
"${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/restresults.h" |
| 281 |
) |
| 282 |
endif() |
| 283 |
|
| 284 |
if (WIN32 AND NOT MINGW AND NOT CONAN_EXPORTED) |
| 285 |
|
| 286 |
if (NOT WINDOWS_32_BIT) |
| 287 |
target_link_libraries(${modname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/libssl.lib" |
| 288 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/libcrypto.lib" |
| 289 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/opus.lib" |
| 290 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/zlib.lib") |
| 291 |
else() |
| 292 |
target_link_libraries(${modname} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/libssl.lib" |
| 293 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/libcrypto.lib" |
| 294 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/opus.lib" |
| 295 |
"${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/zlib.lib") |
| 296 |
endif() |
| 297 |
|
| 298 |
else() |
| 299 |
if (CONAN_EXPORTED) |
| 300 |
target_link_libraries(${modname} PUBLIC openssl::openssl ZLIB::ZLIB Opus::opus) |
| 301 |
else() |
| 302 |
target_link_libraries(${modname} PUBLIC ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} ${ZLIB_LIBRARIES}) |
| 303 |
endif() |
| 304 |
if (MINGW) |
| 305 |
target_link_libraries(${modname} PUBLIC wsock32 ws2_32 crypt32) |
| 306 |
endif () |
| 307 |
endif() |
| 308 |
|
| 309 |
if (HAVE_VOICE) |
| 310 |
target_link_libraries(${modname} PUBLIC ${OPUS_LIBRARIES}) |
| 311 |
include_directories(${OPUS_INCLUDE_DIRS}) |
| 312 |
endif() |
| 313 |
endforeach() |
| 314 |
|
| 315 |
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/epoll.cmake") |
| 316 |
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/kqueue.cmake") |
| 317 |
check_epoll(HAS_EPOLL) |
| 318 |
check_kqueue(HAS_KQUEUE) |
| 319 |
if (HAS_EPOLL) |
| 320 |
message("-- Building with ${Green}epoll socket engine${ColourReset} -- ${Green}good!${ColourReset}") |
| 321 |
target_sources("dpp" PRIVATE "${modules_dir}/dpp/socketengines/epoll.cpp") |
| 322 |
elseif (HAS_KQUEUE) |
| 323 |
message("-- Building with ${Green}kqueue socket engine${ColourReset} -- ${Green}good!${ColourReset}") |
| 324 |
target_sources("dpp" PRIVATE "${modules_dir}/dpp/socketengines/kqueue.cpp") |
| 325 |
else() |
| 326 |
message("-- Building with ${Green}poll socket engine${ColourReset} -- ${Red}meh!${ColourReset}") |
| 327 |
target_sources("dpp" PRIVATE "${modules_dir}/dpp/socketengines/poll.cpp") |
| 328 |
endif() |
| 329 |
if (HAVE_VOICE) |
| 330 |
# Private statically linked dependencies |
| 331 |
if(NOT BUILD_SHARED_LIBS AND NOT APPLE) |
| 332 |
target_link_libraries(dpp PRIVATE |
| 333 |
mlspp.a |
| 334 |
mls_vectors.a |
| 335 |
bytes.a |
| 336 |
tls_syntax.a |
| 337 |
hpke.a |
| 338 |
) |
| 339 |
message("-- INFO: Linking static dependencies") |
| 340 |
else() |
| 341 |
target_link_libraries(dpp PRIVATE |
| 342 |
mlspp |
| 343 |
mls_vectors |
| 344 |
bytes |
| 345 |
tls_syntax |
| 346 |
hpke |
| 347 |
) |
| 348 |
message("-- INFO: Linking dynamic dependencies") |
| 349 |
endif() |
| 350 |
endif() |
| 351 |
|
| 352 |
target_compile_features(dpp PUBLIC cxx_std_17) |
| 353 |
target_compile_features(dpp PRIVATE cxx_constexpr) |
| 354 |
target_compile_features(dpp PRIVATE cxx_auto_type) |
| 355 |
target_compile_features(dpp PRIVATE cxx_defaulted_functions) |
| 356 |
target_compile_features(dpp PRIVATE cxx_deleted_functions) |
| 357 |
target_compile_features(dpp PRIVATE cxx_final) |
| 358 |
target_compile_features(dpp PRIVATE cxx_lambdas) |
| 359 |
target_compile_features(dpp PRIVATE cxx_override) |
| 360 |
target_compile_features(dpp PRIVATE cxx_thread_local) |
| 361 |
target_compile_features(dpp PRIVATE cxx_variadic_templates) |
| 362 |
target_compile_features(dpp PRIVATE cxx_attribute_deprecated) |
| 363 |
|
| 364 |
if(HAVE_PRCTL) |
| 365 |
target_compile_definitions(dpp PRIVATE HAVE_PRCTL) |
| 366 |
endif() |
| 367 |
if(HAVE_PTHREAD_SETNAME_NP) |
| 368 |
target_compile_definitions(dpp PRIVATE HAVE_PTHREAD_SETNAME_NP) |
| 369 |
endif() |
| 370 |
|
| 371 |
if(NOT DPP_NO_CORO) |
| 372 |
message("-- Attempting to enable coroutines feature") |
| 373 |
set(CMAKE_CXX_STANDARD 20) |
| 374 |
target_compile_features(dpp PUBLIC cxx_std_20) |
| 375 |
if(WIN32 AND NOT MINGW AND NOT DPP_CLANG_CL) |
| 376 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /await:strict") # https://learn.microsoft.com/en-us/cpp/build/reference/await-enable-coroutine-support?view=msvc-170 |
| 377 |
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") |
| 378 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 19.29.30158) # Taken from 2019 actions, as they seemingly fail to compile. |
| 379 |
message("${BoldRed}Coroutines with MSVC (Visual Studio) require VS 2022 (Compiler Ver: 19.29.30158) or above. Forcing coroutines off.${ColourReset}") |
| 380 |
set(DPP_NO_CORO ON) |
| 381 |
endif() |
| 382 |
endif() |
| 383 |
else() |
| 384 |
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 385 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0.0) # clang >= 14 has native support |
| 386 |
message("-- ${Yellow}Clang < 14 - attempting to detect if using libc++ or stdc++${ColourReset}") |
| 387 |
check_cxx_source_compiles(" |
| 388 |
#include <iostream> |
| 389 |
|
| 390 |
int a = |
| 391 |
#ifdef __GLIBCXX__ |
| 392 |
1; |
| 393 |
#else |
| 394 |
fgsfds; |
| 395 |
#endif |
| 396 |
|
| 397 |
int main(int argc, char* argv[]) |
| 398 |
{ |
| 399 |
return 0; |
| 400 |
} |
| 401 |
" IS_GLIBCXX) |
| 402 |
if(IS_GLIBCXX) |
| 403 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0.0) |
| 404 |
message("${BoldRed}Clang with stdc++ and coroutines requires version 12.0.0 or above. Forcing coroutines off.${ColourReset}") |
| 405 |
set(DPP_NO_CORO ON) |
| 406 |
else() |
| 407 |
message("-- ${Yellow}Detected stdc++ - enabling mock std::experimental namespace${ColourReset}") |
| 408 |
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO") |
| 409 |
endif() |
| 410 |
else() |
| 411 |
message("-- ${Yellow}Detected libc++ - using <experimental/coroutine>${ColourReset}") |
| 412 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0.0) |
| 413 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines-ts") |
| 414 |
endif() |
| 415 |
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO") |
| 416 |
endif() |
| 417 |
message("-- ${Yellow}Note - coroutines in clang < 14 are experimental, upgrading is recommended${ColourReset}") |
| 418 |
endif() |
| 419 |
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") |
| 420 |
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) |
| 421 |
message("${BoldRed}Coroutines with g++ require version 10 or above. Forcing coroutines off.${ColourReset}") |
| 422 |
set(DPP_NO_CORO ON) |
| 423 |
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0) |
| 424 |
message("-- ${Yellow}Note - coroutines in g++10 are experimental, upgrading to g++11 or above is recommended${ColourReset}") |
| 425 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines") |
| 426 |
target_compile_definitions(dpp PUBLIC "STDCORO_GLIBCXX_COMPAT" "DPP_CORO") |
| 427 |
endif() |
| 428 |
endif() |
| 429 |
endif() |
| 430 |
endif() |
| 431 |
|
| 432 |
if(DPP_NO_CORO) |
| 433 |
message("-- ${Yellow}Coroutines are disabled.${ColourReset}") |
| 434 |
target_compile_definitions(dpp PUBLIC DPP_NO_CORO) |
| 435 |
else() |
| 436 |
message("-- ${Green}Coroutines are enabled!${ColourReset}") |
| 437 |
endif() |
| 438 |
|
| 439 |
if(DPP_FORMATTERS) |
| 440 |
target_compile_definitions(dpp PUBLIC DPP_FORMATTERS) |
| 441 |
endif() |
| 442 |
|
| 443 |
if (NOT BUILD_SHARED_LIBS) |
| 444 |
if (HAVE_VOICE) |
| 445 |
add_library(dppstatic STATIC |
| 446 |
$<TARGET_OBJECTS:dpp> |
| 447 |
$<TARGET_OBJECTS:hpke> |
| 448 |
$<TARGET_OBJECTS:tls_syntax> |
| 449 |
$<TARGET_OBJECTS:mls_vectors> |
| 450 |
$<TARGET_OBJECTS:mlspp> |
| 451 |
$<TARGET_OBJECTS:bytes> |
| 452 |
) |
| 453 |
target_link_libraries(dppstatic ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} ${OPUS_LIBRARIES} -static-libgcc -static-libstdc++) |
| 454 |
else() |
| 455 |
add_library(dppstatic STATIC |
| 456 |
$<TARGET_OBJECTS:dpp> |
| 457 |
) |
| 458 |
target_link_libraries(dppstatic ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES}) |
| 459 |
endif() |
| 460 |
|
| 461 |
target_include_directories(dppstatic PUBLIC |
| 462 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> |
| 463 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp> |
| 464 |
) |
| 465 |
target_compile_definitions(dppstatic PUBLIC $<TARGET_PROPERTY:dpp,INTERFACE_COMPILE_DEFINITIONS>) |
| 466 |
endif() |
| 467 |
|
| 468 |
if (DPP_BUILD_TEST) |
| 469 |
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..) |
| 470 |
file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*") |
| 471 |
foreach (fulltestname ${testnamelist}) |
| 472 |
get_filename_component(testname ${fulltestname} NAME) |
| 473 |
if (NOT "${testname}" STREQUAL "dpp") |
| 474 |
message("-- Configuring test: ${Green}${testname}${ColourReset} with source: ${modules_dir}/${testname}/*.cpp") |
| 475 |
set (testsrc "") |
| 476 |
file(GLOB testsrc "${modules_dir}/${testname}/*.cpp") |
| 477 |
add_executable(${testname} ${testsrc}) |
| 478 |
if ((NOT DPP_NO_CORO) OR DPP_FORMATTERS) |
| 479 |
target_compile_features(${testname} PRIVATE cxx_std_20) |
| 480 |
else() |
| 481 |
target_compile_features(${testname} PRIVATE cxx_std_17) |
| 482 |
endif() |
| 483 |
if (MSVC) |
| 484 |
target_compile_options(${testname} PRIVATE /utf-8) |
| 485 |
endif() |
| 486 |
if(BUILD_SHARED_LIBS) |
| 487 |
target_link_libraries(${testname} PUBLIC ${modname}) |
| 488 |
else() |
| 489 |
target_link_libraries(${testname} PUBLIC dppstatic) |
| 490 |
endif() |
| 491 |
endif() |
| 492 |
endforeach() |
| 493 |
add_test( |
| 494 |
NAME unittest |
| 495 |
COMMAND unittest |
| 496 |
) |
| 497 |
endif() |
| 498 |
|
| 499 |
if (NOT CONAN_EXPORTED) |
| 500 |
if(WIN32 AND NOT MINGW) |
| 501 |
if (NOT WINDOWS_32_BIT) |
| 502 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/bin/zlib1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 503 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/bin/libcrypto-1_1-x64.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 504 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/bin/libssl-1_1-x64.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 505 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/bin/opus.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 506 |
else() |
| 507 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/zlib1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 508 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/libcrypto-1_1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 509 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/libssl-1_1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 510 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/opus.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY) |
| 511 |
endif() |
| 512 |
endif() |
| 513 |
endif() |
| 514 |
|
| 515 |
if(DPP_INSTALL) |
| 516 |
if(NOT WIN32) |
| 517 |
# Installation |
| 518 |
|
| 519 |
include(GNUInstallDirs) |
| 520 |
install(TARGETS dpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 521 |
message("Library install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") |
| 522 |
install(DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 523 |
message("Include files install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") |
| 524 |
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DRUN_LDCONFIG=${RUN_LDCONFIG} -DLDCONFIG_EXECUTABLE=${LDCONFIG_EXECUTABLE} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/PostInstall.cmake)") |
| 525 |
|
| 526 |
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../dpp.pc.in" "${CMAKE_BINARY_DIR}/dpp.pc" @ONLY) |
| 527 |
install(FILES "${CMAKE_BINARY_DIR}/dpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") |
| 528 |
elseif(MINGW) |
| 529 |
install(TARGETS dpp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) |
| 530 |
install(DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include) |
| 531 |
endif() |
| 532 |
|
| 533 |
# Setup information for packaging and distribution |
| 534 |
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CPackSetup.cmake") |
| 535 |
|
| 536 |
# CPack initialization for distribution |
| 537 |
include(CPack) |
| 538 |
endif() |