1- cmake_minimum_required (VERSION 3.10 )
1+ cmake_minimum_required (VERSION 3.15 )
22
33project (
44 topgg
@@ -10,24 +10,37 @@ project(
1010set (CMAKE_VERBOSE_MAKEFILE ON )
1111set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
1212set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type" )
13+
1314option (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 )
1519option (TESTING "Enable this only if you are testing the library" OFF )
1620
21+ if (ENABLE_API)
1722file (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
1931if (BUILD_SHARED_LIBS )
2032add_library (topgg SHARED ${TOPGG_SOURCE_FILES} )
2133
2234if (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__)
2437endif ()
2538else ()
2639add_library (topgg STATIC ${TOPGG_SOURCE_FILES} )
27- endif ()
2840
2941if (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 ()
3144endif ()
3245
3346if (ENABLE_CORO)
@@ -42,24 +55,88 @@ target_compile_definitions(topgg PRIVATE __TOPGG_TESTING__)
4255endif ()
4356
4457set_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
5265find_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
54127if (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>)
56129else ()
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)
58131endif ()
59132
60133target_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