hemplate

Simple XML template engine
git clone git://git.dimitrijedobrota.com/hemplate.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit faaee8fde5745e50fdb31fb1ca804c6876956b1a
parent 6db03b9dad805863dd70bfda01d371212a004803
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Wed, 23 Apr 2025 09:03:22 +0200

Modernize build for vcpkg and proper testing

Diffstat:
M BUILDING.md | ++++
M CMakeLists.txt | +++++++++++++
M CMakePresets.json | +++++++++++++++++++++++++++ -----------------------
M HACKING.md | ++++++++++++ --------------------------
M README.md | ++++++ --------------
M cmake/install-config.cmake | ++++++ -
A example/CMakeLists.txt | +++++++++++++++++++++++++
A example/html.cpp | ++++++++++++++++++++++++++++++++++
M test/CMakeLists.txt | ++++++++++ ---------
D test/source/hemplate_test.cpp | ----------------------------------
A vcpkg-configuration.json | +++++++++++++++
A vcpkg.json | +++++++++++++++++++++++

12 files changed, 175 insertions(+), 107 deletions(-)


diff --git a/ BUILDING.md b/ BUILDING.md

@@ -1,5 +1,9 @@ # Building with CMake
## Dependencies
For a list of dependencies, please refer to [vcpkg.json](vcpkg.json).
## Build This project doesn't require any special command-line flags to build to keep

diff --git a/ CMakeLists.txt b/ CMakeLists.txt

@@ -13,6 +13,8 @@ project( include(cmake/project-is-top-level.cmake) include(cmake/variables.cmake)
find_package(based 0.1 CONFIG REQUIRED)
# ---- Declare library ---- add_library(

@@ -21,6 +23,7 @@ add_library( source/element.cpp source/attribute.cpp )
target_link_libraries(hemplate_hemplate PUBLIC based::based)
add_library(hemplate::hemplate ALIAS hemplate_hemplate) include(GenerateExportHeader)

@@ -65,6 +68,16 @@ if(NOT CMAKE_SKIP_INSTALL_RULES) include(cmake/install-rules.cmake) endif()
# ---- Examples ----
if(PROJECT_IS_TOP_LEVEL)
option(BUILD_EXAMPLES "Build examples tree." "${hemplate_DEVELOPER_MODE}")
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()
endif()
# ---- Developer mode ---- if(NOT hemplate_DEVELOPER_MODE)

diff --git a/ CMakePresets.json b/ CMakePresets.json

@@ -7,26 +7,25 @@ }, "configurePresets": [ {
"name": "cmake-pedantic",
"name": "dev-mode",
"hidden": true,
"warnings": {
"dev": true,
"deprecated": true,
"uninitialized": true,
"unusedCli": true,
"systemVars": false
},
"errors": {
"dev": true,
"deprecated": true
"cacheVariables": {
"hemplate_DEVELOPER_MODE": "ON",
"VCPKG_MANIFEST_FEATURES": "test"
} }, {
"name": "dev-mode",
"name": "vcpkg",
"hidden": true,
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "vcpkg-win64-static",
"hidden": true,
"inherits": "cmake-pedantic",
"cacheVariables": {
"hemplate_DEVELOPER_MODE": "ON"
"VCPKG_TARGET_TRIPLET": "x64-windows-static-md"
} }, {

@@ -93,7 +92,10 @@ "name": "ci-darwin", "inherits": ["flags-appleclang", "ci-std"], "generator": "Xcode",
"hidden": true
"hidden": true,
"cacheVariables": {
"CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE": "PRE_TEST"
}
}, { "name": "ci-win64",

@@ -110,14 +112,15 @@ "cacheVariables": { "ENABLE_COVERAGE": "ON", "CMAKE_BUILD_TYPE": "Coverage",
"CMAKE_CXX_FLAGS_COVERAGE": "-Og -g --coverage -fkeep-inline-functions -fkeep-static-functions",
"CMAKE_CXX_FLAGS_COVERAGE": "-O0 -g --coverage -fkeep-inline-functions -fkeep-static-functions",
"CMAKE_EXE_LINKER_FLAGS_COVERAGE": "--coverage",
"CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage"
"CMAKE_SHARED_LINKER_FLAGS_COVERAGE": "--coverage",
"CMAKE_MAP_IMPORTED_CONFIG_COVERAGE": "Coverage;RelWithDebInfo;Release;Debug;"
} }, { "name": "ci-coverage",
"inherits": ["coverage-linux", "dev-mode"],
"inherits": ["coverage-linux", "dev-mode", "vcpkg"],
"cacheVariables": { "COVERAGE_HTML_COMMAND": "" }

@@ -125,10 +128,11 @@ { "name": "ci-sanitize", "binaryDir": "${sourceDir}/build/sanitize",
"inherits": ["ci-linux", "dev-mode"],
"inherits": ["ci-linux", "dev-mode", "vcpkg"],
"cacheVariables": { "CMAKE_BUILD_TYPE": "Sanitize",
"CMAKE_CXX_FLAGS_SANITIZE": "-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common"
"CMAKE_CXX_FLAGS_SANITIZE": "-U_FORTIFY_SOURCE -O2 -g -fsanitize=address,undefined -fno-omit-frame-pointer -fno-common",
"CMAKE_MAP_IMPORTED_CONFIG_SANITIZE": "Sanitize;RelWithDebInfo;Release;Debug;"
} }, {

@@ -146,15 +150,15 @@ }, { "name": "ci-macos",
"inherits": ["ci-build", "ci-darwin", "dev-mode", "ci-multi-config"]
"inherits": ["ci-build", "ci-darwin", "dev-mode", "ci-multi-config", "vcpkg"]
}, { "name": "ci-ubuntu",
"inherits": ["ci-build", "ci-linux", "clang-tidy", "cppcheck", "dev-mode"]
"inherits": ["ci-build", "ci-linux", "clang-tidy", "vcpkg", "cppcheck", "dev-mode"]
}, { "name": "ci-windows",
"inherits": ["ci-build", "ci-win64", "dev-mode", "ci-multi-config"]
"inherits": ["ci-build", "ci-win64", "dev-mode", "ci-multi-config", "vcpkg", "vcpkg-win64-static"]
} ] }

diff --git a/ HACKING.md b/ HACKING.md

@@ -41,7 +41,7 @@ the project: { "name": "dev", "binaryDir": "${sourceDir}/build/dev",
"inherits": ["dev-mode", "ci-<os>"],
"inherits": ["dev-mode", "vcpkg", "ci-<os>"],
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }

@@ -87,6 +87,17 @@ in the terminal. > in `Tools > Options > CMake` **prior to opening the project**, after which > you can manually configure using `Project > Configure Cache`.
### Dependency manager
The above preset will make use of the [vcpkg][vcpkg] dependency manager. After
installing it, make sure the `VCPKG_ROOT` environment variable is pointing at
the directory where the vcpkg executable is. On Windows, you might also want
to inherit from the `vcpkg-win64-static` preset, which will make vcpkg install
the dependencies as static libraries. This is only necessary if you don't want
to setup `PATH` to run tests.
[vcpkg]: https://github.com/microsoft/vcpkg
### Configure, build and test If you followed the above instructions, then you can configure, build and test

@@ -141,30 +152,5 @@ These targets run the codespell tool on the codebase to check errors and to fix them respectively. Customization available using the `SPELL_COMMAND` cache variable.
## Running tests on Windows with `BUILD_SHARED_LIBS=ON`
If you are building a shared library on Windows, you must add the path to the
DLL file to `PATH` when you want to run tests. One way you could do that is by
using PowerShell and writing a script for it, e.g. `env.ps1` at the project
root:
```powershell
$oldPrompt = (Get-Command prompt).ScriptBlock
function prompt() { "(Debug) $(& $oldPrompt)" }
$VsInstallPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -Property InstallationPath
$Env:Path += ";$VsInstallPath\Common7\IDE;$Pwd\build\dev\Debug"
```
Then you can source this script by running `. env.ps1`. This particular
example will only work for Debug builds.
### Passing `PATH` to editors
Make sure you launch your editor of choice from the console with the above
script sourced. Look for `(Debug)` in the prompt to confirm, then run e.g.
`code .` for VScode or `devenv .` for Visual Studio.
[1]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html [2]: https://cmake.org/download/

diff --git a/ README.md b/ README.md

@@ -14,23 +14,17 @@ The big source of inspiration for this project is GNU cgicc. ## Dependencies * CMake 3.14 or latter
* Compiler with C++20 support (tested: clang 16.0.5, gcc 13.2.0)
* Compiler with C++20 support (tested on clang version 19.1.7)
## Building and installing
See the [BUILDING](BUILDING.md) document.
See the [`BUILDING`](BUILDING.md) document.
## Usage
> Please reference demo folder for relevant usage example.
## Help
Refer to [GNU cgicc documentation](https://www.gnu.org/software/chicc/)
> Please reference example folder for relevant usage examples.
## Version History

@@ -43,14 +37,12 @@ Refer to [GNU cgicc documentation](https://www.gnu.org/software/chicc/) ## Contributing
See the [CONTRIBUTING](CONTRIBUTING.md) document.
See the [`CONTRIBUTING`](CONTRIBUTING.md) document.
## Licensing
This project is licensed under the MIT License -
see the [LICENSE](LICENSE.md) document for details
## License
This project is licensed under the MIT License - see the [`LICENSE`](LICENSE.md) file for details
## Acknowledgments

diff --git a/ cmake/install-config.cmake b/ cmake/install-config.cmake

@@ -1,1 +1,6 @@
include("${CMAKE_CURRENT_LIST_DIR}/hemplateTargets.cmake")
include(CMakeFindDependencyMacro)
find_dependency(based)
if(based_FOUND)
include("${CMAKE_CURRENT_LIST_DIR}/hemplateTargets.cmake")
endif()

diff --git a/ example/CMakeLists.txt b/ example/CMakeLists.txt

@@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.14)
project(hemplateExamples CXX)
include(../cmake/project-is-top-level.cmake)
include(../cmake/folders.cmake)
if(PROJECT_IS_TOP_LEVEL)
find_package(hemplate REQUIRED)
endif()
add_custom_target(run-examples)
function(add_example NAME)
add_executable("${NAME}" "${NAME}.cpp")
target_link_libraries("${NAME}" PRIVATE hemplate::hemplate)
target_compile_features("${NAME}" PRIVATE cxx_std_20)
add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM)
add_dependencies("run_${NAME}" "${NAME}")
add_dependencies(run-examples "run_${NAME}")
endfunction()
add_example(html)
add_folders(Example)

diff --git a/ example/html.cpp b/ example/html.cpp

@@ -0,0 +1,34 @@
#include <iostream>
#include "hemplate/attribute.hpp"
#include "hemplate/html.hpp"
int main()
{
using namespace hemplate; // NOLINT
const attribute_list li_attrs {{"class", "home_li"}};
const attribute_list ul_attrs {
{"id", "main_ul"},
{"class", "home_ul"},
{"style", "margin-bottom: 1em"},
};
std::cout << html::html {
comment("Hello this is a comment"),
html::ul {
ul_attrs,
html::li {
li_attrs.add("class", "item1"),
"Item 1",
},
html::li {
li_attrs.add("class", "item2"),
"Item 2",
},
},
html::meta(),
};
return 0;
}

diff --git a/ test/CMakeLists.txt b/ test/CMakeLists.txt

@@ -5,20 +5,21 @@ project(hemplateTests LANGUAGES CXX) include(../cmake/project-is-top-level.cmake) include(../cmake/folders.cmake)
# ---- Dependencies ----
if(PROJECT_IS_TOP_LEVEL)
find_package(hemplate REQUIRED)
enable_testing()
endif()
find_package(Catch2 REQUIRED)
include(Catch)
# ---- Tests ----
add_executable(hemplate_test source/hemplate_test.cpp)
target_link_libraries(hemplate_test PRIVATE hemplate::hemplate)
target_compile_features(hemplate_test PRIVATE cxx_std_20)
add_test(NAME hemplate_test COMMAND hemplate_test)
function(add_test NAME)
add_executable("${NAME}" "source/${NAME}.cpp")
target_link_libraries("${NAME}" PRIVATE hemplate::hemplate)
target_link_libraries("${NAME}" PRIVATE Catch2::Catch2WithMain)
target_compile_features("${NAME}" PRIVATE cxx_std_20)
catch_discover_tests("${NAME}")
endfunction()
# ---- End-of-file commands ----

diff --git a/ test/source/hemplate_test.cpp b/ test/source/hemplate_test.cpp

@@ -1,34 +0,0 @@
#include <iostream>
#include "hemplate/attribute.hpp"
#include "hemplate/html.hpp"
int main()
{
using namespace hemplate; // NOLINT
const attribute_list li_attrs {{"class", "home_li"}};
const attribute_list ul_attrs {
{"id", "main_ul"},
{"class", "home_ul"},
{"style", "margin-bottom: 1em"},
};
std::cout << html::html {
comment("Hello this is a comment"),
html::ul {
ul_attrs,
html::li {
li_attrs.add("class", "item1"),
"Item 1",
},
html::li {
li_attrs.add("class", "item2"),
"Item 2",
},
},
html::meta(),
};
return 0;
}

diff --git a/ vcpkg-configuration.json b/ vcpkg-configuration.json

@@ -0,0 +1,15 @@
{
"default-registry": {
"kind": "git",
"baseline": "566f9496b7e00ee0cc00aca0ab90493d122d148a",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "git",
"repository": "git://git.dimitrijedobrota.com/vcpkg-registry.git",
"baseline": "93159a6024f170bb5fedd97daad8b7dd8dbc99ab",
"packages": [ "based" ]
}
]
}

diff --git a/ vcpkg.json b/ vcpkg.json

@@ -0,0 +1,23 @@
{
"name": "hemplate",
"version-semver": "0.4.0",
"dependencies": [
{
"name": "based",
"version>=": "0.1"
}
],
"default-features": [],
"features": {
"test": {
"description": "Dependencies for testing",
"dependencies": [
{
"name": "catch2",
"version>=": "3.7.1"
}
]
}
},
"builtin-baseline": "eba7c6a894fce24146af4fdf161fef8e90dd6be3"
}