Skip to content

Commit

Permalink
fix: fix broken vcpkg builds which were failing because they were try…
Browse files Browse the repository at this point in the history
…ing to compile as static
  • Loading branch information
braindigitalis committed Oct 16, 2024
1 parent ff22ba4 commit 68b0470
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 41 deletions.
83 changes: 56 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,25 +53,29 @@ 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)
message("-- INFO: Configuring .rc resource script")
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")
Expand All @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions library-vcpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -51,19 +49,20 @@ if(WIN32)
add_compile_definitions(WIN32_LEAN_AND_MEAN)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE)
# Fake an ssl version number to satisfy MLSPP
set(OPENSSL_VERSION "1.1.1f")
endif()

# Fake an ssl version number to satisfy MLSPP
set(OPENSSL_VERSION "1.1.1f")

target_compile_options(
"${LIB_NAME}"
PUBLIC
"$<$<PLATFORM_ID:Windows>:/bigobj;/Zc:preprocessor>"
PRIVATE
"$<$<PLATFORM_ID:Windows>:$<$<CONFIG:Debug>:/sdl;/Od;/DEBUG;/MP;/DFD_SETSIZE=1024>>"
"$<$<PLATFORM_ID:Windows>:$<$<CONFIG:Release>:/O2;/Oi;/Oy;/GL;/Gy;/sdl;/MP;/DFD_SETSIZE=1024>>"
"$<$<PLATFORM_ID:Linux>:$<$<CONFIG:Debug>:-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>>"
"$<$<PLATFORM_ID:Linux>:$<$<CONFIG:Release>:-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>>"
"$<$<PLATFORM_ID:Linux>:$<$<CONFIG:Debug>:-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>>"
"$<$<PLATFORM_ID:Linux>:$<$<CONFIG:Release>:-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}"
)

Expand All @@ -82,6 +81,7 @@ target_include_directories(
"$<INSTALL_INTERFACE:include>"
)

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")
Expand All @@ -99,8 +99,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(
Expand Down
2 changes: 0 additions & 2 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mlspp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68b0470

Please sign in to comment.