-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: resolve build issues and update gitignore #11
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,79 @@ | ||
cmake_minimum_required(VERSION 3.8.2) | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
project( | ||
topgg | ||
VERSION 1.0.0 | ||
LANGUAGES CXX | ||
HOMEPAGE_URL "https://docs.top.gg/docs" | ||
DESCRIPTION "The official C++ wrapper for the Top.gg API." | ||
) | ||
|
||
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type") | ||
option(BUILD_SHARED_LIBS "Build shared libraries" ON) | ||
option(ENABLE_CORO "Support for C++20 coroutines" OFF) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
set(DPP_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/deps/dpp") | ||
list(APPEND CMAKE_PREFIX_PATH "${DPP_ROOT}") | ||
|
||
file(GLOB TOPGG_SOURCE_FILES src/*.cpp) | ||
find_package(DPP REQUIRED) | ||
include(FetchContent) | ||
FetchContent_Declare(json | ||
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz | ||
) | ||
FetchContent_MakeAvailable(json) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
add_library(topgg SHARED ${TOPGG_SOURCE_FILES}) | ||
set(TOPGG_SOURCES | ||
src/client.cpp | ||
src/webhook.cpp | ||
src/models.cpp | ||
src/result.cpp | ||
) | ||
|
||
if(WIN32) | ||
target_sources(topgg PRIVATE ${CMAKE_SOURCE_DIR}/topgg.rc) | ||
endif() | ||
else() | ||
add_library(topgg STATIC ${TOPGG_SOURCE_FILES}) | ||
endif() | ||
add_library(topgg STATIC ${TOPGG_SOURCES}) | ||
|
||
if(WIN32) | ||
target_compile_definitions(topgg PRIVATE $<$<BOOL:${BUILD_SHARED_LIBS}>:__TOPGG_BUILDING_DLL__:DPP_STATIC TOPGG_STATIC>) | ||
endif() | ||
target_compile_definitions(topgg PUBLIC TOPGG_STATIC_DEFINE) | ||
target_include_directories(topgg PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
if(ENABLE_CORO) | ||
set(TOPGG_CXX_STANDARD 20) | ||
target_compile_definitions(topgg PUBLIC DPP_CORO=ON) | ||
else() | ||
set(TOPGG_CXX_STANDARD 17) | ||
endif() | ||
target_link_libraries(topgg PUBLIC DPP::DPP nlohmann_json::nlohmann_json) | ||
|
||
set_target_properties(topgg PROPERTIES | ||
OUTPUT_NAME topgg | ||
CXX_STANDARD ${TOPGG_CXX_STANDARD} | ||
CXX_STANDARD_REQUIRED ON | ||
enable_testing() | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip | ||
) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
add_executable(topgg_tests | ||
tests/client_test.cpp | ||
tests/webhook_test.cpp | ||
tests/models_test.cpp | ||
) | ||
|
||
find_package(DPP REQUIRED) | ||
target_link_libraries(topgg_tests PRIVATE | ||
topgg | ||
GTest::gtest_main | ||
GTest::gmock | ||
DPP::DPP | ||
) | ||
|
||
if(MSVC) | ||
target_compile_options(topgg PUBLIC $<$<CONFIG:Debug>:/diagnostics:caret /MTd> $<$<CONFIG:Release>:/MT /O2 /Oi /Oy /Gy>) | ||
else() | ||
target_compile_options(topgg PUBLIC $<$<CONFIG:Release>:-O3> -Wall -Wextra -Wpedantic -Wformat=2 -Wnull-dereference -Wuninitialized -Wdeprecated) | ||
endif() | ||
target_include_directories(topgg_tests PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
) | ||
|
||
target_include_directories(topgg PUBLIC | ||
${CMAKE_SOURCE_DIR}/include | ||
${DPP_INCLUDE_DIR} | ||
add_test(NAME topgg_tests COMMAND topgg_tests) | ||
|
||
add_custom_command(TARGET topgg_tests POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
"${DPP_ROOT}/lib/dpp.dll" | ||
$<TARGET_FILE_DIR:topgg_tests> | ||
) | ||
|
||
set_tests_properties(topgg_tests PROPERTIES | ||
ENVIRONMENT "PATH=${DPP_ROOT}/lib;${CMAKE_CURRENT_BINARY_DIR}/Release;$ENV{PATH}" | ||
) | ||
|
||
target_link_libraries(topgg ${DPP_LIBRARIES}) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
if(WIN32 AND NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/dpp.lib) | ||
string(TOLOWER ${CMAKE_BUILD_TYPE} INSTALL_DPP_BUILD_TYPE) | ||
execute_process(COMMAND powershell "-NoLogo" "-NoProfile" "-File" ".\\install_dpp_msvc.ps1" ${INSTALL_DPP_BUILD_TYPE} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PS: I removed every DPP-related installation scripts because I cannot and don't know how to build it using that on Windows. It shows too much build errors when I first ran it, I don't know if I did something wrong or something. That was the first time I cloned the repository btw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh? but it worked for me... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you show me what the errors are? |
||
endif() | ||
# FindDPP.cmake | ||
|
||
if(APPLE) | ||
find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS "/opt/homebrew/include") | ||
find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS "/opt/homebrew/lib") | ||
else() | ||
find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS ${CMAKE_SOURCE_DIR}/include) | ||
find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS ${CMAKE_SOURCE_DIR}/deps) | ||
endif() | ||
message(STATUS "DPP_ROOT is set to: ${DPP_ROOT}") | ||
|
||
# Find DPP library | ||
find_library(DPP_LIBRARY | ||
NAMES dpp dpp.lib libdpp | ||
PATHS | ||
"${DPP_ROOT}/lib" | ||
"${DPP_ROOT}/lib/Release" | ||
"${DPP_ROOT}/lib/Debug" | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
message(STATUS "DPP_LIBRARY found at: ${DPP_LIBRARY}") | ||
|
||
# Find DPP headers | ||
find_path(DPP_INCLUDE_DIR | ||
NAMES dpp/dpp.h | ||
PATHS "${DPP_ROOT}/include" | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
message(STATUS "DPP_INCLUDE_DIR found at: ${DPP_INCLUDE_DIR}") | ||
|
||
get_filename_component(DPP_LIBRARY_DIR ${DPP_LIBRARY} DIRECTORY) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR) | ||
find_package_handle_standard_args(DPP | ||
REQUIRED_VARS DPP_LIBRARY DPP_INCLUDE_DIR | ||
) | ||
|
||
if(DPP_FOUND AND NOT TARGET DPP::DPP) | ||
add_library(DPP::DPP UNKNOWN IMPORTED) | ||
set_target_properties(DPP::DPP PROPERTIES | ||
IMPORTED_LOCATION "${DPP_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${DPP_INCLUDE_DIR}" | ||
) | ||
endif() | ||
|
||
mark_as_advanced(DPP_INCLUDE_DIR DPP_LIBRARY) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,7 @@ | |
*/ | ||
|
||
#pragma once | ||
|
||
#include <topgg/topgg.h> | ||
|
||
#include <functional> | ||
#include <vector> | ||
#include <string> | ||
#include <map> | ||
#include "topgg/export.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this should've been There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
|
||
namespace topgg { | ||
/** | ||
|
@@ -87,7 +81,7 @@ namespace topgg { | |
* | ||
* @since 2.0.0 | ||
*/ | ||
class TOPGG_EXPORT client { | ||
class TOPGG_API client { | ||
std::multimap<std::string, std::string> m_headers; | ||
std::string m_token; | ||
dpp::cluster& m_cluster; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#if defined(TOPGG_STATIC_DEFINE) | ||
#define TOPGG_API | ||
#else | ||
#ifdef _MSC_VER | ||
#ifdef TOPGG_EXPORTS | ||
#define TOPGG_API __declspec(dllexport) | ||
#else | ||
#define TOPGG_API __declspec(dllimport) | ||
#endif | ||
#else | ||
#define TOPGG_API | ||
#endif | ||
#endif | ||
|
||
// Add macro for unused variables in catch blocks | ||
#if defined(__GNUC__) || defined(__clang__) | ||
#define TOPGG_UNUSED __attribute__((unused)) | ||
#else | ||
#define TOPGG_UNUSED | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove
ENABLE_CORO
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option lets users of this library choose whether to utilize C++20 coroutines or not (done through callbacks, but compatible with C++17).