config: config injection
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
8
test/entt/config/config.cpp
Normal file
8
test/entt/config/config.cpp
Normal 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);
|
||||
}
|
||||
10
test/include/entt/ext/config.h
Normal file
10
test/include/entt/ext/config.h
Normal 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
|
||||
Reference in New Issue
Block a user