mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Merge pull request #59 from gocarlos/master
build: improve cmake scripts
This commit is contained in:
commit
8a066c9823
9 changed files with 270 additions and 55 deletions
72
.github/workflows/main.yml
vendored
Normal file
72
.github/workflows/main.yml
vendored
Normal file
|
@ -0,0 +1,72 @@
|
|||
name: CMake
|
||||
|
||||
on: [push]
|
||||
|
||||
env:
|
||||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
|
||||
BUILD_TYPE: RelWithDebInfo
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: "3.x"
|
||||
|
||||
- name: Install tools (Linux)
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
run: |
|
||||
sudo apt-get install python3-setuptools python3-wheel python3-pip
|
||||
shell: bash
|
||||
|
||||
- name: Install conan (Linux)
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
run: |
|
||||
sudo pip3 install conan --upgrade
|
||||
shell: bash
|
||||
|
||||
- name: Install conan (Windows)
|
||||
if: startsWith(runner.os, 'Windows')
|
||||
run: |
|
||||
pip3 install conan --upgrade
|
||||
shell: bash
|
||||
|
||||
- name: Create Build Environment
|
||||
run: cmake -E make_directory ${{runner.workspace}}/build
|
||||
|
||||
- name: Install conan profile
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: conan profile new default --detect
|
||||
|
||||
- name: Use cpp 11 (Linux)
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
run: |
|
||||
conan profile update settings.compiler.libcxx=libstdc++11 default
|
||||
shell: bash
|
||||
|
||||
- name: Install conan dependencies
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: conan install $GITHUB_WORKSPACE --build missing
|
||||
shell: bash
|
||||
|
||||
- name: Configure CMake
|
||||
shell: bash
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
|
||||
- name: Build
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
shell: bash
|
||||
run: cmake --build . --config $BUILD_TYPE
|
||||
|
||||
- name: Test
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
shell: bash
|
||||
run: ctest --verbose
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build/
|
103
CMakeLists.txt
103
CMakeLists.txt
|
@ -1,26 +1,95 @@
|
|||
# CMakeLists files in this project can
|
||||
# refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
|
||||
# to the root binary directory of the project as ${HELLO_BINARY_DIR}.
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(cpp-jwt)
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.11)
|
||||
project (cpp-jwt)
|
||||
option(CPP_JWT_BUILD_EXAMPLES "build examples" ON)
|
||||
option(CPP_JWT_BUILD_TESTS "build tests" ON)
|
||||
option(CPP_JWT_USE_VENDORED_NLOHMANN_JSON "use vendored json header" ON)
|
||||
|
||||
#SET (CMAKE_CXX_COMPILER /usr/local/bin/g++)
|
||||
SET( CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra" )
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
include_directories (include)
|
||||
# only set compiler flags if we are the main project, otherwise let the main
|
||||
# project decide on the flags
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}"
|
||||
MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||
endif()
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
endif()
|
||||
|
||||
enable_testing()
|
||||
# ##############################################################################
|
||||
# LIBRARY
|
||||
# ##############################################################################
|
||||
|
||||
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually
|
||||
# cause another cmake executable to run. The same process will walk through
|
||||
# the project's entire directory structure.
|
||||
add_subdirectory (tests)
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(
|
||||
${PROJECT_NAME}
|
||||
INTERFACE $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
${OpenSSL_INCLUDE_DIR})
|
||||
target_link_libraries(${PROJECT_NAME} INTERFACE ${OpenSSL_LIBRARIES})
|
||||
if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
target_link_libraries(${PROJECT_NAME} INTERFACE nlohmann_json::nlohmann_json)
|
||||
else()
|
||||
add_definitions(-DCPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
endif()
|
||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14)
|
||||
|
||||
add_subdirectory (examples)
|
||||
# ##############################################################################
|
||||
# TESTS
|
||||
# ##############################################################################
|
||||
|
||||
if(CPP_JWT_BUILD_TESTS)
|
||||
find_package(GTest REQUIRED)
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
enable_testing()
|
||||
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually
|
||||
# cause another cmake executable to run. The same process will walk through
|
||||
# the project's entire directory structure.
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# EXAMPLES
|
||||
# ##############################################################################
|
||||
|
||||
if(CPP_JWT_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# INSTALL
|
||||
# ##############################################################################
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}_Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/detail
|
||||
DESTINATION include/jwt)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/impl
|
||||
DESTINATION include/jwt)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/json
|
||||
DESTINATION include/jwt)
|
||||
install(
|
||||
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/
|
||||
DESTINATION include/jwt
|
||||
FILES_MATCHING
|
||||
PATTERN "*.hpp")
|
||||
|
|
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.
|
||||
|
||||
## 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
|
||||
|
|
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,18 +1,24 @@
|
|||
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
SET(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rsa_256")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"")
|
||||
set(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rsa_256")
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"")
|
||||
|
||||
add_executable(simple_ex1 simple_ex1.cc)
|
||||
target_link_libraries(simple_ex1 ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME simple_ex1 COMMAND ./simple_ex1 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(simple_ex1 ${PROJECT_NAME})
|
||||
add_test(
|
||||
NAME simple_ex1
|
||||
COMMAND ./simple_ex1
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(simple_ex2 simple_ex2.cc)
|
||||
target_link_libraries(simple_ex2 ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME simple_ex2 COMMAND ./simple_ex2 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(simple_ex2 ${PROJECT_NAME})
|
||||
add_test(
|
||||
NAME simple_ex2
|
||||
COMMAND ./simple_ex2
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(simple_ex3_rsa simple_ex3_rsa.cc)
|
||||
target_link_libraries(simple_ex3_rsa ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME simple_ex3_rsa COMMAND ./simple_ex3_rsa WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
target_link_libraries(simple_ex3_rsa ${PROJECT_NAME})
|
||||
add_test(
|
||||
NAME simple_ex3_rsa
|
||||
COMMAND ./simple_ex3_rsa
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#if defined( CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
#include "./json.hpp"
|
||||
|
||||
#else
|
||||
#include "nlohmann/json.hpp"
|
||||
#endif
|
||||
using json = nlohmann::json;
|
||||
|
||||
void basic_json_test()
|
||||
|
|
|
@ -38,8 +38,11 @@ SOFTWARE.
|
|||
#include "jwt/string_view.hpp"
|
||||
#include "jwt/parameters.hpp"
|
||||
#include "jwt/exceptions.hpp"
|
||||
#if defined(CPP_JWT_USE_VENDORED_NLOHMANN_JSON)
|
||||
#include "jwt/json/json.hpp"
|
||||
|
||||
#else
|
||||
#include "nlohmann/json.hpp"
|
||||
#endif
|
||||
// For convenience
|
||||
using json_t = nlohmann::json;
|
||||
using system_time_t = std::chrono::time_point<std::chrono::system_clock>;
|
||||
|
|
|
@ -1,33 +1,69 @@
|
|||
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
SET(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/certs")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"")
|
||||
set(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/certs")
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"")
|
||||
|
||||
add_executable(test_jwt_object test_jwt_object.cc)
|
||||
target_link_libraries(test_jwt_object ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_object COMMAND ./test_jwt_object WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_object ${GTest_LIBRARIES} ${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_object PRIVATE ${GTEST_INCLUDE_DIRS}
|
||||
${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_object
|
||||
COMMAND ./test_jwt_object
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_encode test_jwt_encode.cc)
|
||||
target_link_libraries(test_jwt_encode ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_encode COMMAND ./test_jwt_encode WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_encode ${GTest_LIBRARIES} ${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_encode PRIVATE ${GTEST_INCLUDE_DIRS}
|
||||
${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_encode
|
||||
COMMAND ./test_jwt_encode
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_decode test_jwt_decode.cc)
|
||||
target_link_libraries(test_jwt_decode ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_decode COMMAND ./test_jwt_decode WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_decode ${GTest_LIBRARIES} ${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_decode PRIVATE ${GTEST_INCLUDE_DIRS}
|
||||
${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_decode
|
||||
COMMAND ./test_jwt_decode
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_decode_verifiy test_jwt_decode_verifiy.cc)
|
||||
target_link_libraries(test_jwt_decode_verifiy ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_decode_verifiy COMMAND ./test_jwt_decode_verifiy WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_decode_verifiy ${GTest_LIBRARIES}
|
||||
${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_decode_verifiy
|
||||
PRIVATE ${GTEST_INCLUDE_DIRS} ${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_decode_verifiy
|
||||
COMMAND ./test_jwt_decode_verifiy
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_decode_verifiy_with_exception test_jwt_decode_verifiy_with_exception.cc)
|
||||
target_link_libraries(test_jwt_decode_verifiy_with_exception ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_decode_verifiy_with_exception COMMAND ./test_jwt_decode_verifiy_with_exception WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
add_executable(test_jwt_decode_verifiy_with_exception
|
||||
test_jwt_decode_verifiy_with_exception.cc)
|
||||
target_link_libraries(test_jwt_decode_verifiy_with_exception ${GTest_LIBRARIES}
|
||||
${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_decode_verifiy_with_exception
|
||||
PRIVATE ${GTEST_INCLUDE_DIRS} ${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_decode_verifiy_with_exception
|
||||
COMMAND ./test_jwt_decode_verifiy_with_exception
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_rsa test_jwt_rsa.cc)
|
||||
target_link_libraries(test_jwt_rsa ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES} )
|
||||
add_test(NAME test_jwt_rsa COMMAND ./test_jwt_rsa WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_rsa ${GTest_LIBRARIES} ${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_rsa PRIVATE ${GTEST_INCLUDE_DIRS}
|
||||
${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_rsa
|
||||
COMMAND ./test_jwt_rsa
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
add_executable(test_jwt_es test_jwt_es.cc)
|
||||
target_link_libraries(test_jwt_es ${OPENSSL_LIBRARIES} ${GTEST_LIBRARIES})
|
||||
add_test(NAME test_jwt_es COMMAND ./test_jwt_es WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
target_link_libraries(test_jwt_es ${GTest_LIBRARIES} ${PROJECT_NAME})
|
||||
target_include_directories(test_jwt_es PRIVATE ${GTEST_INCLUDE_DIRS}
|
||||
${GTest_INCLUDE_DIRS})
|
||||
add_test(
|
||||
NAME test_jwt_es
|
||||
COMMAND ./test_jwt_es
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue