Skip to content

Commit

Permalink
build: allow to disable swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Bycob authored and mergify[bot] committed Jun 14, 2022
1 parent 4dac269 commit d1fd335
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
57 changes: 34 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ OPTION(USE_COMMAND_LINE "build command line JSON API" ON)
OPTION(USE_JSON_API "build internal JSON API" ON)
OPTION(USE_HTTP_SERVER "build cppnet-lib version of http JSON API " OFF)
OPTION(USE_HTTP_SERVER_OATPP "build oatpp version of http JSON API" ON)
OPTION(USE_OATPP_SWAGGER "Enable Swagger documentation endpoint" ON)

# user set variables
set(USE_OPENCV_VERSION CACHE STRING "OpenCV Version used by DeepDetect")
Expand Down Expand Up @@ -1047,44 +1048,54 @@ ExternalProject_Add(
INSTALL_COMMAND ""
DEPENDS oatpp
)
ExternalProject_Add(
oatpp-swagger
PREFIX oatpp-swagger
URL https://github.com/oatpp/oatpp-swagger/archive/${OATPP_SWAGGER_VERSION}.tar.gz
URL_HASH SHA256=56dd44f3b041fe432c27b52f741bb98f1ef97b3c6c4095dc8b9d76e840639ac8
BUILD_IN_SOURCE true
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=OFF
-DOATPP_BUILD_TESTS=OFF
-DOATPP_INSTALL=OFF
-DOATPP_MODULES_LOCATION=CUSTOM
-DOATPP_DIR_SRC=${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
-DOATPP_DIR_LIB=${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
DEPENDS oatpp
)

# FIXME(sileht): we should copy res outside build dir and dynamically looks at runtime at different places
add_definitions("-DOATPP_SWAGGER_RES_PATH=\"${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/res/\"")

set(OATPP_LIB_DEPS
${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src/liboatpp.a
${CMAKE_BINARY_DIR}/oatpp-zlib/src/oatpp-zlib/src/liboatpp-zlib.a
${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src/liboatpp-swagger.a
z # zlib
)
include_directories(
SYSTEM ${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
SYSTEM ${CMAKE_BINARY_DIR}/oatpp-zlib/src/oatpp-zlib/src
SYSTEM ${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src
)
set(OATPP_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
${CMAKE_BINARY_DIR}/oatpp-zlib/src/oatpp-zlib/src
${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src
)

if(USE_OATPP_SWAGGER)
ExternalProject_Add(
oatpp-swagger
PREFIX oatpp-swagger
URL https://github.com/oatpp/oatpp-swagger/archive/${OATPP_SWAGGER_VERSION}.tar.gz
URL_HASH SHA256=56dd44f3b041fe432c27b52f741bb98f1ef97b3c6c4095dc8b9d76e840639ac8
BUILD_IN_SOURCE true
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=OFF
-DOATPP_BUILD_TESTS=OFF
-DOATPP_INSTALL=OFF
-DOATPP_MODULES_LOCATION=CUSTOM
-DOATPP_DIR_SRC=${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
-DOATPP_DIR_LIB=${CMAKE_BINARY_DIR}/oatpp/src/oatpp/src
DEPENDS oatpp
)

list(APPEND OATPP_LIB_DEPS
${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src/liboatpp-swagger.a
)
include_directories(
SYSTEM ${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src
)
list(APPEND OATPP_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/src
)
# FIXME(sileht): we should copy res outside build dir and dynamically looks at runtime at different places
add_definitions("-DUSE_OATPP_SWAGGER")
add_definitions("-DOATPP_SWAGGER_RES_PATH=\"${CMAKE_BINARY_DIR}/oatpp-swagger/src/oatpp-swagger/res/\"")
endif()

if (USE_HTTP_SERVER)
ExternalProject_Add(
cpp-netlib
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ if (USE_HTTP_SERVER)
add_dependencies(ddetect cpp-netlib)
endif()
if (USE_HTTP_SERVER_OATPP)
add_dependencies(ddetect oatpp oatpp-swagger oatpp-zlib)
add_dependencies(ddetect oatpp oatpp-zlib)
if (USE_OATPP_SWAGGER)
add_dependencies(ddetect oatpp-swagger)
endif()
endif()
if (BUILD_SPDLOG)
add_dependencies(ddetect spdlog)
Expand Down
4 changes: 4 additions & 0 deletions src/http/app_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

#include "http/access_log.hpp"
#include "http/error_handler.hpp"
#ifdef USE_OATPP_SWAGGER
#include "http/swagger_component.hpp"
#endif

#include <gflags/gflags.h>

Expand All @@ -53,10 +55,12 @@ class AppComponent
AppComponent(const std::shared_ptr<spdlog::logger> &logger)
: _logger(logger){};

#ifdef USE_OATPP_SWAGGER
/**
* Swagger component
*/
SwaggerComponent swaggerComponent;
#endif

/**
* Create ObjectMapper component to serialize/deserialize DTOs in Contoller's
Expand Down
5 changes: 4 additions & 1 deletion src/oatppjsonapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/core/macro/component.hpp"
#ifdef USE_OATPP_SWAGGER
#include "oatpp-swagger/Controller.hpp"
#endif

#include "utils/oatpp.hpp"

Expand Down Expand Up @@ -342,6 +344,7 @@ namespace dd
= DedeController::createShared(this, defaultObjectMapper);
dedeController->addEndpointsToRouter(router);

#ifdef USE_OATPP_SWAGGER
// Initialize swagger
auto docEndpoints = oatpp::swagger::Controller::Endpoints::createShared();
docEndpoints->pushBackAll(dedeController->getEndpoints());
Expand Down Expand Up @@ -371,7 +374,7 @@ namespace dd
auto swaggerController = std::make_shared<oatpp::swagger::Controller>(
swaggerMapper, document, resources);
swaggerController->addEndpointsToRouter(router);
// ===
#endif

auto scp = components.serverConnectionProvider.getObject();
auto sch = components.serverConnectionHandler.getObject();
Expand Down

0 comments on commit d1fd335

Please sign in to comment.