diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f35431..3f9282f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.5.0) -project(cpp-jwt VERSION 1.2.0) +cmake_minimum_required(VERSION 3.14.0) +project(cpp-jwt VERSION 1.5.0) option(CPP_JWT_BUILD_EXAMPLES "build examples" ON) option(CPP_JWT_BUILD_TESTS "build tests" ON) @@ -43,7 +43,7 @@ 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) else() - add_definitions(-DCPP_JWT_USE_VENDORED_NLOHMANN_JSON) + target_compile_definitions(${PROJECT_NAME} INTERFACE CPP_JWT_USE_VENDORED_NLOHMANN_JSON) endif() target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) @@ -90,30 +90,27 @@ install( NAMESPACE ${PROJECT_NAME}:: COMPONENT dev) configure_package_config_file(cmake/Config.cmake.in ${PROJECT_NAME}Config.cmake - INSTALL_DESTINATION ${CPP_JWT_CONFIG_INSTALL_DIR}) + PATH_VARS CPP_JWT_CONFIG_INSTALL_DIR + INSTALL_DESTINATION ${CPP_JWT_CONFIG_INSTALL_DIR} + NO_SET_AND_CHECK_MACRO) write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake - COMPATIBILITY SameMajorVersion) + COMPATIBILITY SameMajorVersion + ARCH_INDEPENDENT) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake DESTINATION ${CPP_JWT_CONFIG_INSTALL_DIR} COMPONENT dev) -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/detail - DESTINATION include/jwt - COMPONENT dev) -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/impl - DESTINATION include/jwt - COMPONENT dev) -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/json - DESTINATION include/jwt - COMPONENT dev) +if(NOT CPP_JWT_USE_VENDORED_NLOHMANN_JSON) + set(CPP_JWT_VENDORED_NLOHMANN_JSON_INSTALL_PATTERN PATTERN "json" EXCLUDE) +endif() install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/jwt/ DESTINATION include/jwt COMPONENT dev FILES_MATCHING - PATTERN "*.hpp") + PATTERN "*.hpp" + PATTERN "*.ipp" + PATTERN "test" EXCLUDE + ${CPP_JWT_VENDORED_NLOHMANN_JSON_INSTALL_PATTERN}) diff --git a/README.md b/README.md index 479a233..5769263 100644 --- a/README.md +++ b/README.md @@ -136,16 +136,16 @@ Few good resources on this material which I found useful are: //Most APIs have an overload which takes enum class type as well //It can be used interchangeably with strings. obj.remove_claim(jwt::registered_claims::expiration); - assert (not obj.has_claim("exp")); + assert (!obj.has_claim("exp")); //Using `add_claim` with extra features. //Check return status and overwrite bool ret = obj.payload().add_claim("sub", "new test", false/*overwrite*/); - assert (not ret); + assert (!ret); // Overwrite an existing claim ret = obj.payload().add_claim("sub", "new test", true/*overwrite*/); - assert ( ret ); + assert (ret); assert (obj.payload().has_claim_with_value("sub", "new test")); @@ -234,7 +234,7 @@ cmake --build . -j ## Consuming the library -this library is uses cmake as a build system. +This library is uses cmake as a build system. ```cmake # you can use cmake's `find_package` after installation or `add_subdirectory` when vendoring this repository @@ -246,8 +246,10 @@ add_executable(main main.cpp) target_link_libraries(main cpp-jwt::cpp-jwt) ``` -you can also use this library as a conan package, its available in the [conan center](https://conan.io/center/cpp-jwt/1.2/?user=_&channel=_): -just add `cpp-jwt[>=1.2]` to your conanfile.txt +You can also use this library as a conan package, its available in the [conan center](https://conan.io/center/cpp-jwt): +just add `cpp-jwt[>=1.2]` to your conanfile.txt. + +It can also be installed using [vcpkg](https://github.com/microsoft/vcpkg) by adding `"cpp-jwt"` to the dependencies in your `vcpkg.json` file. ## Parameters There are two sets of parameters which can be used for creating `jwt_object` and for decoding. diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 8138918..4cf7087 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -6,5 +6,5 @@ endif() find_package(OpenSSL REQUIRED) -include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +include("@PACKAGE_CPP_JWT_CONFIG_INSTALL_DIR@/@PROJECT_NAME@Targets.cmake") check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/examples/simple_ex2.cc b/examples/simple_ex2.cc index a223f9d..d906a62 100644 --- a/examples/simple_ex2.cc +++ b/examples/simple_ex2.cc @@ -33,11 +33,11 @@ int main() { //Most APIs have an overload which takes enum class type as well //It can be used interchangeably with strings. obj.remove_claim(jwt::registered_claims::expiration); - assert (not obj.has_claim("exp")); + assert (!obj.has_claim("exp")); //Using `add_claim` with extra features. //Check return status and overwrite - assert (not obj.payload().add_claim("sub", "new test", false/*overwrite*/)); + assert (!obj.payload().add_claim("sub", "new test", false/*overwrite*/)); // Overwrite an existing claim assert (obj.payload().add_claim("sub", "new test", true/*overwrite*/)); diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..a8a3bed --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,11 @@ +{ + "name": "cpp-jwt", + "version": "1.5", + "description": "JSON Web Token library for C++", + "homepage": "https://github.com/arun11299/cpp-jwt", + "dependencies": [ + "nlohmann-json", + "openssl", + "gtest" + ] +}