Skip to content

Commit

Permalink
Inja v2 (#67)
Browse files Browse the repository at this point in the history
* inja2

* header only

* reduce dependencies

* code cleaning

* c++17

* use stdc++

* code cleaning

* infrastructure

* header only

* add infrastructure

* fix tests

* use minimum clang 6

* code cleaning, polyfill for c++11

* fix some file tests

* fix readme

* update appveyor

* fix polyfill and ci

* fix polyfill

* fix ci?

* test msvc __cplusplus

* add doxygen

* activate all tests

* code cleaning

* add coveralls, set default to dot notation

* add html test

* add doxygen comments

* test single_include file

* change build folder in appveyor

* correct make arguments in appveyor

* fix appveyor arguments
  • Loading branch information
pantor authored Dec 23, 2018
1 parent d90f93f commit 699c207
Show file tree
Hide file tree
Showing 77 changed files with 7,417 additions and 3,519 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ dist
.coveralls.yml

.vscode

doc/html
doc/latex
89 changes: 21 additions & 68 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,56 @@ sudo: required

matrix:
include:
### Coveralls ###
- os: linux
compiler: gcc
env: COMPILER=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-5
before_install:
- pip install --user cpp-coveralls
after_success:
- make clean
# - coveralls --exclude lib --exclude tests --gcov-options '\-lp'

- os: linux
compiler: gcc
env: COMPILER=g++-4.9
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-4.9

- os: linux
compiler: gcc
env: COMPILER=g++-5
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-5

- os: linux
compiler: gcc
env: COMPILER=g++-6
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: g++-6

- os: linux
compiler: gcc
env: COMPILER=g++-7
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
sources: ubuntu-toolchain-r-test
packages: g++-7

- os: linux
compiler: clang
env: COMPILER=clang++-3.6
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6']
packages: clang-3.6

- os: linux
compiler: clang
env: COMPILER=clang++-3.7
compiler: gcc
env:
- COMPILER=g++-8
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7']
packages: clang-3.7
sources: ubuntu-toolchain-r-test
packages: g++-8

- os: linux
compiler: clang
env: COMPILER=clang++-4.0
compiler: gcc
env:
- COMPILER=g++-8
- CXXFLAGS=-std=c++17
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-4.0']
packages: ['g++-6', 'clang-4.0']
sources: ubuntu-toolchain-r-test
packages: g++-8

- os: linux
compiler: clang
env: COMPILER=clang++-5.0
env: COMPILER=clang++-6.0
addons:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-5.0']
packages: ['g++-6', 'clang-5.0']

- os: osx
osx_image: xcode7.3
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-6.0']
packages: ['clang-6.0', 'libstdc++-7-dev']

- os: osx
osx_image: xcode8

- os: osx
osx_image: xcode8.3
osx_image: xcode9

- os: osx
osx_image: xcode9
osx_image: xcode10


script:
- if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi
- uname -a
- $CXX --version

- mkdir -p build && cd build
- cmake .. && cmake --build . --config Release -- -j4
- mkdir -p build
- cd build
- cmake ..
- cmake --build . --config Release -- -j4
- ctest -C Release -V
- cd ..
166 changes: 49 additions & 117 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,137 +1,69 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.5)


##
## PROJECT
##
project(inja LANGUAGES CXX VERSION 1.0.1)
set(INJA_VERSION ${PROJECT_VERSION})
project(inja LANGUAGES CXX VERSION 2.0.0)


##
## OPTIONS
##
option(BUILD_UNIT_TESTS "Build the unit tests" ON)
option(BUILD_BENCHMARK "Build the inja benchmark" OFF)
option(HUNTER_ENABLED "Use hunter to manage dependencies" OFF)
option(BUILD_TESTS "Build the inja unit tests" ON)
option(BUILD_BENCHMARK "Build the inja benchmark" ON)
option(COVERALLS "Generate coveralls data" OFF)


##
## HUNTER
##
if(HUNTER_ENABLED)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.156.tar.gz"
SHA1 "8d5e4635b137365e0d1ade4d60accf4e2bb41f0d"
)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE Release)
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")


##
## CONFIGURATION
##
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(INJA_INCLUDE_DIR include)
set(INJA_SINGLE_INCLUDE_DIR single_include)
set(INJA_HEADER_INSTALL_DIR include)
add_library(inja INTERFACE)
target_include_directories(inja INTERFACE include)


execute_process(COMMAND python3 amalgamate/amalgamate.py -c amalgamate/config.json -s include WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})


if (COVERALLS)
include(Coveralls)
coveralls_turn_on_coverage()

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.")
file(GLOB_RECURSE COVERAGE_SRCS include/inja/*.hpp)

# set(COVERAGE_SRCS test/unit.cpp test/unit-renderer.cpp include/inja)

coveralls_setup("${COVERAGE_SRCS}" OFF) # If we should upload.
endif()


##
## TESTS
## create and configure the unit test target
##
if(BUILD_UNIT_TESTS)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

add_executable(inja_test
test/unit.cpp
test/unit-files.cpp
test/unit-renderer.cpp
)
target_link_libraries(inja_test PRIVATE inja)

##
## AMALGAMATE
## amalgamate header files into single_include
##
execute_process(COMMAND python3 amalgamate/amalgamate.py -c amalgamate/config.json -s include
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
add_test(inja_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/inja_test)


##
## TARGETS
## Build targets for the interface library
##
add_library(inja INTERFACE)
target_include_directories(inja INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${INJA_HEADER_INSTALL_DIR}>
)


add_library(inja_single INTERFACE)
target_include_directories(inja_single INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_SINGLE_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INJA_INCLUDE_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_library(single_inja INTERFACE)
target_include_directories(single_inja INTERFACE single_include include)

add_executable(single_inja_test
test/unit.cpp
test/unit-files.cpp
test/unit-renderer.cpp
)
target_link_libraries(single_inja_test PRIVATE single_inja)

add_test(single_inja_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/single_inja_test)
endif()


##
## INSTALL
## install header files, generate and install cmake config files for find_package()
##
set(include_install_dir ${INJA_HEADER_INSTALL_DIR})
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)


write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"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}"
)

install(
FILES ${INJA_INCLUDE_DIR}/inja.hpp
DESTINATION "${include_install_dir}"
)

install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
if(BUILD_BENCHMARK)
add_executable(inja_benchmark test/benchmark.cpp)
target_link_libraries(inja_benchmark PRIVATE inja)
endif()
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,32 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---


Copyright (c) 2009-2018 FIRST
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the FIRST nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY FIRST AND CONTRIBUTORS``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 699c207

Please sign in to comment.