소스 검색

Add CMake option to avoid using third-party containers.

Michael Ragazzon 6 년 전
부모
커밋
baef5621bc
3개의 변경된 파일21개의 추가작업 그리고 10개의 파일을 삭제
  1. 1 1
      .travis.yml
  2. 6 0
      CMakeLists.txt
  3. 14 9
      Include/RmlUi/Core/Types.h

+ 1 - 1
.travis.yml

@@ -55,7 +55,7 @@ before_install:
 install:
   - cd "$TRAVIS_BUILD_DIR"
   - if [[ "$TRAVIS_OS_NAME" != "osx" ]]; then cmake -DBUILD_LUA_BINDINGS=ON -DBUILD_SAMPLES=ON .; fi
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cmake -G Xcode .; fi
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cmake -DNO_THIRDPARTY_CONTAINERS=ON -G Xcode .; fi
 
 before_script:
   - if [[ "$VALGRIND_SAMPLES" == "1" ]] && [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0 && sh -e /etc/init.d/xvfb start && sleep 3; fi

+ 6 - 0
CMakeLists.txt

@@ -159,6 +159,12 @@ if(NOT BUILD_SHARED_LIBS)
 	add_definitions(-DRMLUI_STATIC_LIB)
 endif()
 
+option(NO_THIRDPARTY_CONTAINERS "Only use standard library containers." OFF)
+if( NO_THIRDPARTY_CONTAINERS )
+	add_definitions(-DRMLUI_NO_THIRDPARTY_CONTAINERS)
+	message("-- No third-party containers will be used: Make sure to #define RMLUI_NO_THIRDPARTY_CONTAINERS before including RmlUi in your project.")
+endif()
+
 #===================================
 # Find dependencies ================
 #===================================

+ 14 - 9
Include/RmlUi/Core/Types.h

@@ -37,16 +37,17 @@
 #include <set>
 #include <unordered_set>
 #include <vector>
-#include "Containers/chobo/flat_map.hpp"
-#include "Containers/chobo/flat_set.hpp"
-#include "Containers/robin_hood.h"
 
 #include "Platform.h"
 #include "Debug.h"
 #include "Traits.h"
 
-#ifdef RMLUI_DEBUG
+#ifdef RMLUI_NO_THIRDPARTY_CONTAINERS
 #include <unordered_map>
+#else
+#include "Containers/chobo/flat_map.hpp"
+#include "Containers/chobo/flat_set.hpp"
+#include "Containers/robin_hood.h"
 #endif
 
 namespace Rml {
@@ -129,22 +130,26 @@ using ElementPtr = UniqueReleaserPtr<Element>;
 using ContextPtr = UniqueReleaserPtr<Context>;
 using EventPtr = UniqueReleaserPtr<Event>;
 
-// Custom containers
-#ifdef RMLUI_DEBUG
+// Containers
+#ifdef RMLUI_NO_THIRDPARTY_CONTAINERS
 template <typename Key, typename Value>
 using UnorderedMap = std::unordered_map< Key, Value >;
+template <typename Key, typename Value>
+using SmallUnorderedMap = UnorderedMap< Key, Value >;
+template <typename T>
+using SmallOrderedSet = std::set< T >;
+template <typename T>
+using SmallUnorderedSet = std::unordered_set< T >;
 #else
 template < typename Key, typename Value>
 using UnorderedMap = robin_hood::unordered_flat_map< Key, Value >;
-#endif
 template <typename Key, typename Value>
 using SmallUnorderedMap = chobo::flat_map< Key, Value >;
 template <typename T>
 using SmallOrderedSet = chobo::flat_set< T >;
 template <typename T>
 using SmallUnorderedSet = chobo::flat_set< T >;
-// Note: Right now the SmallOrderedSet and SmallUnorderedSet use the same container. However, as we may 
-// want to change this later, use the ordered container strictly when a sorted container is needed.
+#endif
 
 
 // Container types for common classes