2023-03-23 20:20:44 +02:00
# Check for various C functions
check_cxx_symbol_exists ( prctl "sys/prctl.h" HAVE_PRCTL )
check_cxx_symbol_exists ( pthread_setname_np "pthread.h" HAVE_PTHREAD_SETNAME_NP )
# Go into more detail here and identify the valid signature of pthread_setname_np,
# because different systems have different forms of this function (ugh).
if ( HAVE_PTHREAD_SETNAME_NP )
include ( CheckCXXSourceCompiles )
check_cxx_source_compiles ( "
#include <thread>
i n t main ( ) {
pthread_setname_np ( \"ThreadName\");
r e t u r n 0 ;
} " H A V E _ S I N G L E _ P A R A M E T E R _ S E T N A M E _ N P )
check_cxx_source_compiles ( "
#include <thread>
i n t main ( ) {
pthread_setname_np ( pthread_self( ) , \ " T h r e a d N a m e \ " ) ;
r e t u r n 0 ;
} " H A V E _ T W O _ P A R A M E T E R _ S E T N A M E _ N P )
endif ( )
add_compile_definitions ( DPP_OS= ${ CMAKE_SYSTEM_NAME } )
if ( WIN32 AND NOT MINGW )
if ( NOT WINDOWS_32_BIT )
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 ( )
endif ( )
if ( UNIX )
message ( "-- Checking for ability to update autogenerated files" )
execute_process (
C O M M A N D w h i c h p h p
R E S U L T _ V A R I A B L E H A S _ P H P
O U T P U T _ Q U I E T
)
if ( ${ HAS_PHP } STREQUAL "0" )
message ( "-- Checking for update to autogenerated files" )
# target for rebuild of cluster::*_sync() functions
execute_process (
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . "
C O M M A N D p h p b u i l d t o o l s / m a k e _ s t r u c t . p h p " \ \ D p p \ \ G e n e r a t o r \ \ S y n c G e n e r a t o r "
)
set_source_files_properties ( "${CMAKE_CURRENT_SOURCE_DIR}/../include/dpp/cluster_sync_calls.h" PROPERTIES GENERATED TRUE )
else ( )
message ( "-- Autogeneration is not available" )
endif ( )
endif ( )
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_CURRENT_SOURCE_DIR}/../cmake/colour.cmake" )
if ( BUILD_VOICE_SUPPORT )
if ( MINGW OR NOT WIN32 )
find_package ( PkgConfig QUIET )
if ( PKG_CONFIG_FOUND )
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/FindSodium.cmake" )
else ( )
message ( "-- Could not detect ${Green}libsodium${ColourReset} due to missing ${Green}pkgconfig${ColourReset}. VOICE support will be ${Red}disabled${ColourReset}" )
endif ( )
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/FindOpus.cmake" )
endif ( )
if ( DEFINED OPUS_FOUND )
message ( "-- Found Opus ${Green}${OPUS_LIBRARIES}${ColourReset}" )
2023-08-05 21:31:33 +03:00
if ( ( WIN32 OR PKG_CONFIG_FOUND ) AND DEFINED sodium_VERSION_STRING AND DEFINED sodium_LIBRARY_RELEASE )
2023-03-23 20:20:44 +02:00
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 )
else ( )
message ( "-- Voice support disabled by cmake option" )
endif ( )
string ( ASCII 27 Esc )
set ( THREADS_PREFER_PTHREAD_FLAG ON )
find_package ( Threads REQUIRED )
if ( MINGW OR NOT WIN32 )
find_package ( ZLIB REQUIRED )
endif ( MINGW OR NOT WIN32 )
if ( APPLE )
if ( CMAKE_APPLE_SILICON_PROCESSOR EQUAL arm64 )
set ( OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl" )
else ( )
set ( OPENSSL_ROOT_DIR "/usr/local/opt/openssl" )
endif ( )
find_package ( OpenSSL REQUIRED )
else ( )
if ( MINGW OR NOT WIN32 )
find_package ( OpenSSL REQUIRED )
endif ( )
endif ( )
include_directories ( ${ OPENSSL_INCLUDE_DIR } ${ ZLIB_INCLUDE_DIRS } )
find_package ( Git QUIET )
if ( NOT GIT_FOUND AND EXISTS "${CMAKE_CURRENT_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 "${CMAKE_CURRENT_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" )
2023-08-05 21:31:33 +03:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /Od /DEBUG /Zi /sdl /DFD_SETSIZE=1024" )
2023-03-23 20:20:44 +02:00
else ( )
2023-08-05 21:31:33 +03:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /O2 /Oi /Oy /Gy /sdl /DFD_SETSIZE=1024" )
endif ( )
if ( NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zc:preprocessor" )
if ( NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL" )
endif ( )
2023-03-23 20:20:44 +02:00
endif ( )
string ( REGEX REPLACE "/W[1|2|3|4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -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" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og" )
if ( NOT MINGW )
add_link_options ( "-rdynamic" )
endif ( )
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" "${modules_dir}/dpp/cluster/*.cpp" "${modules_dir}/dpp/*.rc" )
if ( BUILD_SHARED_LIBS )
add_library ( ${ modname } SHARED ${ modsrc } )
else ( )
add_library ( ${ modname } STATIC ${ modsrc } )
endif ( )
set_target_properties ( ${ modname }
P R O P E R T I E S
V E R S I O N $ { C M A K E _ P R O J E C T _ V E R S I O N }
S O V E R S I O N $ { C M A K E _ P R O J E C T _ V E R S I O N }
P O S I T I O N _ I N D E P E N D E N T _ C O D E t r u e
)
target_include_directories ( ${ modname } PUBLIC
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / i n c l u d e >
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / i n c l u d e / d p p >
)
if ( WIN32 AND NOT MINGW )
if ( NOT WINDOWS_32_BIT )
target_link_libraries ( ${ modname } PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../win32/lib/libssl.lib"
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / l i b / l i b c r y p t o . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / l i b / l i b s o d i u m . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / l i b / o p u s . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / l i b / z l i b . l i b " )
else ( )
target_link_libraries ( ${ modname } PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/lib/libssl.lib"
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / 3 2 / l i b / l i b c r y p t o . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / 3 2 / l i b / l i b s o d i u m . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / 3 2 / l i b / o p u s . l i b "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / w i n 3 2 / 3 2 / l i b / z l i b . l i b " )
endif ( )
else ( )
target_link_libraries ( ${ modname } PUBLIC ${ OPENSSL_CRYPTO_LIBRARY } ${ OPENSSL_SSL_LIBRARY } ${ ZLIB_LIBRARIES } )
if ( MINGW )
target_link_libraries ( ${ modname } PUBLIC wsock32 ws2_32 crypt32 )
endif ( )
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 PUBLIC cxx_std_17 )
target_compile_features ( dpp PRIVATE cxx_constexpr )
target_compile_features ( dpp PRIVATE cxx_auto_type )
target_compile_features ( dpp PRIVATE cxx_defaulted_functions )
target_compile_features ( dpp PRIVATE cxx_deleted_functions )
target_compile_features ( dpp PRIVATE cxx_final )
target_compile_features ( dpp PRIVATE cxx_lambdas )
target_compile_features ( dpp PRIVATE cxx_override )
target_compile_features ( dpp PRIVATE cxx_thread_local )
target_compile_features ( dpp PRIVATE cxx_variadic_templates )
target_compile_features ( dpp PRIVATE cxx_attribute_deprecated )
if ( DPP_BUILD_TEST )
enable_testing ( ${ CMAKE_CURRENT_SOURCE_DIR } /.. )
file ( GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*" )
foreach ( fulltestname ${ testnamelist } )
get_filename_component ( testname ${ fulltestname } NAME )
if ( NOT "${testname}" STREQUAL "dpp" )
message ( "-- Configuring test: ${Green}${testname}${ColourReset} with source: ${modules_dir}/${testname}/*.cpp" )
set ( testsrc "" )
file ( GLOB testsrc "${modules_dir}/${testname}/*.cpp" )
add_executable ( ${ testname } ${ testsrc } )
target_compile_features ( ${ testname } PRIVATE cxx_std_17 )
target_link_libraries ( ${ testname } PUBLIC ${ modname } )
endif ( )
endforeach ( )
add_test (
N A M E u n i t t e s t s
C O M M A N D l i b r a r y / u n i t t e s t
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ R U N T I M E _ O U T P U T _ D I R E C T O R Y } / l i b r a r y
)
endif ( )
if ( HAVE_PRCTL )
target_compile_definitions ( dpp PRIVATE HAVE_PRCTL )
endif ( )
if ( HAVE_PTHREAD_SETNAME_NP )
target_compile_definitions ( dpp PRIVATE HAVE_PTHREAD_SETNAME_NP )
endif ( )
if ( DPP_CORO )
message ( "-- ${Yellow}Enabled experimental coroutine support${ColourReset}" )
set ( CMAKE_CXX_STANDARD 20 )
target_compile_features ( dpp PRIVATE cxx_std_20 )
if ( WIN32 AND NOT MINGW )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /await:strict" )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines" )
endif ( )
target_compile_definitions ( dpp PUBLIC DPP_CORO )
execute_process ( WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
C O M M A N D p h p b u i l d t o o l s / m a k e _ s t r u c t . p h p " \ \ D p p \ \ G e n e r a t o r \ \ C o r o G e n e r a t o r " )
endif ( )
if ( WIN32 AND NOT MINGW )
if ( NOT WINDOWS_32_BIT )
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 )
else ( )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/zlib1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/libcrypto-1_1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/libssl-1_1.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/libsodium.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../win32/32/bin/opus.dll" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" COPYONLY )
endif ( )
endif ( )
if ( DPP_INSTALL )
if ( NOT WIN32 )
# Installation
include ( GNUInstallDirs )
install ( TARGETS dpp LIBRARY DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
message ( "Library install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" )
install ( DIRECTORY ../include/ DESTINATION ${ CMAKE_INSTALL_INCLUDEDIR } )
message ( "Include files install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}" )
install ( CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DRUN_LDCONFIG=${RUN_LDCONFIG} -DLDCONFIG_EXECUTABLE=${LDCONFIG_EXECUTABLE} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/PostInstall.cmake)" )
configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/../dpp.pc.in" "${CMAKE_BINARY_DIR}/dpp.pc" @ONLY )
install ( FILES "${CMAKE_BINARY_DIR}/dpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" )
elseif ( MINGW )
install ( TARGETS dpp LIBRARY DESTINATION ${ CMAKE_INSTALL_PREFIX } /lib )
install ( DIRECTORY ../include/ DESTINATION ${ CMAKE_INSTALL_PREFIX } /include )
endif ( )
include ( "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CPackSetup.cmake" ) # Setup information for packaging and distribution
# CPack initialization for distribution
include ( CPack )
endif ( )