Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
87 changes: 77 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.0.1)
project(Jinja2Cpp VERSION 0.9.1)

if (${CMAKE_VERSION} VERSION_GREATER "3.12")
cmake_policy(SET CMP0074 OLD)
endif ()

set (JINJA2CPP_DEPS_MODE "internal" CACHE STRING "Jinja2Cpp dependency management mode (internal | external | external-boost | conan-build). See documentation for details. 'interal' is default.")
if (NOT JINJA2CPP_DEPS_MODE)
set (JINJA2CPP_DEPS_MODE "internal")
endif ()

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE_ENABLED)
Expand Down Expand Up @@ -48,6 +56,7 @@ endif()
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)
option(JINJA2CPP_BUILD_SHARED "Build shared linkage version of Jinja2Cpp" OFF)

if (JINJA2CPP_BUILD_SHARED)
set(LIB_LINK_TYPE SHARED)
else()
Expand All @@ -72,10 +81,12 @@ set(CURRENT_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BUILD_CFG_NAME}}")

include(thirdparty/CMakeLists.txt)

target_link_libraries(${LIB_TARGET_NAME} PUBLIC expected-lite variant-lite value-ptr-lite optional-lite boost_variant boost_filesystem boost_algorithm)
target_link_libraries(${LIB_TARGET_NAME} PUBLIC ${JINJA2CPP_PUBLIC_LIBS} PRIVATE ${JINJA2CPP_PRIVATE_LIBS})

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

if(JINJA2CPP_STRICT_WARNINGS)
if(NOT MSVC)
Expand All @@ -89,9 +100,17 @@ if (COVERAGE_ENABLED AND NOT MSVC)
endif ()

target_compile_definitions(${LIB_TARGET_NAME} PUBLIC variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD)

set_target_properties(${LIB_TARGET_NAME} PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)
CXX_STANDARD_REQUIRED ON
VERSION ${PROJECT_VERSION}
SOVERSION 1
)

set_property(TARGET ${LIB_TARGET_NAME} PROPERTY PUBLIC_HEADER ${PublicHeaders} ${JINJA2CPP_EXTRA_PUBLIC_HEADERS})

configure_file(jinja2cpp.pc.in jinja2cpp.pc @ONLY)

if (JINJA2CPP_BUILD_TESTS)
enable_testing()
Expand Down Expand Up @@ -130,10 +149,58 @@ if (JINJA2CPP_BUILD_TESTS)
add_test(NAME jinja2cpp_tests COMMAND jinja2cpp_tests)
endif ()

