diff --git a/CMakeLists.txt b/CMakeLists.txt index b12fe99ef1..c1a5262c9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,11 +29,14 @@ option(DPP_FORMATTERS "Support for C++20 formatters" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) option(AVX_TYPE "Force AVX type for speeding up audio mixing" OFF) +option(DPP_TEST_VCPKG "Force VCPKG build without VCPKG installed (for development use only!)" OFF) include(CheckCXXSymbolExists) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_definitions(DPP_BUILD) +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/colour.cmake") + set(DPP_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) file(READ "${DPP_ROOT_PATH}/include/dpp/version.h" version_h) @@ -50,10 +53,14 @@ string(CONCAT DPP_VERSION "${DPP_VERSION_MAJOR}.${DPP_VERSION_MINOR}.${DPP_VERSI set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${DPP_ROOT_PATH}/cmake/") -if (DPP_NO_VCPKG) - message("-- INFO: Explicitly disabling VCPKG as running inside the CI action.") +if (DPP_TEST_VCPKG) + message("-- ${Red}DEVELOPER WARNING${ColourReset}: Running in ${Red}VCPKG test mode${ColourReset}: EMULATING A VCPKG BUILD WITHOUT VCPKG") else() - message("-- INFO: Using VCPKG if detected") + if (DPP_NO_VCPKG) + message("-- INFO: Explicitly disabling VCPKG as running inside the CI action.") + else() + message("-- INFO: Using VCPKG if detected") + endif() endif() if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS) @@ -61,14 +68,14 @@ if (WIN32 AND NOT MINGW AND BUILD_SHARED_LIBS) configure_file("${DPP_ROOT_PATH}/src/dpp/dpp.rc.in" "${DPP_ROOT_PATH}/src/dpp/dpp.rc" NEWLINE_STYLE WIN32) endif() -if (NOT DPP_NO_VCPKG AND EXISTS "${_VCPKG_ROOT_DIR}") +if (DPP_TEST_VCPKG) set(PROJECT_NAME "dpp") project( - "${PROJECT_NAME}" - VERSION "${DPP_VERSION}" - LANGUAGES CXX - HOMEPAGE_URL "https://dpp.dev/" - DESCRIPTION "An incredibly lightweight C++ Discord library." + "${PROJECT_NAME}" + VERSION "${DPP_VERSION}" + LANGUAGES CXX + HOMEPAGE_URL "https://dpp.dev/" + DESCRIPTION "An incredibly lightweight C++ Discord library." ) if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") @@ -82,25 +89,47 @@ if (NOT DPP_NO_VCPKG AND EXISTS "${_VCPKG_ROOT_DIR}") add_subdirectory(library-vcpkg) else() - set(PROJECT_NAME "libdpp") - project( - "${PROJECT_NAME}" - VERSION "${DPP_VERSION}" - LANGUAGES CXX - HOMEPAGE_URL "https://dpp.dev/" - DESCRIPTION "An incredibly lightweight C++ Discord library." - ) - - if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(DPP_CLANG_CL true) + if (NOT DPP_NO_VCPKG AND EXISTS "${_VCPKG_ROOT_DIR}") + set(PROJECT_NAME "dpp") + project( + "${PROJECT_NAME}" + VERSION "${DPP_VERSION}" + LANGUAGES CXX + HOMEPAGE_URL "https://dpp.dev/" + DESCRIPTION "An incredibly lightweight C++ Discord library." + ) + + if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(DPP_CLANG_CL true) + endif() + + # Required before we add any subdirectories. + if (DPP_BUILD_TEST) + enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + add_subdirectory(library-vcpkg) + else() + set(PROJECT_NAME "libdpp") + project( + "${PROJECT_NAME}" + VERSION "${DPP_VERSION}" + LANGUAGES CXX + HOMEPAGE_URL "https://dpp.dev/" + DESCRIPTION "An incredibly lightweight C++ Discord library." + ) + + if (MSVC AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(DPP_CLANG_CL true) + endif() + + # Required before we add any subdirectories. + if (DPP_BUILD_TEST) + enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + add_subdirectory(library) endif() - - # Required before we add any subdirectories. - if (DPP_BUILD_TEST) - enable_testing(${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - add_subdirectory(library) endif() find_package(Filesystem) diff --git a/library-vcpkg/CMakeLists.txt b/library-vcpkg/CMakeLists.txt index 16df61f4f5..5e7b9ae6d7 100644 --- a/library-vcpkg/CMakeLists.txt +++ b/library-vcpkg/CMakeLists.txt @@ -18,14 +18,12 @@ add_compile_definitions(HAVE_VOICE) -file(GLOB THE_SOURCES "${DPP_ROOT_PATH}/src/dpp/events/*.cpp" "${modules_dir}/dpp/voice/enabled/*.cpp" "${DPP_ROOT_PATH}/dpp/dave/*.cpp" "${DPP_ROOT_PATH}/src/dpp/cluster/*.cpp" "${DPP_ROOT_PATH}/src/dpp/*.cpp" "${DPP_ROOT_PATH}/src/dpp/*.rc") +file(GLOB THE_SOURCES "${DPP_ROOT_PATH}/src/dpp/events/*.cpp" "${DPP_ROOT_PATH}/src/dpp/voice/enabled/*.cpp" "${DPP_ROOT_PATH}/src/dpp/dave/*.cpp" "${DPP_ROOT_PATH}/src/dpp/cluster/*.cpp" "${DPP_ROOT_PATH}/src/dpp/*.cpp" "${DPP_ROOT_PATH}/src/dpp/*.rc") set(LIB_NAME "${PROJECT_NAME}") -if(WIN32) - add_library("${LIB_NAME}" SHARED "${THE_SOURCES}") -else() - add_library("${LIB_NAME}" STATIC "${THE_SOURCES}") +add_library("${LIB_NAME}" SHARED "${THE_SOURCES}") +if(NOT WIN32) find_package(Threads REQUIRED) endif() @@ -55,6 +53,8 @@ if(WIN32) set(OPENSSL_VERSION "1.1.1f") endif() + + target_compile_options( "${LIB_NAME}" PUBLIC @@ -62,8 +62,8 @@ target_compile_options( PRIVATE "$<$:$<$:/sdl;/Od;/DEBUG;/MP;/DFD_SETSIZE=1024>>" "$<$:$<$:/O2;/Oi;/Oy;/GL;/Gy;/sdl;/MP;/DFD_SETSIZE=1024>>" - "$<$:$<$:-fPIC;-Wall;-Wempty-body;-Wno-psabi;-Wunknown-pragmas;-Wignored-qualifiers;-Wimplicit-fallthrough;-Wmissing-field-initializers;-Wsign-compare;-Wtype-limits;-Wuninitialized;-Wshift-negative-value;-pthread;-g;-Og;-fPIC>>" - "$<$:$<$:-fPIC;-Wall;-Wempty-body;-Wno-psabi;-Wunknown-pragmas;-Wignored-qualifiers;-Wimplicit-fallthrough;-Wmissing-field-initializers;-Wsign-compare;-Wtype-limits;-Wuninitialized;-Wshift-negative-value;-pthread;-O3;-fPIC>>" + "$<$:$<$:-fPIC;-Wall;-Wempty-body;-Wno-deprecated-declarations;-Wno-psabi;-Wunknown-pragmas;-Wignored-qualifiers;-Wimplicit-fallthrough;-Wmissing-field-initializers;-Wsign-compare;-Wtype-limits;-Wuninitialized;-Wshift-negative-value;-pthread;-g;-Og;-fPIC>>" + "$<$:$<$:-fPIC;-Wall;-Wempty-body;-Wno-deprecated-declarations;-Wno-psabi;-Wunknown-pragmas;-Wignored-qualifiers;-Wimplicit-fallthrough;-Wmissing-field-initializers;-Wsign-compare;-Wtype-limits;-Wuninitialized;-Wshift-negative-value;-pthread;-O3;-fPIC>>" "${AVX_FLAG}" ) @@ -82,6 +82,7 @@ target_include_directories( "$" ) +find_package(OpenSSL REQUIRED) add_subdirectory("${DPP_ROOT_PATH}/mlspp" "mlspp") include_directories("${DPP_ROOT_PATH}/mlspp/include") include_directories("${DPP_ROOT_PATH}/mlspp/lib/bytes/include") @@ -99,8 +100,12 @@ target_link_options( ) find_package(nlohmann_json CONFIG REQUIRED) -find_package(OpenSSL REQUIRED) -find_package(Opus CONFIG REQUIRED) +if (DPP_TEST_VCPKG) + include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/FindOpus.cmake") + find_package(Opus REQUIRED) +else() + find_package(Opus CONFIG REQUIRED) +endif() find_package(ZLIB REQUIRED) target_link_libraries( diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 0cabd74161..840807669d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -291,8 +291,6 @@ foreach (fullmodname ${subdirlist}) 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) diff --git a/mlspp/CMakeLists.txt b/mlspp/CMakeLists.txt index d019e83f39..52f26b5ba6 100755 --- a/mlspp/CMakeLists.txt +++ b/mlspp/CMakeLists.txt @@ -40,7 +40,7 @@ include(CMakePackageConfigHelpers) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - add_compile_options(-Wall) + add_compile_options(-Wall -fPIC) elseif(MSVC) add_compile_options(/W2) add_definitions(-DWINDOWS)