Skip to content

Commit a1cb15a

Browse files
committed
feat: add webhooks
1 parent 49f0961 commit a1cb15a

File tree

24 files changed

+1092
-120
lines changed

24 files changed

+1092
-120
lines changed

.gitignore

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
**/*.deb
22
**/*.rpm
3+
**/*.exe
4+
**/*.obj
5+
*.cmake
36
.idea
7+
48
cmake-build-debug/
9+
CMakePresets.json
510

611
.vscode/
712
include/dpp/
8-
build/
9-
deps/
13+
include/cpp-httplib/
14+
include/drogon/
15+
include/nlohmann/
16+
**/build/
17+
**/*.dll
18+
**/*.lib
1019
docs/html/
1120

12-
test.exe
13-
test.obj
21+
cpp-httplib/
22+
json/
23+
24+
conan_toolchain.cmake
25+
*conan*.bat

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "docs/doxygen-awesome-css"]
22
path = docs/doxygen-awesome-css
33
url = https://github.com/jothepro/doxygen-awesome-css.git
4+
[submodule "deps/drogon"]
5+
path = deps/drogon
6+
url = https://github.com/drogonframework/drogon.git

CMakeLists.txt

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.10)
1+
cmake_minimum_required(VERSION 3.15)
22

33
project(
44
topgg
@@ -10,24 +10,37 @@ project(
1010
set(CMAKE_VERBOSE_MAKEFILE ON)
1111
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
1212
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
13+
1314
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
14-
option(ENABLE_CORO "Support for C++20 coroutines" OFF)
15+
option(ENABLE_API "Build primary API support" ON)
16+
option(ENABLE_CPP_HTTPLIB_WEBHOOKS "Build support for webhooks via cpp-httplib" OFF)
17+
option(ENABLE_DROGON_WEBHOOKS "Build support for webhooks via drogon" OFF)
18+
option(ENABLE_CORO "Add support for C++20 coroutines" OFF)
1519
option(TESTING "Enable this only if you are testing the library" OFF)
1620

21+
if(ENABLE_API)
1722
file(GLOB TOPGG_SOURCE_FILES src/*.cpp)
23+
endif()
24+
25+
if(ENABLE_CPP_HTTPLIB_WEBHOOKS)
26+
set(TOPGG_SOURCE_FILES ${TOPGG_SOURCE_FILES} src/webhooks/cpp-httplib.cpp src/webhooks/models.cpp)
27+
elseif(ENABLE_DROGON_WEBHOOKS)
28+
set(TOPGG_SOURCE_FILES ${TOPGG_SOURCE_FILES} src/webhooks/drogon.cpp src/webhooks/models.cpp)
29+
endif()
1830

1931
if(BUILD_SHARED_LIBS)
2032
add_library(topgg SHARED ${TOPGG_SOURCE_FILES})
2133

2234
if(WIN32)
23-
target_sources(topgg PRIVATE ${CMAKE_SOURCE_DIR}/topgg.rc)
35+
target_sources(topgg PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/topgg.rc)
36+
target_compile_definitions(topgg PRIVATE __TOPGG_BUILDING_DLL__)
2437
endif()
2538
else()
2639
add_library(topgg STATIC ${TOPGG_SOURCE_FILES})
27-
endif()
2840

2941
if(WIN32)
30-
target_compile_definitions(topgg PRIVATE $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,__TOPGG_BUILDING_DLL__,DPP_STATIC TOPGG_STATIC>)
42+
target_compile_definitions(topgg PUBLIC DPP_STATIC TOPGG_STATIC)
43+
endif()
3144
endif()
3245

3346
if(ENABLE_CORO)
@@ -42,24 +55,88 @@ target_compile_definitions(topgg PRIVATE __TOPGG_TESTING__)
4255
endif()
4356

4457
set_target_properties(topgg PROPERTIES
45-
OUTPUT_NAME topgg
4658
CXX_STANDARD ${TOPGG_CXX_STANDARD}
4759
CXX_STANDARD_REQUIRED ON
4860
)
4961

50-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
62+
if(ENABLE_API)
63+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
5164

5265
find_package(DPP REQUIRED)
66+
endif()
67+
68+
if(ENABLE_CPP_HTTPLIB_WEBHOOKS)
69+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/cpp-httplib/cpp-httplib.h")
70+
execute_process(COMMAND git clone https://github.com/yhirose/cpp-httplib.git --depth 1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
71+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/cpp-httplib")
72+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/cpp-httplib")
73+
endif()
74+
file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/cpp-httplib/httplib.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/cpp-httplib/httplib.h")
75+
file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/cpp-httplib")
76+
endif()
77+
78+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/nlohmann/json.hpp")
79+
execute_process(COMMAND git clone https://github.com/nlohmann/json.git --depth 1 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
80+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/nlohmann")
81+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/nlohmann")
82+
endif()
83+
file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/json/single_include/nlohmann/json.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/nlohmann/json.hpp")
84+
file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/json")
85+
endif()
86+
endif()
87+
88+
if(ENABLE_DROGON_WEBHOOKS)
89+
if(WIN32)
90+
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/conan_toolchain.cmake")
91+
92+
include(${CMAKE_CURRENT_SOURCE_DIR}/conan_toolchain.cmake)
93+
endif()
94+
95+
set(DROGON_LIBRARY drogon)
96+
97+
set(
98+
TRANTOR_INCLUDE_DIR
99+
"${CMAKE_CURRENT_SOURCE_DIR}/deps/drogon/trantor"
100+
"${CMAKE_BINARY_DIR}/deps/drogon/trantor/exports"
101+
)
102+
103+
set(
104+
DROGON_INCLUDE_DIR
105+
"${CMAKE_CURRENT_SOURCE_DIR}/deps/drogon/lib/inc"
106+
"${CMAKE_CURRENT_SOURCE_DIR}/deps/drogon/orm_lib/inc"
107+
"${CMAKE_CURRENT_SOURCE_DIR}/deps/drogon/nosql_lib/redis/inc"
108+
"${CMAKE_BINARY_DIR}/deps/drogon/exports"
109+
)
110+
111+
set(BUILD_CTL OFF)
112+
set(BUILD_EXAMPLES OFF)
113+
set(BUILD_BROTLI OFF)
114+
set(BUILD_YAML_CONFIG OFF)
115+
set(USE_SUBMODULE ON)
116+
117+
add_subdirectory(deps/drogon)
118+
119+
target_compile_definitions(topgg PRIVATE __TOPGG_DROGON_WEBHOOKS__)
120+
121+
if(WIN32)
122+
target_compile_definitions(topgg PRIVATE _CRT_SECURE_NO_WARNINGS)
123+
cmake_policy(SET CMP0091 NEW)
124+
endif()
125+
endif()
53126

54127
if(MSVC)
55-
target_compile_options(topgg PUBLIC $<$<CONFIG:Debug>:/diagnostics:caret /MTd /DDEBUG /D_DEBUG> $<$<CONFIG:Release>:/MT /O2 /Oi /Oy /Gy /DNDEBUG>)
128+
target_compile_options(topgg PRIVATE /nologo $<$<CONFIG:Debug>:/diagnostics:caret /MDd /DDEBUG /D_DEBUG> $<$<CONFIG:Release>:/MD /O2 /Oi /Oy /Gy /DNDEBUG>)
56129
else()
57-
target_compile_options(topgg PUBLIC $<$<CONFIG:Release>:-O3> -Wall -Wextra -Wpedantic -Wformat=2 -Wnull-dereference -Wuninitialized -Wdeprecated)
130+
target_compile_options(topgg PRIVATE $<$<CONFIG:Release>:-O3> -Wall -Wextra -Wpedantic -Wformat=2 -Wnull-dereference -Wuninitialized -Wdeprecated)
58131
endif()
59132

60133
target_include_directories(topgg PUBLIC
61-
${CMAKE_SOURCE_DIR}/include
134+
${CMAKE_CURRENT_SOURCE_DIR}/include
62135
${DPP_INCLUDE_DIR}
136+
${JSONCPP_INCLUDE_DIRS}
137+
${ZLIB_INCLUDE_DIR}
138+
${TRANTOR_INCLUDE_DIR}
139+
${DROGON_INCLUDE_DIR}
63140
)
64141

65-
target_link_libraries(topgg ${DPP_LIBRARIES})
142+
target_link_libraries(topgg PUBLIC ${DPP_LIBRARIES} ${JSONCPP_LIBRARIES} ${DROGON_LIBRARY})

0 commit comments

Comments
 (0)