diff --git a/docs/md/config.md b/docs/md/config.md index 5f9ff6f2e..06c001a61 100644 --- a/docs/md/config.md +++ b/docs/md/config.md @@ -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++.
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.
+`EnTT` uses `__has_include` internally and looks for a specific path, namely +``. This can be provided by the user by setting the include +paths appropriately.
+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. diff --git a/src/entt/config/config.h b/src/entt/config/config.h index 3511229aa..1b54e7a36 100644 --- a/src/entt/config/config.h +++ b/src/entt/config/config.h @@ -1,6 +1,10 @@ #ifndef ENTT_CONFIG_CONFIG_H #define ENTT_CONFIG_CONFIG_H +#if __has_include() +# include +#endif + #include "version.h" // NOLINTBEGIN(cppcoreguidelines-macro-usage) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bc385ad06..2a319642d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/entt/config/config.cpp b/test/entt/config/config.cpp new file mode 100644 index 000000000..92b3a70d7 --- /dev/null +++ b/test/entt/config/config.cpp @@ -0,0 +1,8 @@ +#include +#include + +TEST(Config, All) { + ASSERT_TRUE(ENTT_EXT_CONFIG); + ASSERT_EQ(ENTT_SPARSE_PAGE, 512); + ASSERT_EQ(ENTT_PACKED_PAGE, 128); +} diff --git a/test/include/entt/ext/config.h b/test/include/entt/ext/config.h new file mode 100644 index 000000000..9a1f2a228 --- /dev/null +++ b/test/include/entt/ext/config.h @@ -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