Skip to content

Commit 8871737

Browse files
authored
Preparing release 0.9.1: warnings fix, Win CI build fix, build system improvement (#81)
* Fix build with C++17 enabled and system-provided boost package * Fix build * Fix build * Build scripts cleanup and Readme file update * Fix readme, improve appveyor matrix * Debug Win-based CI * Debug Win-based CI * Debug Win-based CI * Fix runtime type bypass to gtest submodule * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI builds * Debug Win CI build Fix MSVC warnings * Debug Win CI build * [skip ci] Update readme
1 parent 2722df7 commit 8871737

16 files changed

+216
-87
lines changed

.travis.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ matrix:
4141
sources: ['ubuntu-toolchain-r-test']
4242
packages: ['cmake', 'g++-7']
4343

44+
- os: linux
45+
compiler: gcc
46+
env:
47+
COMPILER=g++-7
48+
CMAKE_CXX_FLAGS=-std=c++17
49+
addons:
50+
apt:
51+
sources: ['ubuntu-toolchain-r-test']
52+
packages: ['cmake', 'g++-7']
53+
54+
- os: linux
55+
compiler: gcc
56+
env:
57+
COMPILER=g++-7
58+
SYSTEM_BOOST_PACKAGE=YES
59+
addons:
60+
apt:
61+
sources: ['ubuntu-toolchain-r-test']
62+
packages: ['cmake', 'g++-7']
63+
4464
- os: linux
4565
compiler: clang
4666
env: COMPILER=clang++-5.0
@@ -60,11 +80,10 @@ matrix:
6080
before_install:
6181
- date -u
6282
- uname -a
63-
# - sudo add-apt-repository -y ppa:samuel-bachmann/boost
64-
# - sudo apt-get update -qq
83+
- if [[ "${SYSTEM_BOOST_PACKAGE}" != "" ]]; then sudo add-apt-repository -y ppa:samuel-bachmann/boost && sudo apt-get update -qq; fi
6584

6685
install:
67-
# - sudo apt-get install libboost1.60-all-dev
86+
- if [[ "${SYSTEM_BOOST_PACKAGE}" != "" ]]; then sudo apt-get install libboost1.60-all-dev; fi
6887

6988
script:
7089
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
@@ -73,7 +92,7 @@ script:
7392
- $CXX --version
7493

7594
- mkdir -p build && cd build
76-
- cmake $CMAKE_OPTS -DCMAKE_BUILD_TYPE=$BUILD_CONFIG .. && cmake --build . --config $BUILD_CONFIG -- -j4
95+
- cmake $CMAKE_OPTS -DCMAKE_BUILD_TYPE=$BUILD_CONFIG -DCMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS .. && cmake --build . --config $BUILD_CONFIG -- -j4
7796
- ctest -C $BUILD_CONFIG -V
7897

7998

CMakeLists.txt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
cmake_minimum_required(VERSION 3.0.2)
2-
project(Jinja2Cpp VERSION 0.5.0)
2+
project(Jinja2Cpp VERSION 0.9.1)
3+
4+
if (${CMAKE_VERSION} VERSION_GREATER "3.12")
5+
cmake_policy(SET CMP0074 OLD)
6+
endif ()
37

48
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
59

6-
set(CMAKE_CXX_STANDARD 14)
7-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
810
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
911
if (NOT UNIX)
1012
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wa,-mbig-obj")
@@ -13,12 +15,11 @@ else ()
1315
set (COMMON_MSVC_OPTS "/wd4503 /DBOOST_ALL_NO_LIB")
1416

1517
# MSVC
16-
if (NOT DEFINED MSVC_RUNTIME_TYPE)
17-
set (MSVC_RUNTIME_TYPE "/MD")
18-
set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
18+
if (CMAKE_BUILD_TYPE MATCHES "Debug" AND MSVC_RUNTIME_TYPE)
19+
set (MSVC_RUNTIME_TYPE "${MSVC_RUNTIME_TYPE}d")
1920
endif ()
2021
if (CMAKE_BUILD_TYPE MATCHES "Debug")
21-
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_RUNTIME_TYPE}d ${COMMON_MSVC_OPTS}")
22+
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${MSVC_RUNTIME_TYPE} ${COMMON_MSVC_OPTS}")
2223
set (Boost_USE_DEBUG_RUNTIME ON)
2324
else ()
2425
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MSVC_RUNTIME_TYPE} ${COMMON_MSVC_OPTS}")
@@ -51,6 +52,9 @@ add_library(${LIB_TARGET_NAME} STATIC
5152
${PublicHeaders}
5253
)
5354

