config: config injection

This commit is contained in:
skypjack
2026-03-23 16:46:24 +01:00
parent 75769cde27
commit 06bcc770f0
5 changed files with 40 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
* [ENTT_NO_ETO](#entt_no_eto)
* [ENTT_NO_MIXIN](#entt_no_mixin)
* [ENTT_STANDARD_CPP](#entt_standard_cpp)
* [Configuration injection](#configuration-injection)
# Introduction
@@ -130,3 +131,14 @@ This definition prevents the library from using non-standard techniques, that
is, functionalities that are not fully compliant with the standard C++.<br/>
While there are no known portability issues at the time of this writing, this
should make the library fully portable anyway if needed.
# Configuration injection
Configuration variables are provided via code or injected directly from the
outside via a dedicated file.<br/>
`EnTT` uses `__has_include` internally and looks for a specific path, namely
`<entt/ext/config.h>`. This can be provided by the user by setting the include
paths appropriately.<br/>
For example, `CMake` allows users to _bind_ additional include directories to a
target with `target_include_directories`. See the test suite, and in particular
the `config_ext` test for a practical example.

View File

@@ -1,6 +1,10 @@
#ifndef ENTT_CONFIG_CONFIG_H
#define ENTT_CONFIG_CONFIG_H
#if __has_include(<entt/ext/config.h>)
# include <entt/ext/config.h>
#endif
#include "version.h"
// NOLINTBEGIN(cppcoreguidelines-macro-usage)

View File

@@ -220,6 +220,12 @@ endif()
# Test config
SETUP_BASIC_TEST(
NAME config_ext
SOURCES entt/config/config.cpp
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include
)
SETUP_BASIC_TEST(
NAME config
SOURCES entt/config/version.cpp

View File

@@ -0,0 +1,8 @@
#include <gtest/gtest.h>
#include <entt/config/config.h>
TEST(Config, All) {
ASSERT_TRUE(ENTT_EXT_CONFIG);
ASSERT_EQ(ENTT_SPARSE_PAGE, 512);
ASSERT_EQ(ENTT_PACKED_PAGE, 128);
}

View File

@@ -0,0 +1,10 @@
#ifndef ENTT_INCLUDE_EXT_CONFIG_H
#define ENTT_INCLUDE_EXT_CONFIG_H
#define ENTT_EXT_CONFIG true
// let's configure something just to be able to check it in the testsuite
#define ENTT_SPARSE_PAGE 512
#define ENTT_PACKED_PAGE 128
#endif