mirror of
https://github.com/pantor/inja.git
synced 2026-02-17 09:03:58 +00:00
update to json 3.2 and catch 2.3, clean cmake
This commit is contained in:
@@ -1,42 +1,45 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
|
||||
##
|
||||
## PROJECT
|
||||
##
|
||||
project(inja LANGUAGES CXX VERSION 1.0.1)
|
||||
set(INJA_VERSION ${PROJECT_VERSION})
|
||||
|
||||
|
||||
##
|
||||
## OPTIONS
|
||||
##
|
||||
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
|
||||
option(HUNTER_ENABLED "Use hunter to manage dependencies" OFF)
|
||||
|
||||
|
||||
##
|
||||
## HUNTER
|
||||
##
|
||||
option(HUNTER_ENABLED "Use hunter to manage dependencies" OFF)
|
||||
if(HUNTER_ENABLED)
|
||||
include("cmake/HunterGate.cmake")
|
||||
HunterGate(
|
||||
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
|
||||
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
|
||||
)
|
||||
include("cmake/HunterGate.cmake")
|
||||
HunterGate(
|
||||
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
|
||||
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
|
||||
)
|
||||
endif()
|
||||
|
||||
##
|
||||
## PROJECT
|
||||
## name and version
|
||||
##
|
||||
project(inja LANGUAGES CXX VERSION 1.0.1)
|
||||
set(INJA_VERSION ${PROJECT_VERSION})
|
||||
|
||||
##
|
||||
## CONFIGURATION
|
||||
##
|
||||
# set(CMAKE_CXX_COMPILER g++-7)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
set(INJA_SOURCE_DIR src)
|
||||
set(INJA_HEADER_INSTALL_DIR include)
|
||||
|
||||
if(WIN32 AND MSVC AND MSVC_VERSION LESS 1900)
|
||||
message(FATAL_ERROR "[${PROJECT_NAME}] Visual Studio versions prior to 2015 do not support the noexcept keyword, which is used in the JSON library.")
|
||||
message(FATAL_ERROR "[${PROJECT_NAME}] Visual Studio versions prior to 2015 do not support the noexcept keyword, which is used in the JSON library.")
|
||||
endif()
|
||||
|
||||
|
||||
##
|
||||
## TESTS
|
||||
## create and configure the unit test target
|
||||
@@ -46,28 +49,30 @@ if(BUILD_UNIT_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
||||
##
|
||||
## TARGETS
|
||||
## Build targets for the interface library
|
||||
##
|
||||
add_library(inja INTERFACE)
|
||||
target_include_directories(inja INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
|
||||
)
|
||||
if(HUNTER_ENABLED) # Use Hunter to manage dependencies
|
||||
# Add JSON package
|
||||
hunter_add_package(nlohmann_json)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
# Add dependencies to target
|
||||
target_link_libraries(inja INTERFACE nlohmann_json)
|
||||
# Add JSON package
|
||||
hunter_add_package(nlohmann_json)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
# Add dependencies to target
|
||||
target_link_libraries(inja INTERFACE nlohmann_json)
|
||||
else()
|
||||
target_include_directories(inja INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test/thirdparty>
|
||||
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
|
||||
)
|
||||
target_include_directories(inja INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test/thirdparty>
|
||||
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
##
|
||||
## INSTALL
|
||||
## install header files, generate and install cmake config files for find_package()
|
||||
@@ -81,42 +86,37 @@ set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
|
||||
set(namespace "${PROJECT_NAME}::")
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
# Use:
|
||||
# * PROJECT_VERSION
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${version_config}" COMPATIBILITY SameMajorVersion
|
||||
"${version_config}" COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
|
||||
# Use:
|
||||
# * TARGETS_EXPORT_NAME
|
||||
# * PROJECT_NAME
|
||||
configure_package_config_file(
|
||||
"cmake/Config.cmake.in"
|
||||
"${project_config}"
|
||||
INSTALL_DESTINATION "${config_install_dir}"
|
||||
"cmake/Config.cmake.in"
|
||||
"${project_config}"
|
||||
INSTALL_DESTINATION "${config_install_dir}"
|
||||
)
|
||||
|
||||
install(
|
||||
TARGETS inja
|
||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||
LIBRARY DESTINATION "lib"
|
||||
ARCHIVE DESTINATION "lib"
|
||||
RUNTIME DESTINATION "bin"
|
||||
INCLUDES DESTINATION "${include_install_dir}"
|
||||
TARGETS inja
|
||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||
LIBRARY DESTINATION "lib"
|
||||
ARCHIVE DESTINATION "lib"
|
||||
RUNTIME DESTINATION "bin"
|
||||
INCLUDES DESTINATION "${include_install_dir}"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${INJA_SOURCE_DIR}/inja.hpp
|
||||
DESTINATION "${include_install_dir}"
|
||||
FILES ${INJA_SOURCE_DIR}/inja.hpp
|
||||
DESTINATION "${include_install_dir}"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES "${project_config}" "${version_config}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
FILES "${project_config}" "${version_config}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||
NAMESPACE "${namespace}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||
NAMESPACE "${namespace}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
)
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 lbersch
|
||||
Copyright (c) 2018 lbersch
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Inja - A Template Engine for Modern C++
|
||||
version 1.0.0
|
||||
version 1.1.0
|
||||
https://github.com/pantor/inja
|
||||
|
||||
Licensed under the MIT License <https://opensource.org/licenses/MIT>.
|
||||
@@ -29,8 +29,8 @@ SOFTWARE.
|
||||
#define PANTOR_INJA_HPP
|
||||
|
||||
#define PANTOR_INJA_VERSION_MAJOR 1
|
||||
#define PANTOR_INJA_VERSION_MINOR 0
|
||||
#define PANTOR_INJA_VERSION_PATCH 1
|
||||
#define PANTOR_INJA_VERSION_MINOR 1
|
||||
#define PANTOR_INJA_VERSION_PATCH 0
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,68 +1,70 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
##
|
||||
## HUNTER
|
||||
##
|
||||
option(HUNTER_ENABLED "Use hunter to manage dependencies" OFF)
|
||||
if(HUNTER_ENABLED)
|
||||
include("../cmake/HunterGate.cmake")
|
||||
HunterGate(
|
||||
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
|
||||
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
|
||||
)
|
||||
include("../cmake/HunterGate.cmake")
|
||||
HunterGate(
|
||||
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
|
||||
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
|
||||
)
|
||||
endif()
|
||||
|
||||
##
|
||||
## PROJECT
|
||||
## name and version
|
||||
##
|
||||
project(inja-testing LANGUAGES CXX VERSION ${INJA_VERSION})
|
||||
|
||||
##
|
||||
## TARGETS
|
||||
##
|
||||
set(UNITTEST_TARGET_NAME "inja_unit")
|
||||
file(GLOB TEST_SOURCES "src/*.cpp")
|
||||
add_executable(${UNITTEST_TARGET_NAME} ${TEST_SOURCES})
|
||||
add_executable(inja_test
|
||||
src/unit-files.cpp
|
||||
src/unit-renderer.cpp
|
||||
src/unit-string-helper.cpp
|
||||
src/unit.cpp
|
||||
)
|
||||
|
||||
|
||||
##
|
||||
## INCLUDES
|
||||
##
|
||||
if(HUNTER_ENABLED) # Use Hunter to manage dependencies
|
||||
# Add Catch framework
|
||||
hunter_add_package(Catch)
|
||||
find_package(Catch CONFIG REQUIRED)
|
||||
# Add JSON package
|
||||
hunter_add_package(nlohmann_json)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
# Add dependencies to target
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} Catch::Catch)
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} nlohmann_json)
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} inja)
|
||||
# Add Catch framework
|
||||
hunter_add_package(Catch)
|
||||
find_package(Catch CONFIG REQUIRED)
|
||||
|
||||
# Add JSON package
|
||||
hunter_add_package(nlohmann_json)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
|
||||
# Add dependencies to target
|
||||
target_link_libraries(inja_test Catch::Catch nlohmann_json inja)
|
||||
else() # Manage dependencies manually
|
||||
# Prepare "Catch" library for other executables
|
||||
add_library(Catch INTERFACE)
|
||||
target_include_directories(Catch INTERFACE "thirdparty")
|
||||
# Prepare "JSON" library for other executables
|
||||
add_library(JSON INTERFACE)
|
||||
target_include_directories(JSON INTERFACE "thirdparty")
|
||||
# Add dependencies to target
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} Catch)
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} JSON)
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} inja)
|
||||
# Prepare "Catch" library for other executables
|
||||
add_library(Catch INTERFACE)
|
||||
target_include_directories(Catch INTERFACE "thirdparty")
|
||||
|
||||
# Prepare "JSON" library for other executables
|
||||
add_library(JSON INTERFACE)
|
||||
target_include_directories(JSON INTERFACE "thirdparty")
|
||||
|
||||
# Add dependencies to target
|
||||
target_link_libraries(inja_test Catch JSON inja)
|
||||
endif()
|
||||
|
||||
# Copy test files to build directory
|
||||
|
||||
##
|
||||
## Copy test files to build directory
|
||||
##
|
||||
add_custom_command(
|
||||
TARGET ${UNITTEST_TARGET_NAME} POST_BUILD
|
||||
TARGET inja_test POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_SOURCE_DIR}/test/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data
|
||||
)
|
||||
|
||||
|
||||
##
|
||||
## Add tests to make
|
||||
##
|
||||
add_test(NAME "${UNITTEST_TARGET_NAME}_default"
|
||||
COMMAND ${UNITTEST_TARGET_NAME}
|
||||
add_test(NAME inja_test
|
||||
COMMAND inja_test
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -257,7 +257,7 @@ TEST_CASE("callbacks") {
|
||||
return number1 * number2 * number3;
|
||||
});
|
||||
|
||||
env.add_callback("multiply", 0, [&env](inja::Parsed::Arguments args, json data) {
|
||||
env.add_callback("multiply", 0, [](inja::Parsed::Arguments args, json data) {
|
||||
return 1.0;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user