Bläddra i källkod

config: config injection

skypjack 3 dagar sedan
förälder
incheckning
06bcc770f0
5 ändrade filer med 40 tillägg och 0 borttagningar
  1. 12 0
      docs/md/config.md
  2. 4 0
      src/entt/config/config.h
  3. 6 0
      test/CMakeLists.txt
  4. 8 0
      test/entt/config/config.cpp
  5. 10 0
      test/include/entt/ext/config.h

+ 12 - 0
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++.<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.

+ 4 - 0
src/entt/config/config.h

@@ -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)

+ 6 - 0
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

+ 8 - 0
test/entt/config/config.cpp

@@ -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 - 0
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