-
-
Notifications
You must be signed in to change notification settings - Fork 310
Support for C++20/23 modules #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DockedFerret800
wants to merge
15
commits into
Thalhammer:master
Choose a base branch
from
DockedFerret800:modules
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ae95306
Initial support for modules
DockedFerret800 1e4a461
Wider modules coverage for examples
DockedFerret800 4545447
Return missing installation instructions
DockedFerret800 bd4efd4
Slightly change export approach
DockedFerret800 4c110ba
Use ABI-Breaking style for modules wrapper
DockedFerret800 7c3019e
Merge remote-tracking branch 'upstream/master' into modules
prince-chrismc 1bd1f26
Address comments
DockedFerret800 d2f8dbe
Merge branch 'modules' of https://github.com/DockedFerret800/jwt-cpp …
DockedFerret800 63bae83
Merge remote-tracking branch 'origin/master' into modules
DockedFerret800 46b4ea6
Don't export everything
DockedFerret800 c5d5e0f
Update documentation
DockedFerret800 9dea9df
Modules CI (#1)
DockedFerret800 d8cbf1a
clang 22 and gcc 15 modules CI
DockedFerret800 ac919bd
Address feedback
DockedFerret800 333c2e0
Examples include order
DockedFerret800 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Build & Test with modules | ||
|
|
||
| on: | ||
| push: | ||
| branches: [master] | ||
| pull_request: | ||
| branches: [master] | ||
| paths: | ||
| - "CMakeLists.txt" | ||
| - "cmake/**" | ||
| - "include/jwt-cpp/**" | ||
| - "tests/cmake/**" | ||
| - ".github/actions/**" | ||
| - ".github/workflows/cmake.yml" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: ${{ matrix.runs_on }}-${{ matrix.compiler }}-${{ matrix.configure_preset }} | ||
| runs-on: ${{ matrix.runs_on }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - runs_on: windows-2025-vs2026 | ||
| compiler: msvc-14.50 | ||
| configure_preset: "x64-vs-modules" | ||
| build_preset: "x64-vs-modules-build" | ||
| test_preset : "x64-vs-modules-test" | ||
| # To be uncommented once GitHub Actions adds GCC 15 with Ubuntu 26 | ||
| # - runs_on: ubuntu-latest | ||
| # compiler: gcc-15 | ||
| # configure_preset: "linux-debug" | ||
| # build_preset: "linux-debug-build" | ||
| # test_preset : "linux-debug-test" | ||
| # - runs_on: ubuntu-latest | ||
| # compiler: clang-18 | ||
| # cc: clang | ||
| # cxx: clang++ | ||
| # configure_preset: "linux-debug-modules" | ||
| # build_preset: "linux-debug-modules-build" | ||
| # test_preset : "linux-debug-modules-test" | ||
| steps: | ||
|
|
||
| - uses: actions/checkout@v6 | ||
|
|
||
| - uses: lukka/get-cmake@latest | ||
|
|
||
| - name: "Build & Test" | ||
| uses: lukka/run-cmake@v10 | ||
| env: | ||
| CC: ${{ matrix.cc }} | ||
| CXX: ${{ matrix.cxx }} | ||
| with: | ||
| configurePreset: ${{ matrix.configure_preset }} | ||
| buildPreset: ${{ matrix.build_preset }} | ||
| testPreset: ${{ matrix.test_preset }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ bld/ | |
| [Bb]in/ | ||
| [Oo]bj/ | ||
| [Ll]og/ | ||
| out/ | ||
|
|
||
| # Visual Studio 2015 cache/options directory | ||
| .vs/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ if(POLICY CMP0135) # DOWNLOAD_EXTRACT_TIMESTAMP | |
| cmake_policy(SET CMP0135 NEW) | ||
| endif() | ||
|
|
||
| set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") | ||
|
|
||
| # HUNTER_ENABLED is always set if this package is included in a project using hunter (HunterGate sets it) In this case | ||
| # we will use hunter as well to stay consistent. If not the use can supply it on configure to force using hunter. | ||
| if(HUNTER_ENABLED) | ||
|
|
@@ -20,6 +22,8 @@ option(JWT_BUILD_TESTS "Configure CMake to build tests (or not)" OFF) | |
| option(JWT_BUILD_DOCS "Adds a target for building the doxygen documentation" OFF) | ||
| option(JWT_ENABLE_COVERAGE "Enable code coverage testing" OFF) | ||
| option(JWT_ENABLE_FUZZING "Enable fuzz testing" OFF) | ||
| option(JWT_ENABLE_MODULES "Build C++ modules" OFF) | ||
| option(JWT_USE_IMPORT_STD "Use import std" OFF) | ||
|
DockedFerret800 marked this conversation as resolved.
Outdated
|
||
|
|
||
| option(JWT_DISABLE_PICOJSON "Do not provide the picojson template specialiaze" OFF) | ||
| option(JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF) | ||
|
|
@@ -92,50 +96,95 @@ endif() | |
|
|
||
| set(JWT_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
| set(JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/jwt.h) | ||
| set(JWT_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/modules) | ||
| foreach(traits ${JWT_JSON_TRAITS_OPTIONS}) | ||
| list(APPEND JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/traits/${traits}/defaults.h | ||
| ${JWT_INCLUDE_PATH}/jwt-cpp/traits/${traits}/traits.h) | ||
| endforeach() | ||
|
|
||
| if(NOT JWT_DISABLE_BASE64) | ||
| list(APPEND JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/base.h) | ||
| list(APPEND JWT_HEADER_FILES ${JWT_INCLUDE_PATH}/jwt-cpp/base.h) | ||
| endif() | ||
|
|
||
| add_library(jwt-cpp INTERFACE) | ||
| if (JWT_ENABLE_MODULES) | ||
| if(CMAKE_VERSION VERSION_LESS "4.3") | ||
| message(FATAL_ERROR "CMake >= 4.3 is required to build with modules") | ||
| endif() | ||
|
|
||
| set(CMAKE_CXX_SCAN_FOR_MODULES ON) | ||
|
|
||
| if(JWT_USE_IMPORT_STD) | ||
| if(NOT CMAKE_GENERATOR MATCHES "Visual Studio") | ||
| set(CMAKE_CXX_MODULE_STD 1) | ||
| endif() | ||
| endif() | ||
| endif() | ||
|
|
||
| if (JWT_ENABLE_MODULES) | ||
| add_library(jwt-cpp STATIC) | ||
| set(JWT_LIBRARY_TYPE PUBLIC) | ||
| else() | ||
| add_library(jwt-cpp INTERFACE) | ||
| set(JWT_LIBRARY_TYPE INTERFACE) | ||
| endif() | ||
| add_library(jwt-cpp::jwt-cpp ALIAS jwt-cpp) # To match export | ||
| target_compile_features(jwt-cpp INTERFACE cxx_std_11) | ||
|
|
||
| if(NOT JWT_ENABLE_MODULES) | ||
| target_compile_features(jwt-cpp ${JWT_LIBRARY_TYPE} cxx_std_11) | ||
| else() | ||
| if(NOT JWT_USE_IMPORT_STD) | ||
| target_compile_features(jwt-cpp ${JWT_LIBRARY_TYPE} cxx_std_20) | ||
| else() | ||
| target_compile_features(jwt-cpp ${JWT_LIBRARY_TYPE} cxx_std_23) | ||
| target_compile_definitions(jwt-cpp PRIVATE JWT_USE_IMPORT_STD) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this was public, could we remove the extra defines in the examples and test apps? |
||
| endif() | ||
| target_sources(jwt-cpp | ||
| PUBLIC | ||
| FILE_SET cxx_modules TYPE CXX_MODULES | ||
| BASE_DIRS ${JWT_MODULE_PATH} | ||
| FILES ${JWT_MODULE_PATH}/jwt.cppm | ||
| ) | ||
| endif() | ||
|
|
||
| if(JWT_DISABLE_BASE64) | ||
| target_compile_definitions(jwt-cpp INTERFACE JWT_DISABLE_BASE64) | ||
| target_compile_definitions(jwt-cpp ${JWT_LIBRARY_TYPE} JWT_DISABLE_BASE64) | ||
| endif() | ||
| if(JWT_DISABLE_PICOJSON) | ||
| target_compile_definitions(jwt-cpp INTERFACE JWT_DISABLE_PICOJSON) | ||
| target_compile_definitions(jwt-cpp ${JWT_LIBRARY_TYPE} JWT_DISABLE_PICOJSON) | ||
| endif() | ||
|
|
||
|
|
||
| source_group( | ||
| TREE "${JWT_INCLUDE_PATH}" | ||
| PREFIX "Implementation files" | ||
| FILES ${JWT_HEADER_FILES} | ||
| ) | ||
|
|
||
| include(GNUInstallDirs) | ||
| include(CMakePackageConfigHelpers) | ||
| target_include_directories(jwt-cpp INTERFACE $<BUILD_INTERFACE:${JWT_INCLUDE_PATH}> | ||
| target_include_directories(jwt-cpp ${JWT_LIBRARY_TYPE} $<BUILD_INTERFACE:${JWT_INCLUDE_PATH}> | ||
| $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) | ||
|
|
||
| if(${JWT_SSL_LIBRARY} MATCHES "OpenSSL") | ||
| target_link_libraries(jwt-cpp INTERFACE OpenSSL::SSL OpenSSL::Crypto) | ||
| target_link_libraries(jwt-cpp ${JWT_LIBRARY_TYPE} OpenSSL::SSL OpenSSL::Crypto) | ||
| endif() | ||
|
|
||
| if(${JWT_SSL_LIBRARY} MATCHES "LibreSSL") | ||
| target_link_libraries(jwt-cpp INTERFACE LibreSSL::TLS) | ||
| target_link_libraries(jwt-cpp ${JWT_LIBRARY_TYPE} LibreSSL::TLS) | ||
| endif() | ||
|
|
||
| if(${JWT_SSL_LIBRARY} MATCHES "wolfSSL") | ||
| target_link_libraries(jwt-cpp INTERFACE PkgConfig::wolfssl) | ||
| target_link_libraries(jwt-cpp ${JWT_LIBRARY_TYPE} PkgConfig::wolfssl) | ||
| # This is required to access OpenSSL compatibility API | ||
| target_include_directories(jwt-cpp INTERFACE ${wolfssl_INCLUDE_DIRS}) | ||
| # This flag is required to have the mandatory header included automatically | ||
| target_include_directories(jwt-cpp ${JWT_LIBRARY_TYPE} ${wolfssl_INCLUDE_DIRS}) | ||
| # This flag is required to have the mandatory header included automatically | ||
| # https://github.com/Thalhammer/jwt-cpp/pull/352#discussion_r1627971786 | ||
| # https://github.com/wolfSSL/wolfssl/blob/3b74a6402998a8b8839e25e31ba8ac74749aa9b0/wolfssl/wolfcrypt/settings.h#L58 | ||
| target_compile_definitions(jwt-cpp INTERFACE EXTERNAL_OPTS_OPENVPN) | ||
| target_compile_definitions(jwt-cpp ${JWT_LIBRARY_TYPE} EXTERNAL_OPTS_OPENVPN) | ||
| endif() | ||
|
|
||
| if(NOT JWT_DISABLE_PICOJSON AND JWT_EXTERNAL_PICOJSON) | ||
| target_link_libraries(jwt-cpp INTERFACE picojson::picojson) | ||
| target_link_libraries(jwt-cpp ${JWT_LIBRARY_TYPE} picojson::picojson) | ||
| endif() | ||
|
|
||
| # Hunter needs relative paths so the files are placed correctly | ||
|
|
@@ -146,18 +195,22 @@ endif() | |
| configure_package_config_file( | ||
| ${CMAKE_CURRENT_LIST_DIR}/cmake/jwt-cpp-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config.cmake | ||
| INSTALL_DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR}) | ||
| write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config-version.cmake VERSION 0.7.2 | ||
| COMPATIBILITY ExactVersion) | ||
|
|
||
| install(TARGETS jwt-cpp EXPORT jwt-cpp-targets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config-version.cmake VERSION 0.7.2 COMPATIBILITY ExactVersion) | ||
| if (JWT_ENABLE_MODULES) | ||
| install(TARGETS jwt-cpp EXPORT jwt-cpp-targets | ||
| PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| FILE_SET cxx_modules DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/modules) | ||
| else() | ||
| install(TARGETS jwt-cpp EXPORT jwt-cpp-targets | ||
| PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| endif() | ||
| install(EXPORT jwt-cpp-targets NAMESPACE jwt-cpp:: FILE jwt-cpp-targets.cmake | ||
| DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR}) | ||
| install(DIRECTORY ${JWT_INCLUDE_PATH}/jwt-cpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| if(NOT JWT_EXTERNAL_PICOJSON AND NOT JWT_DISABLE_PICOJSON) | ||
| install(FILES ${JWT_INCLUDE_PATH}/picojson/picojson.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/picojson) | ||
| endif() | ||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config-version.cmake | ||
|
DockedFerret800 marked this conversation as resolved.
|
||
| DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR}) | ||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/jwt-cpp-config-version.cmake DESTINATION ${JWT_CMAKE_FILES_INSTALL_DIR}) | ||
|
|
||
| if(JWT_BUILD_EXAMPLES) | ||
| add_subdirectory(example) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.