mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 08:48:31 +00:00
build: add support for conan and make vendored json optional
This commit is contained in:
parent
de69fd2133
commit
564e9f8d23
5 changed files with 50 additions and 7 deletions
|
@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.5.0)
|
||||||
project(cpp-jwt)
|
project(cpp-jwt)
|
||||||
|
|
||||||
option(CPP_JWT_BUILD_EXAMPLES "build examples" ON)
|
option(CPP_JWT_BUILD_EXAMPLES "build examples" ON)
|
||||||
option(CPP_JWT_BUILD_TESTS "build examples" ON)
|
option(CPP_JWT_BUILD_TESTS "build tests" ON)
|
||||||
|
option(CPP_JWT_USE_VENDORED_NLOHMANN_JSON "use vendored json header" ON)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||||
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
# only set compiler flags if we are the main project, otherwise let the main
|
# only set compiler flags if we are the main project, otherwise let the main
|
||||||
# project decide on the flags
|
# project decide on the flags
|
||||||
|
@ -14,6 +18,10 @@ endif()
|
||||||
|
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
|
|
||||||
|
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
|
find_package(nlohmann_json REQUIRED)
|
||||||
|
endif()
|
||||||
|
|
||||||
# ##############################################################################
|
# ##############################################################################
|
||||||
# LIBRARY
|
# LIBRARY
|
||||||
# ##############################################################################
|
# ##############################################################################
|
||||||
|
@ -24,6 +32,10 @@ target_include_directories(
|
||||||
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
|
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||||
target_link_libraries(${PROJECT_NAME} INTERFACE OpenSSL::SSL)
|
target_link_libraries(${PROJECT_NAME} INTERFACE OpenSSL::SSL)
|
||||||
|
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
|
target_link_libraries(${PROJECT_NAME} INTERFACE nlohmann_json::nlohmann_json)
|
||||||
|
add_definitions(-DCPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
|
endif()
|
||||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
|
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
|
||||||
|
|
||||||
# ##############################################################################
|
# ##############################################################################
|
||||||
|
|
23
README.md
23
README.md
|
@ -209,12 +209,27 @@ Tested with <strong>clang-5.0</strong> and <strong>g++-6.4</strong>.
|
||||||
With issue#12, <strong>VS2017</strong> is also supported.
|
With issue#12, <strong>VS2017</strong> is also supported.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Use the C++ package manager..... just kidding :)
|
|
||||||
This is a header only library, so you can just add it to your include path and start using it. The only somewhat tricky part is to link it with openssl library. Check out the cmake file for building it properly.
|
|
||||||
|
|
||||||
For example one can run cmake like:
|
### using conan
|
||||||
|
|
||||||
|
```shell
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
conan install .. --build missing
|
||||||
|
cmake ..
|
||||||
|
cmake --build . -j
|
||||||
```
|
```
|
||||||
cmake -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2j -DGTEST_ROOT=$HOME/googletest
|
|
||||||
|
### using debian
|
||||||
|
|
||||||
|
```shell
|
||||||
|
sudo apt install nlohmann-json3-dev
|
||||||
|
sudo apt install libgtest-dev
|
||||||
|
sudo apt install libssl-dev
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
cmake --build . -j
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters
|
## Parameters
|
||||||
|
|
10
conanfile.txt
Normal file
10
conanfile.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[requires]
|
||||||
|
gtest/1.10.0
|
||||||
|
nlohmann_json/3.7.0
|
||||||
|
openssl/1.1.1d
|
||||||
|
|
||||||
|
[generators]
|
||||||
|
cmake_find_package
|
||||||
|
cmake_paths
|
||||||
|
|
||||||
|
[options]
|
|
@ -1,7 +1,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#if defined( CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
#include "./json.hpp"
|
#include "./json.hpp"
|
||||||
|
#else
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#endif
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
void basic_json_test()
|
void basic_json_test()
|
||||||
|
|
|
@ -38,8 +38,11 @@ SOFTWARE.
|
||||||
#include "jwt/string_view.hpp"
|
#include "jwt/string_view.hpp"
|
||||||
#include "jwt/parameters.hpp"
|
#include "jwt/parameters.hpp"
|
||||||
#include "jwt/exceptions.hpp"
|
#include "jwt/exceptions.hpp"
|
||||||
|
#if defined(CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||||
#include "jwt/json/json.hpp"
|
#include "jwt/json/json.hpp"
|
||||||
|
#else
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#endif
|
||||||
// For convenience
|
// For convenience
|
||||||
using json_t = nlohmann::json;
|
using json_t = nlohmann::json;
|
||||||
using system_time_t = std::chrono::time_point<std::chrono::system_clock>;
|
using system_time_t = std::chrono::time_point<std::chrono::system_clock>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue