Skip to content

add other json serializers and parsers #279

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
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -83,4 +83,4 @@ jobs:


- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
11 changes: 9 additions & 2 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fail-fast: false
max-parallel: 8
matrix:
compiler: [g++-9, g++-10, g++-11, clang++-12, clang++-13, clang++-14]
compiler: [g++-9, g++-10, g++-11, g++-12, g++-13, clang++-12, clang++-13, clang++-14, clang++-15, clang++-16, clang++-17, clang++-18, clang++-19, clang++-20]
base-flags: ["", -DJINJA2CPP_CXX_STANDARD=17]
build-config: [Release, Debug]
build-shared: [TRUE, FALSE]
Expand All @@ -38,9 +38,16 @@ jobs:
extra-flags: -DJINJA2CPP_STRICT_WARNINGS=OFF
- compiler: g++-11
extra-flags: -DJINJA2CPP_STRICT_WARNINGS=OFF
- compiler: g++-12
extra-flags: -DJINJA2CPP_STRICT_WARNINGS=OFF
- compiler: g++-13
extra-flags: -DJINJA2CPP_STRICT_WARNINGS=OFF
- compiler: g++-14
extra-flags: -DJINJA2CPP_STRICT_WARNINGS=OFF


steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup environment
env:
INPUT_COMPILER: ${{ matrix.compiler }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:


steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build
shell: cmd
Expand Down
141 changes: 117 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.23.0)
cmake_minimum_required(VERSION 3.23.0..4.0)

if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
Expand All @@ -19,9 +19,9 @@ set_property(CACHE JINJA2CPP_WITH_SANITIZERS PROPERTY STRINGS ${JINJA2CPP_SANITI
set(JINJA2CPP_SUPPORTED_REGEX std boost)
set(JINJA2CPP_USE_REGEX boost CACHE STRING "Use regex parser in lexer, boost works faster on most platforms")
set_property(CACHE JINJA2CPP_USE_REGEX PROPERTY STRINGS ${JINJA2CPP_SUPPORTED_REGEX})
set(JINJA2CPP_WITH_JSON_BINDINGS boost nlohmann rapid all none)
set(JINJA2CPP_WITH_JSON_BINDINGS boost CACHE STRING "Build with json support(boost|rapid)")
set_property(CACHE JINJA2CPP_WITH_JSON_BINDINGS PROPERTY STRINGS ${JINJA2CPP_WITH_JSON_BINDINGS})
set(JINJA2CPP_WITH_JSON_SUPPORTED_BINDINGS boost nlohmann rapid)
set(JINJA2CPP_WITH_JSON_BINDINGS boost CACHE STRING "Build with json support(boost|rapid|nlohmann) for serialization operations, like tojson filter. 'boost' is default.")
set_property(CACHE JINJA2CPP_WITH_JSON_BINDINGS PROPERTY STRINGS ${JINJA2CPP_WITH_JSON_SUPPORTED_BINDINGS})
set (JINJA2CPP_DEPS_MODE "internal" CACHE STRING "Jinja2Cpp dependency management mode (internal | external | external-boost | conan-build). See documentation for details. 'interal' is default.")
option(JINJA2CPP_BUILD_TESTS "Build Jinja2Cpp unit tests" ${JINJA2CPP_IS_MAIN_PROJECT})
option(JINJA2CPP_STRICT_WARNINGS "Enable additional warnings and treat them as errors" ON)
Expand Down Expand Up @@ -144,13 +144,29 @@ include(collect_sources)

set (LIB_TARGET_NAME jinja2cpp)

CollectSources(Sources Headers ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(JINJA2CPP_SOURCES
src/error_info.cpp
src/expression_evaluator.cpp
src/expression_parser.cpp
src/filesystem_handler.cpp
src/filters.cpp
src/generic_list.cpp
src/internal_value.cpp
src/lexer.cpp
src/serialize_filters.cpp
src/statements.cpp
src/string_converter_filter.cpp
src/template.cpp
src/template_env.cpp
src/template_parser.cpp
src/testers.cpp
src/value.cpp
)

CollectSources(PublicSources PublicHeaders ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(${LIB_TARGET_NAME} ${LIB_LINK_TYPE}
${Sources}
${Headers}
${PublicHeaders}
${JINJA2CPP_SOURCES}
)

target_sources(${LIB_TARGET_NAME}
Expand Down Expand Up @@ -185,19 +201,6 @@ endif()
set(JINJA2CPP_PRIVATE_LIBS "${JINJA2CPP_PRIVATE_LIBS}")
include(thirdparty/CMakeLists.txt)

target_link_libraries(
${LIB_TARGET_NAME}
PUBLIC
${JINJA2CPP_PUBLIC_LIBS}
PRIVATE
${JINJA2CPP_PRIVATE_LIBS}
)

target_include_directories(${LIB_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

if (JINJA2CPP_STRICT_WARNINGS)
if (UNIX)
Expand All @@ -218,11 +221,44 @@ endif ()
if ("${JINJA2CPP_USE_REGEX}" STREQUAL "boost")
set(_regex_define "-DJINJA2CPP_USE_REGEX_BOOST")
endif()

if ("${JINJA2CPP_WITH_JSON_BINDINGS}" STREQUAL "boost")
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_BOOST")
target_sources(${LIB_TARGET_NAME}
PRIVATE
src/binding/boost_json_serializer.cpp
)
list(APPEND JINJA2CPP_PRIVATE_LIBS Boost::json)
elseif("${JINJA2CPP_WITH_JSON_BINDINGS}" STREQUAL "rapid")
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_RAPID")
target_sources(${LIB_TARGET_NAME}
PRIVATE
src/binding/rapid_json_serializer.cpp
)
list(APPEND JINJA2CPP_PRIVATE_LIBS RapidJson)
else()
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_NLOHMANN")
target_sources(${LIB_TARGET_NAME}
PRIVATE
src/binding/nlohmann_json_serializer.cpp
)
list(APPEND JINJA2CPP_PRIVATE_LIBS nlohmann_json::nlohmann_json)
endif()

target_link_libraries(
${LIB_TARGET_NAME}
PUBLIC
${JINJA2CPP_PUBLIC_LIBS}
PRIVATE
${JINJA2CPP_PRIVATE_LIBS}
)

target_include_directories(${LIB_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_compile_definitions(${LIB_TARGET_NAME}
PUBLIC
-DBOOST_SYSTEM_NO_DEPRECATED
Expand Down Expand Up @@ -251,8 +287,32 @@ if (JINJA2CPP_BUILD_TESTS)
enable_testing()

CollectSources(TestSources TestHeaders ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/test)
add_executable(jinja2cpp_tests ${TestSources} ${TestHeaders})
target_link_libraries(jinja2cpp_tests gtest gtest_main
set(JINJA2CPP_TEST_SOURCES
test/basic_tests.cpp
test/binding
test/errors_test.cpp
test/expressions_test.cpp
test/extends_test.cpp
test/filesystem_handler_test.cpp
test/filters_test.cpp
test/forloop_test.cpp
test/helpers_tests.cpp
test/if_test.cpp
test/import_test.cpp
test/includes_test.cpp
test/macro_test.cpp
test/metadata_test.cpp
test/perf_test.cpp
test/statements_tets.cpp
test/test_data
test/test_tools.h
test/testers_test.cpp
test/tojson_filter_test.cpp
test/user_callable_test.cpp
)

add_executable(jinja2cpp_tests ${JINJA2CPP_TEST_SOURCES})
target_link_libraries(jinja2cpp_tests gtest gmock gtest_main
nlohmann_json::nlohmann_json ${LIB_TARGET_NAME} ${EXTRA_TEST_LIBS} ${JINJA2CPP_PRIVATE_LIBS})

set_target_properties(jinja2cpp_tests PROPERTIES
Expand All @@ -277,6 +337,39 @@ if (JINJA2CPP_BUILD_TESTS)
add_dependencies(jinja2cpp_tests CopyTestData)

add_test(NAME jinja2cpp_tests COMMAND jinja2cpp_tests)

if ("${JINJA2CPP_WITH_JSON_BINDINGS}" STREQUAL "boost")
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_BOOST")
set(_bindings_test_source test/binding/boost_json_binding_test.cpp)

target_sources(jinja2cpp_tests
PRIVATE
src/binding/boost_json_serializer.cpp
)
endif()
if("${JINJA2CPP_WITH_JSON_BINDINGS}" STREQUAL "rapid")
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_RAPID")
target_sources(jinja2cpp_tests
PRIVATE
test/binding/rapid_json_binding_test.cpp
test/binding/rapid_json_serializer_test.cpp
)
endif()
if("${JINJA2CPP_WITH_JSON_BINDINGS}" STREQUAL "nlohmann")
set(_bindings_define "-DJINJA2CPP_WITH_JSON_BINDINGS_RAPID")
target_sources(jinja2cpp_tests
PRIVATE
test/binding/nlohmann_json_binding_test.cpp
)
endif()
target_compile_definitions(jinja2cpp_tests
PUBLIC
-DBOOST_SYSTEM_NO_DEPRECATED
-DBOOST_ERROR_CODE_HEADER_ONLY
${_regex_define}
${_bindings_define}
)

endif ()

set (JINJA2CPP_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/${LIB_TARGET_NAME}")
Expand Down Expand Up @@ -353,4 +446,4 @@ if(JINJA2CPP_INSTALL)
DESTINATION
${JINJA2CPP_INSTALL_CONFIG_DIR}
)
endif()
endif()
24 changes: 24 additions & 0 deletions cmake/patches/0001-fix-custom_command-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From c5e3f11d98aa3116001361ef108c7bd4fa5e3a7f Mon Sep 17 00:00:00 2001
Date: Fri, 13 Jun 2025 14:46:05 +0300
Subject: [PATCH] fix custom_command error

---
CMakeLists.txt | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index be860c93..73f067c9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -161,8 +161,7 @@ if(RAPIDJSON_BUILD_DOC)
add_subdirectory(doc)
endif()

-add_custom_target(travis_doc)
-add_custom_command(TARGET travis_doc
+add_custom_target(TARGET travis_doc
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/travis-doxygen.sh)

if(RAPIDJSON_BUILD_EXAMPLES)
--

Loading
Loading