install(TARGETS ${LIB_TARGET_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
set (JINJA2CPP_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/${LIB_TARGET_NAME})
set (JINJA2CPP_TMP_CONFIG_PATH cmake/config)

install (DIRECTORY include/ DESTINATION include)
install (FILES cmake/public/FindJinja2Cpp.cmake DESTINATION cmake)

macro (Jinja2CppGetTargetIncludeDir infix target)
message (STATUS "infix: ${infix} target: ${target}")

if (TARGET ${target})
set (_J2CPP_VAR_NAME JINJA2CPP_${infix}_INCLUDE_DIRECTORIES)
get_target_property(${_J2CPP_VAR_NAME} ${target} INTERFACE_INCLUDE_DIRECTORIES)
endif ()
endmacro ()

Jinja2CppGetTargetIncludeDir(EXPECTED-LITE expected-lite)
Jinja2CppGetTargetIncludeDir(VARIANT-LITE variant-lite)
Jinja2CppGetTargetIncludeDir(OPTIONAL-LITE optional-lite)
Jinja2CppGetTargetIncludeDir(VALUE-PTR-LITE value-ptr-lite)

# Workaround for #14444 bug of CMake (https://gitlab.kitware.com/cmake/cmake/issues/14444)
# We can't use EXPORT feature of 'install' as is due to limitation of subproject's targets installation
# So jinja2cpp-config.cmake should be written manually

install(TARGETS ${LIB_TARGET_NAME}
EXPORT InstallTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/static
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/jinja2cpp
)

install (FILES ${CMAKE_BINARY_DIR}/jinja2cpp.pc
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

install(EXPORT InstallTargets
FILE jinja2cpp-cfg.cmake
DESTINATION ${JINJA2CPP_INSTALL_CONFIG_DIR})

configure_package_config_file(
cmake/public/jinja2cpp-config.cmake.in
${JINJA2CPP_TMP_CONFIG_PATH}/jinja2cpp-config.cmake
INSTALL_DESTINATION ${JINJA2CPP_TMP_CONFIG_PATH}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

configure_package_config_file(
cmake/public/jinja2cpp-config-deps-${JINJA2CPP_DEPS_MODE}.cmake.in
${JINJA2CPP_TMP_CONFIG_PATH}/jinja2cpp-config-deps.cmake
INSTALL_DESTINATION ${JINJA2CPP_TMP_CONFIG_PATH}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

install (FILES
${CMAKE_CURRENT_BINARY_DIR}/${JINJA2CPP_TMP_CONFIG_PATH}/${LIB_TARGET_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${JINJA2CPP_TMP_CONFIG_PATH}/${LIB_TARGET_NAME}-config-deps.cmake
DESTINATION ${JINJA2CPP_INSTALL_CONFIG_DIR})
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions cmake/public/jinja2cpp-config-deps-external-boost.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
macro (Jinja2CppAddBoostDep name)
if (TARGET Boost::${name})
list (APPEND JINJA2CPP_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:Boost::${name}>)
elseif (TARGET boost_${name})
list (APPEND JINJA2CPP_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:boost_${name}>)
endif ()
endmacro ()

Jinja2CppAddBoostDep(variant)
Jinja2CppAddBoostDep(filesystem)
Jinja2CppAddBoostDep(algorithm)

set_property(TARGET jinja2cpp PROPERTY
INTERFACE_LINK_LIBRARIES ${JINJA2CPP_INTERFACE_LINK_LIBRARIES}
)
45 changes: 45 additions & 0 deletions cmake/public/jinja2cpp-config-deps-external.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Create imported target expected-lite
add_library(expected-lite INTERFACE IMPORTED)

set_target_properties(expected-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "@JINJA2CPP_EXPECTED-LITE_INCLUDE_DIRECTORIES@"
)

# Create imported target variant-lite
add_library(variant-lite INTERFACE IMPORTED)

set_target_properties(variant-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "@JINJA2CPP_VARIANT-LITE_INCLUDE_DIRECTORIES@"
)

# Create imported target optional-lite
add_library(optional-lite INTERFACE IMPORTED)

set_target_properties(optional-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "@JINJA2CPP_OPTIONAL-LITE_INCLUDE_DIRECTORIES@"
)

# Create imported target value-ptr-lite
add_library(value-ptr-lite INTERFACE IMPORTED)

set_target_properties(value-ptr-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "@JINJA2CPP_VALUE-PTR-LITE_INCLUDE_DIRECTORIES@"
)

set (JINJA2CPP_INTERFACE_LINK_LIBRARIES expected-lite variant-lite value-ptr-lite optional-lite)

macro (Jinja2CppAddBoostDep name)
if (TARGET Boost::${name})
list (APPEND JINJA2CPP_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:Boost::${name}>)
elseif (TARGET boost_${name})
list (APPEND JINJA2CPP_INTERFACE_LINK_LIBRARIES $<LINK_ONLY:boost_${name}>)
endif ()
endmacro ()

Jinja2CppAddBoostDep(variant)
Jinja2CppAddBoostDep(filesystem)
Jinja2CppAddBoostDep(algorithm)

set_property(TARGET jinja2cpp PROPERTY
INTERFACE_LINK_LIBRARIES ${JINJA2CPP_INTERFACE_LINK_LIBRARIES}
)
Empty file.
81 changes: 81 additions & 0 deletions cmake/public/jinja2cpp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Based on generated file by CMake

if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)

#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------

# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)

# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget jinja2cpp)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)


# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

# Create imported target jinja2cpp
add_library(jinja2cpp STATIC IMPORTED)

set_target_properties(jinja2cpp PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "variant_CONFIG_SELECT_VARIANT=variant_VARIANT_NONSTD"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
)

# INTERFACE_LINK_LIBRARIES "nonstd::expected-lite;nonstd::variant-lite;nonstd::value_ptr-lite;nonstd::optional-lite;\$<LINK_ONLY:boost::variant>;\$<LINK_ONLY:boost::filesystem>;\$<LINK_ONLY:boost::algorithm>"

if(CMAKE_VERSION VERSION_LESS 2.8.12)
message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.")
endif()

# Load information for each installed configuration.
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/jinja2cpp-cfg-*.cmake")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()

include(${_DIR}/jinja2cpp-config-deps.cmake)

# Cleanup temporary variables.
set(_IMPORT_PREFIX)

# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
33 changes: 33 additions & 0 deletions include/jinja2cpp/error_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <iostream>
#include <vector>
#include <type_traits>

namespace jinja2
{
Expand Down Expand Up @@ -57,6 +58,38 @@ class ErrorInfoTpl
: m_errorData(std::move(data))
{}

~ErrorInfoTpl() noexcept
{
static_assert(std::is_nothrow_move_constructible<ErrorCode>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<SourceLocation>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<std::vector<SourceLocation>>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<Value>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<std::vector<Value>>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<std::basic_string<CharT>>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<Data>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_constructible<ErrorInfoTpl<CharT>>::value, "Should be nothrow-moveable");
static_assert(std::is_nothrow_move_assignable<ErrorInfoTpl<CharT>>::value, "Should be nothrow-moveable");
}
ErrorInfoTpl(const ErrorInfoTpl<CharT>&) = default;
ErrorInfoTpl(ErrorInfoTpl<CharT>&& val) noexcept
: m_errorData(std::move(val.m_errorData))
{ }


ErrorInfoTpl& operator =(const ErrorInfoTpl<CharT>&) = default;
ErrorInfoTpl& operator =(ErrorInfoTpl<CharT>&& val) noexcept
{
if (this == &val)
return *this;

std::swap(m_errorData.code, val.m_errorData.code);
std::swap(m_errorData.srcLoc, val.m_errorData.srcLoc);
std::swap(m_errorData.relatedLocs, val.m_errorData.relatedLocs);
std::swap(m_errorData.extraParams, val.m_errorData.extraParams);
std::swap(m_errorData.locationDescr, val.m_errorData.locationDescr);

return *this;
}

ErrorCode GetCode() const
{
Expand Down
10 changes: 7 additions & 3 deletions include/jinja2cpp/reflected_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
#define JINJA2_REFLECTED_VALUE_H

#include "value.h"

#include <nonstd/optional.hpp>

#include <vector>
#include <set>
#include <cstddef>
#include <string>
#include <type_traits>
#include <memory>
#include <boost/optional.hpp>

namespace jinja2
{
Expand Down Expand Up @@ -80,11 +82,13 @@ class ReflectedMapImpl : public ReflectedMapImplBase<ReflectedMapImpl<T>>
template<typename Fn>
Value GetField(Fn&& accessor) const
{
return accessor(m_valuePtr ? *m_valuePtr : m_value.get());
if (!m_valuePtr && !m_value)
return Value();
return accessor(m_valuePtr ? *m_valuePtr : m_value.value());
}

private:
boost::optional<T> m_value;
nonstd::optional<T> m_value;
const T* m_valuePtr = nullptr;
};

Expand Down
18 changes: 14 additions & 4 deletions include/jinja2cpp/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ class Value

Value();
Value(const Value& val);
Value(Value&& val);
Value(Value&& val) noexcept;
~Value();

Value& operator =(const Value&);
Value& operator =(Value&&);
Value& operator =(Value&&) noexcept;
template<typename T>
Value(T&& val, typename std::enable_if<!AnyOf<T, Value, ValuesList, UserCallable>::value>::type* = nullptr)
: m_data(std::forward<T>(val))
Expand Down Expand Up @@ -272,10 +272,20 @@ inline Value GenericList::GetValueByIndex(int64_t index) const

inline Value::Value() = default;
inline Value::Value(const Value& val) = default;
inline Value::Value(Value&& val) = default;
inline Value::Value(Value&& val) noexcept
: m_data(std::move(val.m_data))
{
}
inline Value::~Value() = default;
inline Value& Value::operator =(const Value&) = default;
inline Value& Value::operator =(Value&&) = default;
inline Value& Value::operator =(Value&& val) noexcept
{
if (this == &val)
return *this;

m_data.swap(val.m_data);
return *this;
}


} // jinja2
Expand Down
Loading