55+
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_CFG_NAME)
56+
set(CURRENT_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BUILD_CFG_NAME}}")
57+
5458
add_subdirectory(thirdparty)
5559

5660
target_link_libraries(${LIB_TARGET_NAME} PUBLIC expected-lite variant-lite value-ptr-lite optional-lite boost_variant boost_filesystem boost_algorithm)
@@ -61,14 +65,32 @@ target_include_directories(${LIB_TARGET_NAME}
6165

6266
if(NOT MSVC)
6367
target_compile_options(${LIB_TARGET_NAME} PRIVATE -Wall -Werror)
68+
else ()
69+
target_compile_options(${LIB_TARGET_NAME} PRIVATE /W4)
6470
endif()
6571

72+
target_compile_definitions(${LIB_TARGET_NAME} PUBLIC variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD)
73+
set_target_properties(${LIB_TARGET_NAME} PROPERTIES
74+
CXX_STANDARD 14
75+
CXX_STANDARD_REQUIRED ON)
76+
6677
if (JINJA2CPP_BUILD_TESTS)
6778
enable_testing()
6879

6980
CollectSources(TestSources TestHeaders ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/test)
7081
add_executable(jinja2cpp_tests ${TestSources} ${TestHeaders})
7182
target_link_libraries(jinja2cpp_tests gtest gtest_main ${LIB_TARGET_NAME} ${EXTRA_TEST_LIBS})
83+
84+
get_target_property(TEST_CXX_STD jinja2cpp_tests CXX_STANDARD)
85+
86+
string (FIND "${CURRENT_CXX_FLAGS}" "-std" TEST_FLAGS_STD_POS)
87+
string (FIND "${TEST_CXX_STD}" "NOTFOUND" TEST_CXX_STD_NOTFOUND_POS)
88+
89+
if (NOT MSVC AND TEST_FLAGS_STD_POS EQUAL -1 AND NOT (TEST_CXX_STD_NOTFOUND_POS EQUAL -1))
90+
set_target_properties(jinja2cpp_tests PROPERTIES
91+
CXX_STANDARD 14
92+
CXX_STANDARD_REQUIRED ON)
93+
endif ()
7294

7395
add_custom_command(
7496
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_data/simple_template1.j2tpl

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Github Releases](https://img.shields.io/github/release/flexferrum/Jinja2Cpp/all.svg)](https://github.com/flexferrum/Jinja2Cpp/releases)
1010
[![Github Issues](https://img.shields.io/github/issues/flexferrum/Jinja2Cpp.svg)](http://github.com/flexferrum/Jinja2Cpp/issues)
1111
[![GitHub License](https://img.shields.io/badge/license-Mozilla-blue.svg)](https://raw.githubusercontent.com/flexferrum/Jinja2Cpp/master/LICENSE)
12+
[![Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Jinja2Cpp/Lobby)
1213

1314
C++ implementation of big subset of Jinja2 template engine features. This library was inspired by [Jinja2CppLight](https://github.com/hughperkins/Jinja2CppLight) project and brings support of mostly all Jinja2 templates features into C++ world. Unlike [inja](https://github.com/pantor/inja) lib, you have to build Jinja2Cpp, but it has only one dependence: boost.
1415

@@ -33,7 +34,9 @@ C++ implementation of big subset of Jinja2 template engine features. This librar
3334
- [Build and install](#build-and-install)
3435
- [Additional CMake build flags](#additional-cmake-build-flags)
3536
- [Link with you projects](#link-with-you-projects)
37+
- [Acknowledgments](#acknowledgments)
3638
- [Changelog](#changelog)
39+
- [Version 0.9.1](#version-091)
3740
- [Version 0.9](#version-09)
3841
- [Version 0.6](#version-06)
3942

@@ -526,8 +529,8 @@ Compilation of Jinja2Cpp tested on the following compilers (with C++14 enabled f
526529
- Linux gcc 6.0
527530
- Linux gcc 7.0
528531
- Linux clang 5.0
529-
- Microsoft Visual Studio 2015 x86
530-
- Microsoft Visual Studio 2017 x86
532+
- Microsoft Visual Studio 2015 x86, x64
533+
- Microsoft Visual Studio 2017 x86, x64
531534

532535
# Build and install
533536
Jinja2Cpp has got only two external dependency: boost library (at least version 1.55) and expected-lite. Because of types from boost are used inside library, you should compile both your projects and Jinja2Cpp library with similar compiler settings. Otherwise ABI could be broken.
@@ -573,7 +576,7 @@ In order to compile Jinja2Cpp you need:
573576
## Additional CMake build flags
574577
You can define (via -D command line CMake option) the following build flags:
575578

576-
* **WITH_TESTS** (default TRUE) - build or not Jinja2Cpp tests.
579+
* **JINJA2CPP_BUILD_TESTS** (default TRUE) - build or not Jinja2Cpp tests.
577580
* **MSVC_RUNTIME_TYPE** (default /MD) - MSVC runtime type to link with (if you use Microsoft Visual Studio compiler).
578581
* **LIBRARY_TYPE** Could be STATIC (default for Windows platform) or SHARED (default for Linux). Specify the type of Jinja2Cpp library to build.
579582

@@ -615,7 +618,20 @@ target_link_libraries(YourTarget
615618
#...
616619
```
617620

621+
# Acknowledgments
622+
Thanks to @manu343726 for CMake scripts improvement, bugs hunting and fixing and conan.io packaging.
623+
624+
Thanks to @martinmoene for perfectly implemented xxx-lite libraries.
625+
618626
# Changelog
627+
## Version 0.9.1
628+
* `applymacro` filter added which allows to apply arbitrary macro as a filter
629+
* dependencies to boost removed from the public interface
630+
* CMake scripts improved
631+
* Various bugs fixed
632+
* Improve reflection
633+
* Warnings cleanup
634+
619635
## Version 0.9
620636
* Support of 'extents'/'block' statements
621637
* Support of 'macro'/'call' statements

appveyor.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,54 @@
1-
version: 0.9.{build}
1+
version: 0.9.1.{build}
22

33
os:
44
- Visual Studio 2015
55
- Visual Studio 2017
66

7+
platform:
8+
- Win32
9+
- x64
10+
11+
configuration:
12+
- Debug
13+
- Release
14+
715
environment:
816
matrix:
9-
- PLATFORM: x64
10-
- PLATFORM: x86
17+
- BUILD_PLATFORM: x64
18+
MSVC_RUNTIME_TYPE: /MD
19+
- BUILD_PLATFORM: x64
20+
MSVC_RUNTIME_TYPE: /MT
21+
- BUILD_PLATFORM: x64
22+
MSVC_RUNTIME_TYPE:
23+
- BUILD_PLATFORM: x86
24+
MSVC_RUNTIME_TYPE: /MD
25+
- BUILD_PLATFORM: x86
26+
MSVC_RUNTIME_TYPE: /MT
27+
- BUILD_PLATFORM: x86
28+
MSVC_RUNTIME_TYPE:
1129

1230
matrix:
1331
fast_finish: false
32+
exclude:
33+
- platform: Win32
34+
BUILD_PLATFORM: x64
35+
- platform: x64
36+
BUILD_PLATFORM: x86
1437

1538
init:
16-
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%PLATFORM%"=="x86" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
17-
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%PLATFORM%"=="x64" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
18-
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
19-
20-
install:
21-
- git submodule -q update --init
39+
- set BOOST_ROOT=C:\Libraries\boost_1_65_1
40+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%BUILD_PLATFORM%"=="x86" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
41+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%BUILD_PLATFORM%"=="x86" set PATH=%BOOST_ROOT%\lib32-msvc-14.1;%PATH%
42+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%BUILD_PLATFORM%"=="x64" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
43+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" if "%BUILD_PLATFORM%"=="x64" set PATH=%BOOST_ROOT%\lib64-msvc-14.1;%PATH%
44+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%BUILD_PLATFORM%"=="x86" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
45+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%BUILD_PLATFORM%"=="x86" set PATH=%BOOST_ROOT%\lib32-msvc-14.0;%PATH%
46+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%BUILD_PLATFORM%"=="x64" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
47+
- if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%BUILD_PLATFORM%"=="x64" set PATH=%BOOST_ROOT%\lib64-msvc-14.0;%PATH%
2248

2349
build_script:
2450
- mkdir -p build && cd build
25-
- set BOOST_DIR=C:\Libraries\boost_1_65_1
26-
- cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
51+
- cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%configuration% -DMSVC_RUNTIME_TYPE=%MSVC_RUNTIME_TYPE%
2752
- cmake --build . --target all
2853

2954
test_script:

include/jinja2cpp/value.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ class Value {
102102
public:
103103
using ValueData = nonstd::variant<EmptyValue, bool, std::string, std::wstring, int64_t, double, RecWrapper<ValuesList>, RecWrapper<ValuesMap>, GenericList, GenericMap, UserFunction>;
104104

105-
Value() = default;
105+
Value();
106+
Value(const Value& val);
107+
Value(Value&& val);
108+
~Value();
109+
110+
Value& operator =(const Value&);
111+
Value& operator =(Value&&);
106112
template<typename T>
107113
Value(T&& val, typename std::enable_if<!std::is_same<std::decay_t<T>, Value>::value && !std::is_same<std::decay_t<T>, ValuesList>::value>::type* = nullptr)
108114
: m_data(std::forward<T>(val))
@@ -211,6 +217,14 @@ inline Value GenericList::GetValueByIndex(int64_t index) const
211217
return m_accessor()->GetValueByIndex(index);
212218
}
213219

220+
inline Value::Value() = default;
221+
inline Value::Value(const Value& val) = default;
222+
inline Value::Value(Value&& val) = default;
223+
inline Value::~Value() = default;
224+
inline Value& Value::operator =(const Value&) = default;
225+
inline Value& Value::operator =(Value&&) = default;
226+
227+
214228
} // jinja2
215229

216230
#endif // JINJA2_VALUE_H

src/error_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct ValueRenderer
7676
}
7777

7878

79-
void operator() (const UserFunction& val) const
79+
void operator() (const UserFunction&) const
8080
{
8181
}
8282

src/expression_evaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ ParsedArguments ParseCallParamsImpl(const T& args, const CallParams& params, boo
455455
continue;
456456
}
457457

458-
int prevNotFound = argsInfo[startPosArg].prevNotFound;
458+
prevNotFound = argsInfo[startPosArg].prevNotFound;
459459
if (prevNotFound != -1)
460460
{
461461
startPosArg = static_cast<std::size_t>(prevNotFound);

src/filesystem_handler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ struct FileContentConverter
2121
{
2222
sPtr->reset(new std::wistringstream(content));
2323
}
24-
void operator() (const std::wstring& content, CharFileStreamPtr* sPtr) const
24+
void operator() (const std::wstring&, CharFileStreamPtr*) const
2525
{
2626
// CharFileStreamPtr stream(new std::istringstream(content), [](std::istream* s) {delete static_cast<std::istringstream>(s);});
2727
// std::swap(*sPtr, stream);
2828
}
2929

30-
void operator() (const std::string& content, WCharFileStreamPtr* sPtr) const
30+
void operator() (const std::string&, WCharFileStreamPtr*) const
3131
{
3232
// WCharFileStreamPtr stream(new std::wistringstream(content), [](std::wistream* s) {delete static_cast<std::wistringstream>(s);});
3333
// std::swap(*sPtr, stream);
@@ -86,7 +86,7 @@ CharFileStreamPtr RealFileSystem::OpenStream(const std::string& name) const
8686
if (result->good())
8787
return result;
8888

89-
return CharFileStreamPtr(nullptr, [](std::istream* s){});
89+
return CharFileStreamPtr(nullptr, [](std::istream*){});
9090
}
9191

9292
WCharFileStreamPtr RealFileSystem::OpenWStream(const std::string& name) const
@@ -99,7 +99,7 @@ WCharFileStreamPtr RealFileSystem::OpenWStream(const std::string& name) const
9999
if (result->good())
100100
return result;
101101

102-
return WCharFileStreamPtr(nullptr, [](std::wistream* s){;});
102+
return WCharFileStreamPtr(nullptr, [](std::wistream*){;});
103103
}
104104

105105
} // jinja2

src/filters.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ struct PrettyPrinter : visitors::BaseVisitor<InternalValue>
469469
return "'"s + str + "'"s;
470470
}
471471

472-
InternalValue operator()(const std::wstring& str) const
472+
InternalValue operator()(const std::wstring&) const
473473
{
474474
return "'<wchar_string>'"s;
475475
}
@@ -479,7 +479,7 @@ struct PrettyPrinter : visitors::BaseVisitor<InternalValue>
479479
return val ? "true"s : "false"s;
480480
}
481481

482-
InternalValue operator()(EmptyValue val) const
482+
InternalValue operator()(EmptyValue) const
483483
{
484484
return "none"s;
485485
}
@@ -515,7 +515,7 @@ Random::Random(FilterParams params)
515515

516516
}
517517

518-
InternalValue Random::Filter(const InternalValue& baseVal, RenderContext& context)
518+
InternalValue Random::Filter(const InternalValue&, RenderContext&)
519519
{
520520
return InternalValue();
521521
}
@@ -687,32 +687,32 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
687687
return result;
688688
}
689689

690-
Serialize::Serialize(FilterParams params, Serialize::Mode mode)
690+
Serialize::Serialize(FilterParams, Serialize::Mode)
691691
{
692692

693693
}
694694

695-
InternalValue Serialize::Filter(const InternalValue& baseVal, RenderContext& context)
695+
InternalValue Serialize::Filter(const InternalValue&, RenderContext&)
696696
{
697697
return InternalValue();
698698
}
699699

700-
Slice::Slice(FilterParams params, Slice::Mode mode)
700+
Slice::Slice(FilterParams, Slice::Mode)
701701
{
702702

703703
}
704704

705-
InternalValue Slice::Filter(const InternalValue& baseVal, RenderContext& context)
705+
InternalValue Slice::Filter(const InternalValue&, RenderContext&)
706706
{
707707
return InternalValue();
708708
}
709709

710-
StringFormat::StringFormat(FilterParams params, StringFormat::Mode mode)
710+
StringFormat::StringFormat(FilterParams, StringFormat::Mode)
711711
{
712712

713713
}
714714

715-
InternalValue StringFormat::Filter(const InternalValue& baseVal, RenderContext& context)
715+
InternalValue StringFormat::Filter(const InternalValue&, RenderContext&)
716716
{
717717
return InternalValue();
718718
}

0 commit comments

Comments
 (0)