├── .gitignore ├── 3rd-party ├── CMakeLists.txt └── eastl │ ├── CMakeLists.txt │ ├── README │ ├── contrib │ └── example │ │ ├── README │ │ └── example.cpp │ ├── include │ ├── EABase │ │ ├── config │ │ │ ├── eacompiler.h │ │ │ ├── eacompilertraits.h │ │ │ └── eaplatform.h │ │ ├── eabase.h │ │ └── earesult.h │ └── EASTL │ │ ├── algorithm.h │ │ ├── allocator.h │ │ ├── bitset.h │ │ ├── bonus │ │ └── sort_extra.h │ │ ├── core_allocator_adapter.h │ │ ├── fixed_allocator.h │ │ ├── fixed_hash_map.h │ │ ├── fixed_hash_set.h │ │ ├── fixed_list.h │ │ ├── fixed_map.h │ │ ├── fixed_set.h │ │ ├── fixed_string.h │ │ ├── fixed_substring.h │ │ ├── fixed_vector.h │ │ ├── functional.h │ │ ├── hash_map.h │ │ ├── hash_set.h │ │ ├── heap.h │ │ ├── internal │ │ ├── config.h │ │ ├── eastl_rw.h │ │ ├── fixed_pool.h │ │ ├── generic_iterator.h │ │ ├── hashtable.h │ │ ├── red_black_tree.h │ │ ├── type_compound.h │ │ ├── type_fundamental.h │ │ ├── type_pod.h │ │ ├── type_properties.h │ │ └── type_transformations.h │ │ ├── iterator.h │ │ ├── list.h │ │ ├── map.h │ │ ├── memory.h │ │ ├── set.h │ │ ├── sort.h │ │ ├── string.h │ │ ├── type_traits.h │ │ ├── utility.h │ │ └── vector.h │ └── src │ ├── allocator.cpp │ ├── assert.cpp │ ├── fixed_pool.cpp │ ├── hashtable.cpp │ ├── new.cpp │ ├── red_black_tree.cpp │ └── string.cpp ├── CMAKE_NOTES.md ├── CMakeLists.txt ├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── app.cpp ├── app.h ├── main.cpp └── version.h ├── app2 ├── .gitignore ├── CMakeLists.txt ├── app2.cpp ├── app2.h ├── main.cpp └── version.h ├── bar ├── CMakeLists.txt ├── bar.cpp ├── bar.h ├── bar_msg.proto └── test │ ├── .gitignore │ ├── CMakeLists.txt │ └── main.cpp ├── bootstrap ├── foo ├── CMakeLists.txt ├── foo.cpp ├── foo.h ├── foo_msg.proto └── test │ ├── .gitignore │ ├── CMakeLists.txt │ └── main.cpp ├── gui ├── .gitignore ├── CMakeLists.txt ├── icon.png ├── main.cpp ├── message.h └── resources.qrc ├── projects ├── project1.cmake ├── project2.cmake └── projects.cmake └── scripts └── cmake ├── .gitignore ├── all.cmake ├── bin.cmake ├── build_config.cmake ├── ccache.cmake ├── compile_flags.cmake ├── create_version.cmake ├── default_build.cmake ├── dependencies.cmake ├── find_lib.cmake ├── include_guard.cmake ├── install.cmake ├── install_makefile.cmake ├── install_tagged.cmake ├── lib.cmake ├── makefile ├── message.cmake ├── module.cmake ├── print_build_config.cmake ├── project.cmake ├── protoc.cmake ├── settings.cmake ├── string.cmake ├── test.cmake ├── utils.cmake ├── version.cc.in └── version.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | app/version_details.h 2 | 3 | .cproject 4 | .project 5 | 6 | Makefile 7 | CMakeCache.txt 8 | CMakeFiles 9 | cmake_install.cmake 10 | CTestTestfile.cmake 11 | 12 | build 13 | bin 14 | 15 | *.a 16 | makefile 17 | .build 18 | *.pb.cc 19 | *.pb.h 20 | Testing/ 21 | -------------------------------------------------------------------------------- /3rd-party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | module(3rd-party) 2 | 3 | add_subdirectory(eastl) 4 | -------------------------------------------------------------------------------- /3rd-party/eastl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS "src/*.cpp") 2 | 3 | lib( 4 | NAME eastl 5 | STATIC 6 | MODULE 3rd-party 7 | SRCS ${SRCS} 8 | ) 9 | 10 | target_include_directories(eastl.lib SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include") 11 | target_compile_options (eastl.lib PRIVATE -Wno-unused-local-typedefs) 12 | target_compile_options (eastl.lib PRIVATE -Wno-unused-parameter) 13 | -------------------------------------------------------------------------------- /3rd-party/eastl/README: -------------------------------------------------------------------------------- 1 | -- About this library -- 2 | 3 | This library consists of the portion of EASTL which has been made open source 4 | through the EAWebKit distribution. EA has made these files available in zip 5 | format at http://gpl.ea.com . The purpose of this github project is to serve up 6 | these files in a more convenient way. This project isn't affiliated or endorsed 7 | by EA. 8 | 9 | EASTL is an STL replacement that is optimized for games. To learn more about 10 | EASTL, go here: 11 | http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html 12 | 13 | If you're just browsing, then most of the good stuff is under include/EASTL/ 14 | 15 | These files are only *part* of the actual EASTL library. According to Paul 16 | Pedriana, only 50-60% of EASTL is officially published; the remainder may be 17 | published sometime in the future. There's also a large suite of unit tests and 18 | benchmarks which are not yet published. 19 | 20 | -- Usage -- 21 | 22 | Add the 'include' directory to your include path, and the contents of 'src' to 23 | your project's source files. Alternatively, you can compile the 'src' files into 24 | a shared library and link against that. 25 | 26 | At minimum, you'll need to implement a default allocator function, since this is 27 | deliberately left unimplemented in EASTL. Here's the simplest code that will 28 | work: 29 | 30 | void* operator new[](size_t size, const char* pName, int flags, 31 | unsigned debugFlags, const char* file, int line) 32 | { 33 | return malloc(size); 34 | } 35 | void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, 36 | const char* pName, int flags, unsigned debugFlags, const char* file, int line) 37 | { 38 | // doesn't support alignment 39 | return malloc(size); 40 | } 41 | 42 | Another function left unimplemented is Vsnprintf8, which can be as simple as: 43 | 44 | int Vsnprintf8(char8_t* pDestination, size_t n, const char8_t* pFormat, 45 | va_list arguments) 46 | { 47 | #ifdef _MSC_VER 48 | return _vsnprintf(pDestination, n, pFormat, arguments); 49 | #else 50 | return vsnprintf(pDestination, n, pFormat, arguments); 51 | #endif 52 | } 53 | 54 | There is also a wealth of compiler flags to choose from, refer to the file 55 | include/EASTL/internal/config.h to see what settings are available. 56 | 57 | For your debug builds, make sure to use the _DEBUG preprocessor flag, as this 58 | will enable many appropriate settings in EASTL. Alternatively, you could enable 59 | EA_DEBUG or EASTL_DEBUG for similar effect. 60 | 61 | For more documentation, you'll have to read the source code. :) 62 | -------------------------------------------------------------------------------- /3rd-party/eastl/contrib/example/README: -------------------------------------------------------------------------------- 1 | 2 | This is a simple app written to test some simple usage of EASTL. This application 3 | was not written or endorsed by EA. 4 | -------------------------------------------------------------------------------- /3rd-party/eastl/contrib/example/example.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Simple program, basic usage of some EASTL containers. 3 | 4 | #include 5 | #include 6 | 7 | // EASTL expects us to define these, see allocator.h line 194 8 | void* operator new[](size_t size, const char* pName, int flags, 9 | unsigned debugFlags, const char* file, int line) 10 | { 11 | return malloc(size); 12 | } 13 | void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, 14 | const char* pName, int flags, unsigned debugFlags, const char* file, int line) 15 | { 16 | // this allocator doesn't support alignment 17 | EASTL_ASSERT(alignment <= 8); 18 | return malloc(size); 19 | } 20 | 21 | // EASTL also wants us to define this (see string.h line 197) 22 | int Vsnprintf8(char8_t* pDestination, size_t n, const char8_t* pFormat, va_list arguments) 23 | { 24 | #ifdef _MSC_VER 25 | return _vsnprintf(pDestination, n, pFormat, arguments); 26 | #else 27 | return vsnprintf(pDestination, n, pFormat, arguments); 28 | #endif 29 | } 30 | 31 | void test_hash_map() 32 | { 33 | eastl::hash_map map; 34 | map["key1"] = "value1"; 35 | map["key2"] = "value2"; 36 | EASTL_ASSERT(map.find("key1")->second == "value1"); 37 | } 38 | 39 | void test_string() 40 | { 41 | eastl::string str; 42 | str += "testing "; 43 | str += "simple "; 44 | str += "string "; 45 | str += "concat"; 46 | EASTL_ASSERT(str == "testing simple string concat"); 47 | 48 | str.sprintf("%d", 20); 49 | EASTL_ASSERT(str == "20"); 50 | } 51 | 52 | int main(int i, char** c) 53 | { 54 | test_hash_map(); 55 | test_string(); 56 | } 57 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EABase/earesult.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /*----------------------------------------------------------------------------- 30 | * earesult.h 31 | * 32 | * Copyright (c) 2002 - 2005 Electronic Arts Inc. All rights reserved. 33 | * Maintained by Paul Pedriana, Maxis 34 | *---------------------------------------------------------------------------*/ 35 | 36 | 37 | #ifndef INCLUDED_earesult_H 38 | #define INCLUDED_earesult_H 39 | 40 | 41 | #ifndef INCLUDED_eabase_H 42 | #include "EABase/eabase.h" 43 | #endif 44 | 45 | 46 | 47 | /// \brief This result type is width-compatible with most systems 48 | typedef int32_t ea_result_type; 49 | 50 | 51 | namespace EA 52 | { 53 | typedef int32_t result_type; 54 | 55 | enum 56 | { 57 | SUCCESS = 0, 58 | FAILURE = -1 59 | }; 60 | } 61 | 62 | 63 | /// \brief Macro to simplify testing for success 64 | #ifndef EA_SUCCEEDED 65 | #define EA_SUCCEEDED(result) ((result) >= 0) 66 | #endif 67 | 68 | /// \brief Macro to simplfify testing for general failure 69 | #ifndef EA_FAILED 70 | #define EA_FAILED(result) ((result) < 0) 71 | #endif 72 | 73 | 74 | #endif 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/allocator.h 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | #ifndef EASTL_ALLOCATOR_H 38 | #define EASTL_ALLOCATOR_H 39 | 40 | 41 | #include 42 | #include 43 | 44 | 45 | #ifdef _MSC_VER 46 | #pragma warning(push) 47 | #pragma warning(disable: 4189) // local variable is initialized but not referenced 48 | #endif 49 | 50 | 51 | namespace eastl 52 | { 53 | 54 | /// EASTL_ALLOCATOR_DEFAULT_NAME 55 | /// 56 | /// Defines a default allocator name in the absence of a user-provided name. 57 | /// 58 | #ifndef EASTL_ALLOCATOR_DEFAULT_NAME 59 | #define EASTL_ALLOCATOR_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX // Unless the user overrides something, this is "EASTL". 60 | #endif 61 | 62 | 63 | /// alloc_flags 64 | /// 65 | /// Defines allocation flags. 66 | /// 67 | enum alloc_flags 68 | { 69 | MEM_TEMP = 0, // Low memory, not necessarily actually temporary. 70 | MEM_PERM = 1 // High memory, for things that won't be unloaded. 71 | }; 72 | 73 | 74 | /// allocator 75 | /// 76 | /// In this allocator class, note that it is not templated on any type and 77 | /// instead it simply allocates blocks of memory much like the C malloc and 78 | /// free functions. It can be thought of as similar to C++ std::allocator. 79 | /// The flags parameter has meaning that is specific to the allocation 80 | /// 81 | class EASTL_API allocator 82 | { 83 | public: 84 | EASTL_ALLOCATOR_EXPLICIT allocator(const char* pName = EASTL_NAME_VAL(EASTL_ALLOCATOR_DEFAULT_NAME)); 85 | allocator(const allocator& x); 86 | allocator(const allocator& x, const char* pName); 87 | 88 | allocator& operator=(const allocator& x); 89 | 90 | void* allocate(size_t n, int flags = 0); 91 | void* allocate(size_t n, size_t alignment, size_t offset, int flags = 0); 92 | void deallocate(void* p, size_t n); 93 | 94 | const char* get_name() const; 95 | void set_name(const char* pName); 96 | 97 | protected: 98 | #if EASTL_NAME_ENABLED 99 | const char* mpName; // Debug name, used to track memory. 100 | #endif 101 | }; 102 | 103 | bool operator==(const allocator& a, const allocator& b); 104 | bool operator!=(const allocator& a, const allocator& b); 105 | 106 | EASTL_API allocator* GetDefaultAllocator(); 107 | EASTL_API allocator* SetDefaultAllocator(allocator* pAllocator); 108 | 109 | 110 | 111 | /// get_default_allocator 112 | /// 113 | /// This templated function allows the user to implement a default allocator 114 | /// retrieval function that any part of EASTL can use. EASTL containers take 115 | /// an Allocator parameter which identifies an Allocator class to use. But 116 | /// different kinds of allocators have different mechanisms for retrieving 117 | /// a default allocator instance, and some don't even intrinsically support 118 | /// such functionality. The user can override this get_default_allocator 119 | /// function in order to provide the glue between EASTL and whatever their 120 | /// system's default allocator happens to be. 121 | /// 122 | /// Example usage: 123 | /// MyAllocatorType* gpSystemAllocator; 124 | /// 125 | /// MyAllocatorType* get_default_allocator(const MyAllocatorType*) 126 | /// { return gpSystemAllocator; } 127 | /// 128 | template 129 | inline Allocator* get_default_allocator(const Allocator*) 130 | { 131 | return NULL; // By default we return NULL; the user must make specialization of this function in order to provide their own implementation. 132 | } 133 | 134 | inline EASTLAllocatorType* get_default_allocator(const EASTLAllocatorType*) 135 | { 136 | return EASTLAllocatorDefault(); // For the built-in allocator EASTLAllocatorType, we happen to already have a function for returning the default allocator instance, so we provide it. 137 | } 138 | 139 | 140 | /// default_allocfreemethod 141 | /// 142 | /// Implements a default allocfreemethod which uses the default global allocator. 143 | /// This version supports only default alignment. 144 | /// 145 | inline void* default_allocfreemethod(size_t n, void* pBuffer, void* /*pContext*/) 146 | { 147 | EASTLAllocatorType* const pAllocator = EASTLAllocatorDefault(); 148 | 149 | if(pBuffer) // If freeing... 150 | { 151 | EASTLFree(*pAllocator, pBuffer, n); 152 | return NULL; // The return value is meaningless for the free. 153 | } 154 | else // allocating 155 | return EASTLAlloc(*pAllocator, n); 156 | } 157 | 158 | 159 | /// allocate_memory 160 | /// 161 | /// This is a memory allocation dispatching function. 162 | /// To do: Make aligned and unaligned specializations. 163 | /// Note that to do this we will need to use a class with a static 164 | /// function instead of a standalone function like below. 165 | /// 166 | template 167 | void* allocate_memory(Allocator& a, size_t n, size_t alignment, size_t alignmentOffset) 168 | { 169 | if(alignment <= 8) 170 | return EASTLAlloc(a, n); 171 | return EASTLAllocAligned(a, n, alignment, alignmentOffset); 172 | } 173 | 174 | } // namespace eastl 175 | 176 | 177 | 178 | 179 | 180 | #ifndef EASTL_USER_DEFINED_ALLOCATOR // If the user hasn't declared that he has defined a different allocator implementation elsewhere... 181 | 182 | #ifdef _MSC_VER 183 | #pragma warning(push, 0) 184 | #include 185 | #pragma warning(pop) 186 | #else 187 | #include 188 | #endif 189 | 190 | #if !EASTL_DLL // If building a regular library and not building EASTL as a DLL... 191 | // It is expected that the application define the following 192 | // versions of operator new for the application. Either that or the 193 | // user needs to override the implementation of the allocator class. 194 | void* operator new[](size_t size, const char* pName, int flags, unsigned debugFlags, const char* file, int line); 195 | void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line); 196 | #endif 197 | 198 | namespace eastl 199 | { 200 | inline allocator::allocator(const char* EASTL_NAME(pName)) 201 | { 202 | #if EASTL_NAME_ENABLED 203 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 204 | #endif 205 | } 206 | 207 | 208 | inline allocator::allocator(const allocator& EASTL_NAME(alloc)) 209 | { 210 | #if EASTL_NAME_ENABLED 211 | mpName = alloc.mpName; 212 | #endif 213 | } 214 | 215 | 216 | inline allocator::allocator(const allocator&, const char* EASTL_NAME(pName)) 217 | { 218 | #if EASTL_NAME_ENABLED 219 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 220 | #endif 221 | } 222 | 223 | 224 | inline allocator& allocator::operator=(const allocator& EASTL_NAME(alloc)) 225 | { 226 | #if EASTL_NAME_ENABLED 227 | mpName = alloc.mpName; 228 | #endif 229 | return *this; 230 | } 231 | 232 | 233 | inline const char* allocator::get_name() const 234 | { 235 | #if EASTL_NAME_ENABLED 236 | return mpName; 237 | #else 238 | return EASTL_ALLOCATOR_DEFAULT_NAME; 239 | #endif 240 | } 241 | 242 | 243 | inline void allocator::set_name(const char* EASTL_NAME(pName)) 244 | { 245 | #if EASTL_NAME_ENABLED 246 | mpName = pName; 247 | #endif 248 | } 249 | 250 | 251 | inline void* allocator::allocate(size_t n, int flags) 252 | { 253 | #if EASTL_NAME_ENABLED 254 | #define pName mpName 255 | #else 256 | #define pName EASTL_ALLOCATOR_DEFAULT_NAME 257 | #endif 258 | 259 | #if EASTL_DLL 260 | // We currently have no support for implementing flags when 261 | // using the C runtime library operator new function. The user 262 | // can use SetDefaultAllocator to override the default allocator. 263 | (void)flags; 264 | return ::new char[n]; 265 | #elif (EASTL_DEBUGPARAMS_LEVEL <= 0) 266 | return ::new((char*)0, flags, 0, (char*)0, 0) char[n]; 267 | #elif (EASTL_DEBUGPARAMS_LEVEL == 1) 268 | return ::new( pName, flags, 0, (char*)0, 0) char[n]; 269 | #else 270 | return ::new( pName, flags, 0, __FILE__, __LINE__) char[n]; 271 | #endif 272 | } 273 | 274 | 275 | inline void* allocator::allocate(size_t n, size_t alignment, size_t offset, int flags) 276 | { 277 | #if EASTL_DLL 278 | // We have a problem here. We cannot support alignment, as we don't have access 279 | // to a memory allocator that can provide aligned memory. The C++ standard doesn't 280 | // recognize such a thing. The user will need to call SetDefaultAllocator to 281 | // provide an alloator which supports alignment. 282 | EASTL_ASSERT(alignment <= 8); // 8 (sizeof(double)) is the standard alignment returned by operator new. 283 | (void)alignment; (void)offset; (void)flags; 284 | return new char[n]; 285 | #elif (EASTL_DEBUGPARAMS_LEVEL <= 0) 286 | return ::new(alignment, offset, (char*)0, flags, 0, (char*)0, 0) char[n]; 287 | #elif (EASTL_DEBUGPARAMS_LEVEL == 1) 288 | return ::new(alignment, offset, pName, flags, 0, (char*)0, 0) char[n]; 289 | #else 290 | return ::new(alignment, offset, pName, flags, 0, __FILE__, __LINE__) char[n]; 291 | #endif 292 | 293 | #undef pName // See above for the definition of this. 294 | } 295 | 296 | 297 | inline void allocator::deallocate(void* p, size_t) 298 | { 299 | delete[] (char*)p; 300 | } 301 | 302 | 303 | inline bool operator==(const allocator&, const allocator&) 304 | { 305 | return true; // All allocators are considered equal, as they merely use global new/delete. 306 | } 307 | 308 | 309 | inline bool operator!=(const allocator&, const allocator&) 310 | { 311 | return false; // All allocators are considered equal, as they merely use global new/delete. 312 | } 313 | 314 | 315 | } // namespace eastl 316 | 317 | 318 | #endif // EASTL_USER_DEFINED_ALLOCATOR 319 | 320 | 321 | #ifdef _MSC_VER 322 | #pragma warning(pop) 323 | #endif 324 | 325 | 326 | #endif // Header include guard 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/core_allocator_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // core_allocator_adapter.h 31 | // 32 | // Copyright (c) 2007, Electronic Arts. All rights reserved. 33 | // Maintained by Paul Pedriana 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | // Implements an EASTL allocator that uses an ICoreAllocator. 38 | // However, this header file is not dependent on ICoreAllocator or its package. 39 | /////////////////////////////////////////////////////////////////////////////// 40 | 41 | 42 | #ifndef EASTL_CORE_ALLOCATOR_ADAPTER_H 43 | #define EASTL_CORE_ALLOCATOR_ADAPTER_H 44 | 45 | 46 | #include 47 | 48 | 49 | namespace EA 50 | { 51 | namespace Allocator 52 | { 53 | /// CoreAllocatorAdapter 54 | /// 55 | /// Implements the EASTL allocator interface. 56 | /// Allocates memory from an instance of ICoreAllocator. 57 | /// 58 | /// Example usage: 59 | /// eastl::list > widgetList("UI/WidgetList", pSomeCoreAllocator); 60 | /// widgetList.push_back(Widget()); 61 | /// 62 | /// Example usage: 63 | /// // Note that the CoreAllocator is declared before and thus destroyed after the widget list. 64 | /// typedef CoreAllocatorAdapter EASTLCoreAllocator; 65 | /// typedef eastl::list WidgetList; 66 | /// CoreAllocatorFixed widgetCoreAllocator(pFixedAllocatorForWidgetListValueType); 67 | /// WidgetList widgetList(EASTLCoreAllocator("UI/WidgetList", &widgetCoreAllocator)); 68 | /// 69 | template 70 | class CoreAllocatorAdapter 71 | { 72 | public: 73 | typedef CoreAllocatorAdapter this_type; 74 | 75 | public: 76 | CoreAllocatorAdapter(const char* pName = EASTL_NAME_VAL(EASTL_ALLOCATOR_DEFAULT_NAME)); 77 | CoreAllocatorAdapter(const char* pName, AllocatorType* pAllocator); 78 | CoreAllocatorAdapter(const char* pName, AllocatorType* pAllocator, int flags); 79 | CoreAllocatorAdapter(const CoreAllocatorAdapter& x); 80 | CoreAllocatorAdapter(const CoreAllocatorAdapter& x, const char* pName); 81 | 82 | CoreAllocatorAdapter& operator=(const CoreAllocatorAdapter& x); 83 | 84 | void* allocate(size_t n, int flags = 0); 85 | void* allocate(size_t n, size_t alignment, size_t offset, int flags = 0); 86 | void deallocate(void* p, size_t n); 87 | 88 | AllocatorType* get_allocator() const; 89 | void set_allocator(AllocatorType* pAllocator); 90 | 91 | int get_flags() const; 92 | void set_flags(int flags); 93 | 94 | const char* get_name() const; 95 | void set_name(const char* pName); 96 | 97 | public: // Public because otherwise VC++ generates (possibly invalid) warnings about inline friend template specializations. 98 | AllocatorType* mpCoreAllocator; 99 | int mnFlags; // Allocation flags. See ICoreAllocator/AllocFlags. 100 | 101 | #if EASTL_NAME_ENABLED 102 | const char* mpName; // Debug name, used to track memory. 103 | #endif 104 | }; 105 | 106 | template 107 | bool operator==(const CoreAllocatorAdapter& a, const CoreAllocatorAdapter& b); 108 | 109 | template 110 | bool operator!=(const CoreAllocatorAdapter& a, const CoreAllocatorAdapter& b); 111 | 112 | 113 | 114 | /// EASTLICoreAllocator 115 | /// 116 | /// Provides a standardized typedef for ICoreAllocator; 117 | /// 118 | /// Example usage: 119 | /// eastl::list widgetList("UI/WidgetList", pSomeCoreAllocator); 120 | /// widgetList.push_back(Widget()); 121 | /// 122 | class ICoreAllocator; 123 | typedef CoreAllocatorAdapter EASTLICoreAllocator; 124 | 125 | 126 | } // namespace Allocator 127 | 128 | } // namespace EA 129 | 130 | 131 | 132 | 133 | 134 | /////////////////////////////////////////////////////////////////////////////// 135 | // Inlines 136 | /////////////////////////////////////////////////////////////////////////////// 137 | 138 | namespace EA 139 | { 140 | namespace Allocator 141 | { 142 | 143 | template 144 | inline CoreAllocatorAdapter::CoreAllocatorAdapter(const char* EASTL_NAME(pName)) 145 | : mpCoreAllocator(AllocatorType::GetDefaultAllocator()), mnFlags(0) 146 | { 147 | #if EASTL_NAME_ENABLED 148 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 149 | #endif 150 | } 151 | 152 | template 153 | inline CoreAllocatorAdapter::CoreAllocatorAdapter(const char* EASTL_NAME(pName), AllocatorType* pCoreAllocator) 154 | : mpCoreAllocator(pCoreAllocator), mnFlags(0) 155 | { 156 | #if EASTL_NAME_ENABLED 157 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 158 | #endif 159 | } 160 | 161 | template 162 | inline CoreAllocatorAdapter::CoreAllocatorAdapter(const char* EASTL_NAME(pName), AllocatorType* pCoreAllocator, int flags) 163 | : mpCoreAllocator(pCoreAllocator), mnFlags(flags) 164 | { 165 | #if EASTL_NAME_ENABLED 166 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 167 | #endif 168 | } 169 | 170 | template 171 | inline CoreAllocatorAdapter::CoreAllocatorAdapter(const CoreAllocatorAdapter& x) 172 | : mpCoreAllocator(x.mpCoreAllocator), mnFlags(x.mnFlags) 173 | { 174 | #if EASTL_NAME_ENABLED 175 | mpName = x.mpName; 176 | #endif 177 | } 178 | 179 | template 180 | inline CoreAllocatorAdapter::CoreAllocatorAdapter(const CoreAllocatorAdapter& x, const char* EASTL_NAME(pName)) 181 | : mpCoreAllocator(x.mpCoreAllocator), mnFlags(x.mnFlags) 182 | { 183 | #if EASTL_NAME_ENABLED 184 | mpName = pName ? pName : EASTL_ALLOCATOR_DEFAULT_NAME; 185 | #endif 186 | } 187 | 188 | template 189 | inline CoreAllocatorAdapter& CoreAllocatorAdapter::operator=(const CoreAllocatorAdapter& x) 190 | { 191 | // In order to be consistent with EASTL's allocator implementation, 192 | // we don't copy the name from the source object. 193 | mpCoreAllocator = x.mpCoreAllocator; 194 | mnFlags = x.mnFlags; 195 | return *this; 196 | } 197 | 198 | template 199 | inline void* CoreAllocatorAdapter::allocate(size_t n, int /*flags*/) 200 | { 201 | // It turns out that EASTL itself doesn't use the flags parameter, 202 | // whereas the user here might well want to specify a flags 203 | // parameter. So we use ours instead of the one passed in. 204 | return mpCoreAllocator->Alloc(n, EASTL_NAME_VAL(mpName), (unsigned)mnFlags); 205 | } 206 | 207 | template 208 | inline void* CoreAllocatorAdapter::allocate(size_t n, size_t alignment, size_t offset, int /*flags*/) 209 | { 210 | // It turns out that EASTL itself doesn't use the flags parameter, 211 | // whereas the user here might well want to specify a flags 212 | // parameter. So we use ours instead of the one passed in. 213 | return mpCoreAllocator->Alloc(n, EASTL_NAME_VAL(mpName), (unsigned)mnFlags, (unsigned)alignment, (unsigned)offset); 214 | } 215 | 216 | template 217 | inline void CoreAllocatorAdapter::deallocate(void* p, size_t n) 218 | { 219 | return mpCoreAllocator->Free(p, n); 220 | } 221 | 222 | template 223 | inline AllocatorType* CoreAllocatorAdapter::get_allocator() const 224 | { 225 | return mpCoreAllocator; 226 | } 227 | 228 | template 229 | inline void CoreAllocatorAdapter::set_allocator(AllocatorType* pAllocator) 230 | { 231 | mpCoreAllocator = pAllocator; 232 | } 233 | 234 | template 235 | inline int CoreAllocatorAdapter::get_flags() const 236 | { 237 | return mnFlags; 238 | } 239 | 240 | template 241 | inline void CoreAllocatorAdapter::set_flags(int flags) 242 | { 243 | mnFlags = flags; 244 | } 245 | 246 | template 247 | inline const char* CoreAllocatorAdapter::get_name() const 248 | { 249 | #if EASTL_NAME_ENABLED 250 | return mpName; 251 | #else 252 | return EASTL_ALLOCATOR_DEFAULT_NAME; 253 | #endif 254 | } 255 | 256 | template 257 | inline void CoreAllocatorAdapter::set_name(const char* pName) 258 | { 259 | #if EASTL_NAME_ENABLED 260 | mpName = pName; 261 | #else 262 | (void)pName; 263 | #endif 264 | } 265 | 266 | 267 | 268 | template 269 | inline bool operator==(const CoreAllocatorAdapter& a, const CoreAllocatorAdapter& b) 270 | { 271 | return (a.mpCoreAllocator == b.mpCoreAllocator) && 272 | (a.mnFlags == b.mnFlags); 273 | } 274 | 275 | template 276 | inline bool operator!=(const CoreAllocatorAdapter& a, const CoreAllocatorAdapter& b) 277 | { 278 | return (a.mpCoreAllocator != b.mpCoreAllocator) || 279 | (a.mnFlags != b.mnFlags); 280 | } 281 | 282 | 283 | } // namespace Allocator 284 | 285 | } // namespace EA 286 | 287 | 288 | #endif // Header include guard 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/fixed_substring.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/fixed_substring.h 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | #ifndef EASTL_FIXED_SUBSTRING_H 38 | #define EASTL_FIXED_SUBSTRING_H 39 | 40 | 41 | #include 42 | 43 | 44 | namespace eastl 45 | { 46 | 47 | /// fixed_substring 48 | /// 49 | /// Implements a string which is a reference to a segment of characters. 50 | /// This class is efficient because it allocates no memory and copies no 51 | /// memory during construction and assignment, but rather refers directly 52 | /// to the segment of chracters. A common use of this is to have a 53 | /// fixed_substring efficiently refer to a substring within another string. 54 | /// 55 | /// You cannot directly resize a fixed_substring (e.g. via resize, insert, 56 | /// append, erase), but you can assign a different substring to it. 57 | /// You can modify the characters within a substring in place. 58 | /// As of this writing, in the name of being lean and simple it is the 59 | /// user's responsibility to not call unsupported resizing functions 60 | /// such as those listed above. A detailed listing of the functions which 61 | /// are not supported is given below in the class declaration. 62 | /// 63 | /// The c_str function doesn't act as one might hope, as it simply 64 | /// returns the pointer to the beginning of the string segment and the 65 | /// 0-terminator may be beyond the end of the segment. If you want to 66 | /// always be able to use c_str as expected, use the fixed string solution 67 | /// we describe below. 68 | /// 69 | /// Another use of fixed_substring is to provide C++ string-like functionality 70 | /// with a C character array. This allows you to work on a C character array 71 | /// as if it were a C++ string as opposed using the C string API. Thus you 72 | /// can do this: 73 | /// 74 | /// void DoSomethingForUser(char* timeStr, size_t timeStrCapacity) 75 | /// { 76 | /// fixed_substring tmp(timeStr, timeStrCapacity); 77 | /// tmp = "hello "; 78 | /// tmp += "world"; 79 | /// } 80 | /// 81 | /// Note that this class constructs and assigns from const string pointers 82 | /// and const string objects, yet this class does not declare its member 83 | /// data as const. This is a concession in order to allow this implementation 84 | /// to be simple and lean. It is the user's responsibility to make sure 85 | /// that strings that should not or can not be modified are either not 86 | /// used by fixed_substring or are not modified by fixed_substring. 87 | /// 88 | /// A more flexible alternative to fixed_substring is fixed_string. 89 | /// fixed_string has none of the functional limitations that fixed_substring 90 | /// has and like fixed_substring it doesn't allocate memory. However, 91 | /// fixed_string makes a *copy* of the source string and uses local 92 | /// memory to store that copy. Also, fixed_string objects on the stack 93 | /// are going to have a limit as to their maximum size. 94 | /// 95 | /// Notes: 96 | /// As of this writing, the string class necessarily reallocates when 97 | /// an insert of self is done into self. As a result, the fixed_substring 98 | /// class doesn't support inserting self into self. 99 | /// 100 | /// Example usage: 101 | /// basic_string str("hello world"); 102 | /// fixed_substring sub(str, 2, 5); // sub == "llo w" 103 | /// 104 | template 105 | class fixed_substring : public basic_string 106 | { 107 | public: 108 | typedef basic_string base_type; 109 | typedef fixed_substring this_type; 110 | typedef typename base_type::size_type size_type; 111 | typedef typename base_type::value_type value_type; 112 | 113 | using base_type::npos; 114 | using base_type::mpBegin; 115 | using base_type::mpEnd; 116 | using base_type::mpCapacity; 117 | using base_type::reset; 118 | using base_type::mAllocator; 119 | 120 | public: 121 | fixed_substring() 122 | : base_type() 123 | { 124 | } 125 | 126 | fixed_substring(const base_type& x) 127 | : base_type() 128 | { 129 | #if EASTL_NAME_ENABLED 130 | mAllocator.set_name(x.get_allocator().get_name()); 131 | #endif 132 | 133 | assign(x); 134 | } 135 | 136 | fixed_substring(const base_type& x, size_type position, size_type n = base_type::npos) 137 | : base_type() 138 | { 139 | #if EASTL_NAME_ENABLED 140 | mAllocator.set_name(x.get_allocator().get_name()); 141 | #endif 142 | 143 | assign(x, position, n); 144 | } 145 | 146 | fixed_substring(const value_type* p, size_type n) 147 | : base_type() 148 | { 149 | assign(p, n); 150 | } 151 | 152 | fixed_substring(const value_type* p) 153 | : base_type() 154 | { 155 | assign(p); 156 | } 157 | 158 | fixed_substring(const value_type* pBegin, const value_type* pEnd) 159 | : base_type() 160 | { 161 | assign(pBegin, pEnd); 162 | } 163 | 164 | ~fixed_substring() 165 | { 166 | // We need to reset, as otherwise the parent destructor will 167 | // attempt to free our memory. 168 | reset(); 169 | } 170 | 171 | this_type& operator=(const base_type& x) 172 | { 173 | assign(x); 174 | return *this; 175 | } 176 | 177 | this_type& operator=(const value_type* p) 178 | { 179 | assign(p); 180 | return *this; 181 | } 182 | 183 | this_type& assign(const base_type& x) 184 | { 185 | // By design, we need to cast away const-ness here. 186 | mpBegin = const_cast(x.data()); 187 | mpEnd = mpBegin + x.size(); 188 | mpCapacity = mpEnd; 189 | return *this; 190 | } 191 | 192 | this_type& assign(const base_type& x, size_type position, size_type n) 193 | { 194 | // By design, we need to cast away const-ness here. 195 | mpBegin = const_cast(x.data()) + position; 196 | mpEnd = mpBegin + n; 197 | mpCapacity = mpEnd; 198 | return *this; 199 | } 200 | 201 | this_type& assign(const value_type* p, size_type n) 202 | { 203 | // By design, we need to cast away const-ness here. 204 | mpBegin = const_cast(p); 205 | mpEnd = mpBegin + n; 206 | mpCapacity = mpEnd; 207 | return *this; 208 | } 209 | 210 | this_type& assign(const value_type* p) 211 | { 212 | // By design, we need to cast away const-ness here. 213 | mpBegin = const_cast(p); 214 | mpEnd = mpBegin + CharStrlen(p); 215 | mpCapacity = mpEnd; 216 | return *this; 217 | } 218 | 219 | this_type& assign(const value_type* pBegin, const value_type* pEnd) 220 | { 221 | // By design, we need to cast away const-ness here. 222 | mpBegin = const_cast(pBegin); 223 | mpEnd = const_cast(pEnd); 224 | mpCapacity = mpEnd; 225 | return *this; 226 | } 227 | 228 | 229 | // Partially supported functionality 230 | // 231 | // When using fixed_substring on a character sequence that is within another 232 | // string, the following functions may do one of two things: 233 | // 1 Attempt to reallocate 234 | // 2 Write a 0 char at the end of the fixed_substring 235 | // 236 | // Item #1 will result in a crash, due to the attempt by the underlying 237 | // string class to free the substring memory. Item #2 will result in a 0 238 | // char being written to the character array. Item #2 may or may not be 239 | // a problem, depending on how you use fixed_substring. Thus the following 240 | // functions should be used carefully. 241 | // 242 | // basic_string& operator=(const basic_string& x); 243 | // basic_string& operator=(value_type c); 244 | // void resize(size_type n, value_type c); 245 | // void resize(size_type n); 246 | // void reserve(size_type = 0); 247 | // void set_capacity(size_type n); 248 | // void clear(); 249 | // basic_string& operator+=(const basic_string& x); 250 | // basic_string& operator+=(const value_type* p); 251 | // basic_string& operator+=(value_type c); 252 | // basic_string& append(const basic_string& x); 253 | // basic_string& append(const basic_string& x, size_type position, size_type n); 254 | // basic_string& append(const value_type* p, size_type n); 255 | // basic_string& append(const value_type* p); 256 | // basic_string& append(size_type n); 257 | // basic_string& append(size_type n, value_type c); 258 | // basic_string& append(const value_type* pBegin, const value_type* pEnd); 259 | // basic_string& append_sprintf_va_list(const value_type* pFormat, va_list arguments); 260 | // basic_string& append_sprintf(const value_type* pFormat, ...); 261 | // void push_back(value_type c); 262 | // void pop_back(); 263 | // basic_string& assign(const value_type* p, size_type n); 264 | // basic_string& assign(size_type n, value_type c); 265 | // basic_string& insert(size_type position, const basic_string& x); 266 | // basic_string& insert(size_type position, const basic_string& x, size_type beg, size_type n); 267 | // basic_string& insert(size_type position, const value_type* p, size_type n); 268 | // basic_string& insert(size_type position, const value_type* p); 269 | // basic_string& insert(size_type position, size_type n, value_type c); 270 | // iterator insert(iterator p, value_type c); 271 | // void insert(iterator p, size_type n, value_type c); 272 | // void insert(iterator p, const value_type* pBegin, const value_type* pEnd); 273 | // basic_string& erase(size_type position = 0, size_type n = npos); 274 | // iterator erase(iterator p); 275 | // iterator erase(iterator pBegin, iterator pEnd); 276 | // void swap(basic_string& x); 277 | // basic_string& sprintf_va_list(const value_type* pFormat, va_list arguments); 278 | // basic_string& sprintf(const value_type* pFormat, ...); 279 | 280 | 281 | }; // fixed_substring 282 | 283 | 284 | } // namespace eastl 285 | 286 | 287 | 288 | #endif // Header include guard 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/hash_set.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/hash_set.h 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | // This file is based on the TR1 (technical report 1) reference implementation 38 | // of the unordered_set/unordered_map C++ classes as of about 4/2005. Most likely 39 | // many or all C++ library vendors' implementations of this classes will be 40 | // based off of the reference version and so will look pretty similar to this 41 | // file as well as other vendors' versions. 42 | /////////////////////////////////////////////////////////////////////////////// 43 | 44 | 45 | #ifndef EASTL_HASH_SET_H 46 | #define EASTL_HASH_SET_H 47 | 48 | 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | 55 | 56 | namespace eastl 57 | { 58 | 59 | /// EASTL_HASH_SET_DEFAULT_NAME 60 | /// 61 | /// Defines a default container name in the absence of a user-provided name. 62 | /// 63 | #ifndef EASTL_HASH_SET_DEFAULT_NAME 64 | #define EASTL_HASH_SET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " hash_set" // Unless the user overrides something, this is "EASTL hash_set". 65 | #endif 66 | 67 | 68 | /// EASTL_HASH_MULTISET_DEFAULT_NAME 69 | /// 70 | /// Defines a default container name in the absence of a user-provided name. 71 | /// 72 | #ifndef EASTL_HASH_MULTISET_DEFAULT_NAME 73 | #define EASTL_HASH_MULTISET_DEFAULT_NAME EASTL_DEFAULT_NAME_PREFIX " hash_multiset" // Unless the user overrides something, this is "EASTL hash_multiset". 74 | #endif 75 | 76 | 77 | /// EASTL_HASH_SET_DEFAULT_ALLOCATOR 78 | /// 79 | #ifndef EASTL_HASH_SET_DEFAULT_ALLOCATOR 80 | #define EASTL_HASH_SET_DEFAULT_ALLOCATOR allocator_type(EASTL_HASH_SET_DEFAULT_NAME) 81 | #endif 82 | 83 | /// EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR 84 | /// 85 | #ifndef EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR 86 | #define EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR allocator_type(EASTL_HASH_MULTISET_DEFAULT_NAME) 87 | #endif 88 | 89 | 90 | 91 | /// hash_set 92 | /// 93 | /// Implements a hash_set, which is a hashed unique-item container. 94 | /// Lookups are O(1) (that is, they are fast) but the container is 95 | /// not sorted. 96 | /// 97 | /// set_max_load_factor 98 | /// If you want to make a hashtable never increase its bucket usage, 99 | /// call set_max_load_factor with a very high value such as 100000.f. 100 | /// 101 | /// bCacheHashCode 102 | /// We provide the boolean bCacheHashCode template parameter in order 103 | /// to allow the storing of the hash code of the key within the map. 104 | /// When this option is disabled, the rehashing of the table will 105 | /// call the hash function on the key. Setting bCacheHashCode to true 106 | /// is useful for cases whereby the calculation of the hash value for 107 | /// a contained object is very expensive. 108 | /// 109 | /// find_as 110 | /// In order to support the ability to have a hashtable of strings but 111 | /// be able to do efficiently lookups via char pointers (i.e. so they 112 | /// aren't converted to string objects), we provide the find_as 113 | /// function. This function allows you to do a find with a key of a 114 | /// type other than the hashtable key type. 115 | /// 116 | /// Example find_as usage: 117 | /// hash_set hashSet; 118 | /// i = hashSet.find_as("hello"); // Use default hash and compare. 119 | /// 120 | /// Example find_as usage (namespaces omitted for brevity): 121 | /// hash_set hashSet; 122 | /// i = hashSet.find_as("hello", hash(), equal_to_2()); 123 | /// 124 | template , typename Predicate = eastl::equal_to, 125 | typename Allocator = EASTLAllocatorType, bool bCacheHashCode = false> 126 | class hash_set 127 | : public hashtable, Predicate, 128 | Hash, mod_range_hashing, default_ranged_hash, 129 | prime_rehash_policy, bCacheHashCode, false, true> 130 | { 131 | public: 132 | typedef hashtable, Predicate, 133 | Hash, mod_range_hashing, default_ranged_hash, 134 | prime_rehash_policy, bCacheHashCode, false, true> base_type; 135 | typedef hash_set this_type; 136 | typedef typename base_type::size_type size_type; 137 | typedef typename base_type::value_type value_type; 138 | typedef typename base_type::allocator_type allocator_type; 139 | typedef typename base_type::node_type node_type; 140 | 141 | public: 142 | /// hash_set 143 | /// 144 | /// Default constructor. 145 | /// 146 | explicit hash_set(const allocator_type& allocator = EASTL_HASH_SET_DEFAULT_ALLOCATOR) 147 | : base_type(0, Hash(), mod_range_hashing(), default_ranged_hash(), Predicate(), eastl::use_self(), allocator) 148 | { 149 | // Empty 150 | } 151 | 152 | 153 | /// hash_set 154 | /// 155 | /// Constructor which creates an empty container, but start with nBucketCount buckets. 156 | /// We default to a small nBucketCount value, though the user really should manually 157 | /// specify an appropriate value in order to prevent memory from being reallocated. 158 | /// 159 | explicit hash_set(size_type nBucketCount, const Hash& hashFunction = Hash(), const Predicate& predicate = Predicate(), 160 | const allocator_type& allocator = EASTL_HASH_SET_DEFAULT_ALLOCATOR) 161 | : base_type(nBucketCount, hashFunction, mod_range_hashing(), default_ranged_hash(), predicate, eastl::use_self(), allocator) 162 | { 163 | // Empty 164 | } 165 | 166 | 167 | /// hash_set 168 | /// 169 | /// An input bucket count of <= 1 causes the bucket count to be equal to the number of 170 | /// elements in the input range. 171 | /// 172 | template 173 | hash_set(FowardIterator first, FowardIterator last, size_type nBucketCount = 0, const Hash& hashFunction = Hash(), 174 | const Predicate& predicate = Predicate(), const allocator_type& allocator = EASTL_HASH_SET_DEFAULT_ALLOCATOR) 175 | : base_type(first, last, nBucketCount, hashFunction, mod_range_hashing(), default_ranged_hash(), predicate, eastl::use_self(), allocator) 176 | { 177 | // Empty 178 | } 179 | 180 | }; // hash_set 181 | 182 | 183 | 184 | 185 | 186 | 187 | /// hash_multiset 188 | /// 189 | /// Implements a hash_multiset, which is the same thing as a hash_set 190 | /// except that contained elements need not be unique. See the documentation 191 | /// for hash_set for details. 192 | /// 193 | template , typename Predicate = eastl::equal_to, 194 | typename Allocator = EASTLAllocatorType, bool bCacheHashCode = false> 195 | class hash_multiset 196 | : public hashtable, Predicate, 197 | Hash, mod_range_hashing, default_ranged_hash, 198 | prime_rehash_policy, bCacheHashCode, false, false> 199 | { 200 | public: 201 | typedef hashtable, Predicate, 202 | Hash, mod_range_hashing, default_ranged_hash, 203 | prime_rehash_policy, bCacheHashCode, false, false> base_type; 204 | typedef hash_multiset this_type; 205 | typedef typename base_type::size_type size_type; 206 | typedef typename base_type::value_type value_type; 207 | typedef typename base_type::allocator_type allocator_type; 208 | typedef typename base_type::node_type node_type; 209 | 210 | public: 211 | /// hash_multiset 212 | /// 213 | /// Default constructor. 214 | /// 215 | explicit hash_multiset(const allocator_type& allocator = EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR) 216 | : base_type(0, Hash(), mod_range_hashing(), default_ranged_hash(), Predicate(), eastl::use_self(), allocator) 217 | { 218 | // Empty 219 | } 220 | 221 | 222 | /// hash_multiset 223 | /// 224 | /// Constructor which creates an empty container, but start with nBucketCount buckets. 225 | /// We default to a small nBucketCount value, though the user really should manually 226 | /// specify an appropriate value in order to prevent memory from being reallocated. 227 | /// 228 | explicit hash_multiset(size_type nBucketCount, const Hash& hashFunction = Hash(), 229 | const Predicate& predicate = Predicate(), const allocator_type& allocator = EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR) 230 | : base_type(nBucketCount, hashFunction, mod_range_hashing(), default_ranged_hash(), predicate, eastl::use_self(), allocator) 231 | { 232 | // Empty 233 | } 234 | 235 | 236 | /// hash_multiset 237 | /// 238 | /// An input bucket count of <= 1 causes the bucket count to be equal to the number of 239 | /// elements in the input range. 240 | /// 241 | template 242 | hash_multiset(FowardIterator first, FowardIterator last, size_type nBucketCount = 0, const Hash& hashFunction = Hash(), 243 | const Predicate& predicate = Predicate(), const allocator_type& allocator = EASTL_HASH_MULTISET_DEFAULT_ALLOCATOR) 244 | : base_type(first, last, nBucketCount, hashFunction, mod_range_hashing(), default_ranged_hash(), predicate, eastl::use_self(), allocator) 245 | { 246 | // Empty 247 | } 248 | 249 | 250 | }; // hash_multiset 251 | 252 | 253 | 254 | 255 | } // namespace eastl 256 | 257 | 258 | #endif // Header include guard 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/internal/eastl_rw.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // To use this file, you can either copy and paste its contents right below 31 | // the EASTL_USER_CONFIG_HEADER section of EASTL's config.h or you can leave 32 | // config.h unmodified and instead #define EASTL_USER_CONFIG_HEADER be 33 | // config_rw.h and config.h will #include this file automatically. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | #ifndef EASTL_RW_H 38 | #define EASTL_RW_H 39 | 40 | // Unused 41 | 42 | #endif // Header include guard 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/internal/generic_iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/internal/generic_iterator.h 31 | // 32 | // Written and maintained by Paul Pedriana - 2005. 33 | /////////////////////////////////////////////////////////////////////////////// 34 | 35 | /////////////////////////////////////////////////////////////////////////////// 36 | // Implements a generic iterator from a given iteratable type, such as a pointer. 37 | // We cannot put this file into our own iterator.h file because we need to 38 | // still be able to use this file when we have our iterator.h disabled. 39 | // 40 | /////////////////////////////////////////////////////////////////////////////// 41 | 42 | 43 | #ifndef EASTL_INTERNAL_GENERIC_ITERATOR_H 44 | #define EASTL_INTERNAL_GENERIC_ITERATOR_H 45 | 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | 52 | #ifdef _MSC_VER 53 | #pragma warning(push) // VC++ generates a bogus warning that you cannot code away. 54 | #pragma warning(disable: 4619) // There is no warning number 'number'. 55 | #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction. 56 | #endif 57 | 58 | 59 | namespace eastl 60 | { 61 | 62 | /// generic_iterator 63 | /// 64 | /// Converts something which can be iterated into a formal iterator. 65 | /// While this class' primary purpose is to allow the conversion of 66 | /// a pointer to an iterator, you can convert anything else to an 67 | /// iterator by defining an iterator_traits<> specialization for that 68 | /// object type. See EASTL iterator.h for this. 69 | /// 70 | /// Example usage: 71 | /// typedef generic_iterator IntArrayIterator; 72 | /// typedef generic_iterator IntArrayIteratorOther; 73 | /// 74 | template 75 | class generic_iterator 76 | { 77 | protected: 78 | Iterator mIterator; 79 | 80 | public: 81 | typedef typename eastl::iterator_traits::iterator_category iterator_category; 82 | typedef typename eastl::iterator_traits::value_type value_type; 83 | typedef typename eastl::iterator_traits::difference_type difference_type; 84 | typedef typename eastl::iterator_traits::reference reference; 85 | typedef typename eastl::iterator_traits::pointer pointer; 86 | typedef Iterator iterator_type; 87 | typedef Container container_type; 88 | typedef generic_iterator this_type; 89 | 90 | generic_iterator() 91 | : mIterator(iterator_type()) { } 92 | 93 | explicit generic_iterator(const iterator_type& x) 94 | : mIterator(x) { } 95 | 96 | this_type& operator=(const iterator_type& x) 97 | { mIterator = x; return *this; } 98 | 99 | template 100 | generic_iterator(const generic_iterator& x) 101 | : mIterator(x.base()) { } 102 | 103 | reference operator*() const 104 | { return *mIterator; } 105 | 106 | pointer operator->() const 107 | { return mIterator; } 108 | 109 | this_type& operator++() 110 | { ++mIterator; return *this; } 111 | 112 | this_type operator++(int) 113 | { return this_type(mIterator++); } 114 | 115 | this_type& operator--() 116 | { --mIterator; return *this; } 117 | 118 | this_type operator--(int) 119 | { return this_type(mIterator--); } 120 | 121 | reference operator[](const difference_type& n) const 122 | { return mIterator[n]; } 123 | 124 | this_type& operator+=(const difference_type& n) 125 | { mIterator += n; return *this; } 126 | 127 | this_type operator+(const difference_type& n) const 128 | { return this_type(mIterator + n); } 129 | 130 | this_type& operator-=(const difference_type& n) 131 | { mIterator -= n; return *this; } 132 | 133 | this_type operator-(const difference_type& n) const 134 | { return this_type(mIterator - n); } 135 | 136 | const iterator_type& base() const 137 | { return mIterator; } 138 | 139 | }; // class generic_iterator 140 | 141 | 142 | 143 | 144 | 145 | template 146 | inline bool operator==(const generic_iterator& lhs, const generic_iterator& rhs) 147 | { return lhs.base() == rhs.base(); } 148 | 149 | template 150 | inline bool operator==(const generic_iterator& lhs, const generic_iterator& rhs) 151 | { return lhs.base() == rhs.base(); } 152 | 153 | template 154 | inline bool operator!=(const generic_iterator& lhs, const generic_iterator& rhs) 155 | { return lhs.base() != rhs.base(); } 156 | 157 | template 158 | inline bool operator!=(const generic_iterator& lhs, const generic_iterator& rhs) 159 | { return lhs.base() != rhs.base(); } 160 | 161 | template 162 | inline bool operator<(const generic_iterator& lhs, const generic_iterator& rhs) 163 | { return lhs.base() < rhs.base(); } 164 | 165 | template 166 | inline bool operator<(const generic_iterator& lhs, const generic_iterator& rhs) 167 | { return lhs.base() < rhs.base(); } 168 | 169 | template 170 | inline bool operator>(const generic_iterator& lhs, const generic_iterator& rhs) 171 | { return lhs.base() > rhs.base(); } 172 | 173 | template 174 | inline bool operator>(const generic_iterator& lhs, const generic_iterator& rhs) 175 | { return lhs.base() > rhs.base(); } 176 | 177 | template 178 | inline bool operator<=(const generic_iterator& lhs, const generic_iterator& rhs) 179 | { return lhs.base() <= rhs.base(); } 180 | 181 | template 182 | inline bool operator<=(const generic_iterator& lhs, const generic_iterator& rhs) 183 | { return lhs.base() <= rhs.base(); } 184 | 185 | template 186 | inline bool operator>=(const generic_iterator& lhs, const generic_iterator& rhs) 187 | { return lhs.base() >= rhs.base(); } 188 | 189 | template 190 | inline bool operator>=(const generic_iterator& lhs, const generic_iterator& rhs) 191 | { return lhs.base() >= rhs.base(); } 192 | 193 | template 194 | inline typename generic_iterator::difference_type 195 | operator-(const generic_iterator& lhs, const generic_iterator& rhs) 196 | { return lhs.base() - rhs.base(); } 197 | 198 | template 199 | inline generic_iterator 200 | operator+(typename generic_iterator::difference_type n, const generic_iterator& x) 201 | { return generic_iterator(x.base() + n); } 202 | 203 | 204 | 205 | /// is_generic_iterator 206 | /// 207 | /// Tells if an iterator is one of these generic_iterators. This is useful if you want to 208 | /// write code that uses miscellaneous iterators but wants to tell if they are generic_iterators. 209 | /// A primary reason to do so is that you can get at the pointer within the generic_iterator. 210 | /// 211 | template 212 | struct is_generic_iterator : public false_type { }; 213 | 214 | template 215 | struct is_generic_iterator > : public true_type { }; 216 | 217 | 218 | } // namespace eastl 219 | 220 | 221 | #ifdef _MSC_VER 222 | #pragma warning(pop) 223 | #endif 224 | 225 | 226 | #endif // Header include guard 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/internal/type_fundamental.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/internal/type_fundamental.h 31 | // 32 | // Written and maintained by Paul Pedriana - 2005. 33 | /////////////////////////////////////////////////////////////////////////////// 34 | 35 | 36 | #ifndef EASTL_INTERNAL_TYPE_FUNDAMENTAL_H 37 | #define EASTL_INTERNAL_TYPE_FUNDAMENTAL_H 38 | 39 | 40 | namespace eastl 41 | { 42 | 43 | // The following properties or relations are defined here. If the given 44 | // item is missing then it simply hasn't been implemented, at least not yet. 45 | 46 | 47 | /////////////////////////////////////////////////////////////////////// 48 | // is_void 49 | // 50 | // is_void::value == true if and only if T is one of the following types: 51 | // [const][volatile] void 52 | // 53 | /////////////////////////////////////////////////////////////////////// 54 | template struct is_void : public false_type{}; 55 | 56 | template <> struct is_void : public true_type{}; 57 | template <> struct is_void : public true_type{}; 58 | template <> struct is_void : public true_type{}; 59 | template <> struct is_void : public true_type{}; 60 | 61 | 62 | /////////////////////////////////////////////////////////////////////// 63 | // is_integral 64 | // 65 | // is_integral::value == true if and only if T is one of the following types: 66 | // [const] [volatile] bool 67 | // [const] [volatile] char 68 | // [const] [volatile] signed char 69 | // [const] [volatile] unsigned char 70 | // [const] [volatile] wchar_t 71 | // [const] [volatile] short 72 | // [const] [volatile] int 73 | // [const] [volatile] long 74 | // [const] [volatile] long long 75 | // [const] [volatile] unsigned short 76 | // [const] [volatile] unsigned int 77 | // [const] [volatile] unsigned long 78 | // [const] [volatile] unsigned long long 79 | // 80 | /////////////////////////////////////////////////////////////////////// 81 | template struct is_integral : public false_type{}; 82 | 83 | // To do: Need to define volatile and const volatile versions of these. 84 | template <> struct is_integral : public true_type{}; 85 | template <> struct is_integral : public true_type{}; 86 | template <> struct is_integral : public true_type{}; 87 | template <> struct is_integral : public true_type{}; 88 | template <> struct is_integral : public true_type{}; 89 | template <> struct is_integral : public true_type{}; 90 | template <> struct is_integral : public true_type{}; 91 | template <> struct is_integral : public true_type{}; 92 | template <> struct is_integral : public true_type{}; 93 | template <> struct is_integral : public true_type{}; 94 | 95 | template <> struct is_integral : public true_type{}; 96 | template <> struct is_integral : public true_type{}; 97 | template <> struct is_integral : public true_type{}; 98 | template <> struct is_integral : public true_type{}; 99 | template <> struct is_integral : public true_type{}; 100 | template <> struct is_integral : public true_type{}; 101 | template <> struct is_integral : public true_type{}; 102 | template <> struct is_integral : public true_type{}; 103 | template <> struct is_integral : public true_type{}; 104 | template <> struct is_integral : public true_type{}; 105 | 106 | template <> struct is_integral : public true_type{}; 107 | template <> struct is_integral : public true_type{}; 108 | template <> struct is_integral : public true_type{}; 109 | template <> struct is_integral : public true_type{}; 110 | #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 111 | template <> struct is_integral : public true_type{}; 112 | template <> struct is_integral : public true_type{}; 113 | #endif 114 | 115 | /////////////////////////////////////////////////////////////////////// 116 | // is_floating_point 117 | // 118 | // is_floating_point::value == true if and only if T is one of the following types: 119 | // [const] [volatile] float 120 | // [const] [volatile] double 121 | // [const] [volatile] long double 122 | // 123 | /////////////////////////////////////////////////////////////////////// 124 | template struct is_floating_point : public false_type{}; 125 | 126 | // To do: Need to define volatile and const volatile versions of these. 127 | template <> struct is_floating_point : public true_type{}; 128 | template <> struct is_floating_point : public true_type{}; 129 | template <> struct is_floating_point : public true_type{}; 130 | template <> struct is_floating_point : public true_type{}; 131 | template <> struct is_floating_point : public true_type{}; 132 | template <> struct is_floating_point : public true_type{}; 133 | 134 | 135 | 136 | /////////////////////////////////////////////////////////////////////// 137 | // is_arithmetic 138 | // 139 | // is_arithmetic::value == true if and only if: 140 | // is_floating_point::value == true, or 141 | // is_integral::value == true 142 | // 143 | /////////////////////////////////////////////////////////////////////// 144 | template 145 | struct is_arithmetic : public integral_constant::value || is_floating_point::value 147 | >{}; 148 | 149 | 150 | /////////////////////////////////////////////////////////////////////// 151 | // is_fundamental 152 | // 153 | // is_fundamental::value == true if and only if: 154 | // is_floating_point::value == true, or 155 | // is_integral::value == true, or 156 | // is_void::value == true 157 | /////////////////////////////////////////////////////////////////////// 158 | template 159 | struct is_fundamental : public integral_constant::value || is_integral::value || is_floating_point::value 161 | >{}; 162 | 163 | } // namespace eastl 164 | 165 | 166 | #endif // Header include guard 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/internal/type_properties.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/internal/type_properties.h 31 | // Written and maintained by Paul Pedriana - 2005. 32 | /////////////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | #ifndef EASTL_INTERNAL_TYPE_PROPERTIES_H 36 | #define EASTL_INTERNAL_TYPE_PROPERTIES_H 37 | 38 | 39 | #include 40 | 41 | 42 | namespace eastl 43 | { 44 | 45 | // The following properties or relations are defined here. If the given 46 | // item is missing then it simply hasn't been implemented, at least not yet. 47 | 48 | /////////////////////////////////////////////////////////////////////// 49 | // is_const 50 | // 51 | // is_const::value == true if and only if T has const-qualification. 52 | // 53 | /////////////////////////////////////////////////////////////////////// 54 | template struct is_const_value : public false_type{}; 55 | template struct is_const_value : public true_type{}; 56 | template struct is_const_value : public true_type{}; 57 | 58 | template struct is_const : public is_const_value{}; 59 | template struct is_const : public false_type{}; // Note here that T is const, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard. 60 | 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////// 64 | // is_volatile 65 | // 66 | // is_volatile::value == true if and only if T has volatile-qualification. 67 | // 68 | /////////////////////////////////////////////////////////////////////// 69 | 70 | template struct is_volatile_value : public false_type{}; 71 | template struct is_volatile_value : public true_type{}; 72 | template struct is_volatile_value : public true_type{}; 73 | 74 | template struct is_volatile : public is_volatile_value{}; 75 | template struct is_volatile : public false_type{}; // Note here that T is volatile, not the reference to T. So is_const is false. See section 8.3.2p1 of the C++ standard. 76 | 77 | 78 | 79 | /////////////////////////////////////////////////////////////////////// 80 | // is_abstract 81 | // 82 | // is_abstract::value == true if and only if T is a class or struct 83 | // that has at least one pure virtual function. is_abstract may only 84 | // be applied to complete types. 85 | // 86 | /////////////////////////////////////////////////////////////////////// 87 | 88 | // Not implemented yet. 89 | 90 | 91 | 92 | /////////////////////////////////////////////////////////////////////// 93 | // is_signed 94 | // 95 | // is_signed::value == true if and only if T is one of the following types: 96 | // [const] [volatile] char (maybe) 97 | // [const] [volatile] signed char 98 | // [const] [volatile] short 99 | // [const] [volatile] int 100 | // [const] [volatile] long 101 | // [const] [volatile] long long 102 | // 103 | // Used to determine if a integral type is signed or unsigned. 104 | // Given that there are some user-made classes which emulate integral 105 | // types, we provide the EASTL_DECLARE_SIGNED macro to allow you to 106 | // set a given class to be identified as a signed type. 107 | /////////////////////////////////////////////////////////////////////// 108 | template struct is_signed : public false_type{}; 109 | 110 | template <> struct is_signed : public true_type{}; 111 | template <> struct is_signed : public true_type{}; 112 | template <> struct is_signed : public true_type{}; 113 | template <> struct is_signed : public true_type{}; 114 | template <> struct is_signed : public true_type{}; 115 | template <> struct is_signed : public true_type{}; 116 | template <> struct is_signed : public true_type{}; 117 | template <> struct is_signed : public true_type{}; 118 | template <> struct is_signed : public true_type{}; 119 | template <> struct is_signed : public true_type{}; 120 | 121 | #if (CHAR_MAX == SCHAR_MAX) 122 | template <> struct is_signed : public true_type{}; 123 | template <> struct is_signed : public true_type{}; 124 | #endif 125 | #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 126 | #if defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 2147483647) || (__WCHAR_MAX__ == 32767)) // GCC defines __WCHAR_MAX__ for most platforms. 127 | template <> struct is_signed : public true_type{}; 128 | template <> struct is_signed : public true_type{}; 129 | #endif 130 | #endif 131 | 132 | #define EASTL_DECLARE_SIGNED(T) namespace eastl{ template <> struct is_signed : public true_type{}; template <> struct is_signed : public true_type{}; } 133 | 134 | 135 | 136 | /////////////////////////////////////////////////////////////////////// 137 | // is_unsigned 138 | // 139 | // is_unsigned::value == true if and only if T is one of the following types: 140 | // [const] [volatile] char (maybe) 141 | // [const] [volatile] unsigned char 142 | // [const] [volatile] unsigned short 143 | // [const] [volatile] unsigned int 144 | // [const] [volatile] unsigned long 145 | // [const] [volatile] unsigned long long 146 | // 147 | // Used to determine if a integral type is signed or unsigned. 148 | // Given that there are some user-made classes which emulate integral 149 | // types, we provide the EASTL_DECLARE_UNSIGNED macro to allow you to 150 | // set a given class to be identified as an unsigned type. 151 | /////////////////////////////////////////////////////////////////////// 152 | template struct is_unsigned : public false_type{}; 153 | 154 | template <> struct is_unsigned : public true_type{}; 155 | template <> struct is_unsigned : public true_type{}; 156 | template <> struct is_unsigned : public true_type{}; 157 | template <> struct is_unsigned : public true_type{}; 158 | template <> struct is_unsigned : public true_type{}; 159 | template <> struct is_unsigned : public true_type{}; 160 | template <> struct is_unsigned : public true_type{}; 161 | template <> struct is_unsigned : public true_type{}; 162 | template <> struct is_unsigned : public true_type{}; 163 | template <> struct is_unsigned : public true_type{}; 164 | 165 | #if (CHAR_MAX == UCHAR_MAX) 166 | template <> struct is_unsigned : public true_type{}; 167 | template <> struct is_unsigned : public true_type{}; 168 | #endif 169 | #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 170 | #if defined(_MSC_VER) || (defined(__WCHAR_MAX__) && ((__WCHAR_MAX__ == 4294967295U) || (__WCHAR_MAX__ == 65535))) // GCC defines __WCHAR_MAX__ for most platforms. 171 | template <> struct is_unsigned : public true_type{}; 172 | template <> struct is_unsigned : public true_type{}; 173 | #endif 174 | #endif 175 | 176 | #define EASTL_DECLARE_UNSIGNED(T) namespace eastl{ template <> struct is_unsigned : public true_type{}; template <> struct is_unsigned : public true_type{}; } 177 | 178 | 179 | 180 | /////////////////////////////////////////////////////////////////////// 181 | // alignment_of 182 | // 183 | // alignment_of::value is an integral value representing, in bytes, 184 | // the memory alignment of objects of type T. 185 | // 186 | // alignment_of may only be applied to complete types. 187 | // 188 | /////////////////////////////////////////////////////////////////////// 189 | template 190 | struct alignment_of_value{ static const size_t value = EASTL_ALIGN_OF(T); }; 191 | 192 | template 193 | struct alignment_of : public integral_constant::value>{}; 194 | 195 | 196 | 197 | /////////////////////////////////////////////////////////////////////// 198 | // is_aligned 199 | // 200 | // Defined as true if the type has alignment requirements greater 201 | // than default alignment, which is taken to be 8. This allows for 202 | // doing specialized object allocation and placement for such types. 203 | /////////////////////////////////////////////////////////////////////// 204 | template 205 | struct is_aligned_value{ static const bool value = (EASTL_ALIGN_OF(T) > 8); }; 206 | 207 | template 208 | struct is_aligned : public integral_constant::value>{}; 209 | 210 | 211 | 212 | /////////////////////////////////////////////////////////////////////// 213 | // rank 214 | // 215 | // rank::value is an integral value representing the number of 216 | // dimensions possessed by an array type. For example, given a 217 | // multi-dimensional array type T[M][N], std::tr1::rank::value == 2. 218 | // For a given non-array type T, std::tr1::rank::value == 0. 219 | // 220 | /////////////////////////////////////////////////////////////////////// 221 | 222 | // Not implemented yet. 223 | 224 | 225 | 226 | /////////////////////////////////////////////////////////////////////// 227 | // extent 228 | // 229 | // extent::value is an integral type representing the number of 230 | // elements in the Ith dimension of array type T. 231 | // 232 | // For a given array type T[N], std::tr1::extent::value == N. 233 | // For a given multi-dimensional array type T[M][N], std::tr1::extent::value == N. 234 | // For a given multi-dimensional array type T[M][N], std::tr1::extent::value == M. 235 | // For a given array type T and a given dimension I where I >= rank::value, std::tr1::extent::value == 0. 236 | // For a given array type of unknown extent T[], std::tr1::extent::value == 0. 237 | // For a given non-array type T and an arbitrary dimension I, std::tr1::extent::value == 0. 238 | // 239 | /////////////////////////////////////////////////////////////////////// 240 | 241 | // Not implemented yet. 242 | 243 | 244 | 245 | /////////////////////////////////////////////////////////////////////// 246 | // is_base_of 247 | // 248 | // Given two (possibly identical) types Base and Derived, is_base_of::value == true 249 | // if and only if Base is a direct or indirect base class of Derived, 250 | // or Base and Derived are the same type. 251 | // 252 | // is_base_of may only be applied to complete types. 253 | // 254 | /////////////////////////////////////////////////////////////////////// 255 | 256 | // Not implemented yet. 257 | 258 | 259 | 260 | } // namespace eastl 261 | 262 | 263 | #endif // Header include guard 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/internal/type_transformations.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/internal/type_transformations.h 31 | // Written and maintained by Paul Pedriana - 2005 32 | /////////////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | #ifndef EASTL_INTERNAL_TYPE_TRANFORMATIONS_H 36 | #define EASTL_INTERNAL_TYPE_TRANFORMATIONS_H 37 | 38 | 39 | namespace eastl 40 | { 41 | 42 | 43 | // The following transformations are defined here. If the given item 44 | // is missing then it simply hasn't been implemented, at least not yet. 45 | // add_unsigned 46 | // add_signed 47 | // remove_const 48 | // remove_volatile 49 | // remove_cv 50 | // add_const 51 | // add_volatile 52 | // add_cv 53 | // remove_reference 54 | // add_reference 55 | // remove_extent 56 | // remove_all_extents 57 | // remove_pointer 58 | // add_pointer 59 | // aligned_storage 60 | 61 | 62 | /////////////////////////////////////////////////////////////////////// 63 | // add_signed 64 | // 65 | // Adds signed-ness to the given type. 66 | // Modifies only integral values; has no effect on others. 67 | // add_signed::type is int 68 | // add_signed::type is int 69 | // 70 | /////////////////////////////////////////////////////////////////////// 71 | 72 | template 73 | struct add_signed 74 | { typedef T type; }; 75 | 76 | template<> 77 | struct add_signed 78 | { typedef signed char type; }; 79 | 80 | #if (defined(CHAR_MAX) && defined(UCHAR_MAX) && (CHAR_MAX == UCHAR_MAX)) // If char is unsigned (which is usually not the case)... 81 | template<> 82 | struct add_signed 83 | { typedef signed char type; }; 84 | #endif 85 | 86 | template<> 87 | struct add_signed 88 | { typedef short type; }; 89 | 90 | template<> 91 | struct add_signed 92 | { typedef int type; }; 93 | 94 | template<> 95 | struct add_signed 96 | { typedef long type; }; 97 | 98 | template<> 99 | struct add_signed 100 | { typedef long long type; }; 101 | 102 | #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 103 | #if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 4294967295U)) // If wchar_t is a 32 bit unsigned value... 104 | template<> 105 | struct add_signed 106 | { typedef int32_t type; }; 107 | #elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 65535)) // If wchar_t is a 16 bit unsigned value... 108 | template<> 109 | struct add_signed 110 | { typedef int16_t type; }; 111 | #endif 112 | #endif 113 | 114 | 115 | 116 | /////////////////////////////////////////////////////////////////////// 117 | // add_unsigned 118 | // 119 | // Adds unsigned-ness to the given type. 120 | // Modifies only integral values; has no effect on others. 121 | // add_unsigned::type is unsigned int 122 | // add_unsigned::type is unsigned int 123 | // 124 | /////////////////////////////////////////////////////////////////////// 125 | 126 | template 127 | struct add_unsigned 128 | { typedef T type; }; 129 | 130 | template<> 131 | struct add_unsigned 132 | { typedef unsigned char type; }; 133 | 134 | #if (defined(CHAR_MAX) && defined(SCHAR_MAX) && (CHAR_MAX == SCHAR_MAX)) // If char is signed (which is usually so)... 135 | template<> 136 | struct add_unsigned 137 | { typedef unsigned char type; }; 138 | #endif 139 | 140 | template<> 141 | struct add_unsigned 142 | { typedef unsigned short type; }; 143 | 144 | template<> 145 | struct add_unsigned 146 | { typedef unsigned int type; }; 147 | 148 | template<> 149 | struct add_unsigned 150 | { typedef unsigned long type; }; 151 | 152 | template<> 153 | struct add_unsigned 154 | { typedef unsigned long long type; }; 155 | 156 | #ifndef EA_WCHAR_T_NON_NATIVE // If wchar_t is a native type instead of simply a define to an existing type... 157 | #if (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 2147483647)) // If wchar_t is a 32 bit signed value... 158 | template<> 159 | struct add_unsigned 160 | { typedef uint32_t type; }; 161 | #elif (defined(__WCHAR_MAX__) && (__WCHAR_MAX__ == 32767)) // If wchar_t is a 16 bit signed value... 162 | template<> 163 | struct add_unsigned 164 | { typedef uint16_t type; }; 165 | #endif 166 | #endif 167 | 168 | /////////////////////////////////////////////////////////////////////// 169 | // remove_cv 170 | // 171 | // Remove const and volatile from a type. 172 | // 173 | // The remove_cv transformation trait removes top-level const and/or volatile 174 | // qualification (if any) from the type to which it is applied. For a given type T, 175 | // remove_cv::type is equivalent to T. For example, 176 | // remove_cv::type is equivalent to char*, while remove_cv::type 177 | // is equivalent to const char*. In the latter case, the const qualifier modifies 178 | // char, not *, and is therefore not at the top level. 179 | // 180 | /////////////////////////////////////////////////////////////////////// 181 | template struct remove_cv_imp{}; 182 | template struct remove_cv_imp { typedef T unqualified_type; }; 183 | template struct remove_cv_imp { typedef T unqualified_type; }; 184 | template struct remove_cv_imp { typedef T unqualified_type; }; 185 | template struct remove_cv_imp { typedef T unqualified_type; }; 186 | 187 | template struct remove_cv{ typedef typename remove_cv_imp::unqualified_type type; }; 188 | template struct remove_cv{ typedef T& type; }; // References are automatically not const nor volatile. See section 8.3.2p1 of the C++ standard. 189 | 190 | template struct remove_cv { typedef T type[N]; }; 191 | template struct remove_cv { typedef T type[N]; }; 192 | template struct remove_cv{ typedef T type[N]; }; 193 | 194 | 195 | 196 | /////////////////////////////////////////////////////////////////////// 197 | // add_reference 198 | // 199 | // Add reference to a type. 200 | // 201 | // The add_reference transformation trait adds a level of indirection 202 | // by reference to the type to which it is applied. For a given type T, 203 | // add_reference::type is equivalent to T& if is_reference::value == false, 204 | // and T otherwise. 205 | // 206 | /////////////////////////////////////////////////////////////////////// 207 | template 208 | struct add_reference_impl{ typedef T& type; }; 209 | 210 | template 211 | struct add_reference_impl{ typedef T& type; }; 212 | 213 | template <> 214 | struct add_reference_impl{ typedef void type; }; 215 | 216 | template 217 | struct add_reference { typedef typename add_reference_impl::type type; }; 218 | 219 | 220 | } // namespace eastl 221 | 222 | 223 | #endif // Header include guard 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /3rd-party/eastl/include/EASTL/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/utility.h 31 | // Written and maintained by Paul Pedriana - 2005. 32 | /////////////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | 36 | #ifndef EASTL_UTILITY_H 37 | #define EASTL_UTILITY_H 38 | 39 | 40 | #include 41 | 42 | 43 | #ifdef _MSC_VER 44 | #pragma warning(push) // VC++ generates a bogus warning that you cannot code away. 45 | #pragma warning(disable: 4619) // There is no warning number 'number'. 46 | #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction. 47 | #pragma warning(disable: 4512) // 'class' : assignment operator could not be generated. // This disabling would best be put elsewhere. 48 | #endif 49 | 50 | 51 | namespace eastl 52 | { 53 | 54 | /////////////////////////////////////////////////////////////////////// 55 | /// rel_ops 56 | /// 57 | /// rel_ops allow the automatic generation of operators !=, >, <=, >= from 58 | /// just operators == and <. These are intentionally in the rel_ops namespace 59 | /// so that they don't conflict with other similar operators. To use these 60 | /// operators, add "using namespace std::rel_ops;" to an appropriate place in 61 | /// your code, usually right in the function that you need them to work. 62 | /// In fact, you will very likely have collision problems if you put such 63 | /// using statements anywhere other than in the .cpp file like so and may 64 | /// also have collisions when you do, as the using statement will affect all 65 | /// code in the module. You need to be careful about use of rel_ops. 66 | /// 67 | namespace rel_ops 68 | { 69 | template 70 | inline bool operator!=(const T& x, const T& y) 71 | { return !(x == y); } 72 | 73 | template 74 | inline bool operator>(const T& x, const T& y) 75 | { return (y < x); } 76 | 77 | template 78 | inline bool operator<=(const T& x, const T& y) 79 | { return !(y < x); } 80 | 81 | template 82 | inline bool operator>=(const T& x, const T& y) 83 | { return !(x < y); } 84 | } 85 | 86 | 87 | 88 | /////////////////////////////////////////////////////////////////////// 89 | /// pair 90 | /// 91 | /// Implements a simple pair, just like the C++ std::pair. 92 | /// 93 | template 94 | struct pair 95 | { 96 | typedef T1 first_type; 97 | typedef T2 second_type; 98 | 99 | T1 first; 100 | T2 second; 101 | 102 | pair(); 103 | pair(const T1& x); 104 | pair(const T1& x, const T2& y); 105 | 106 | template 107 | pair(const pair& p); 108 | 109 | // pair(const pair& p); // Not necessary, as default version is OK. 110 | // pair& operator=(const pair& p); // Not necessary, as default version is OK. 111 | }; 112 | 113 | 114 | 115 | 116 | /// use_self 117 | /// 118 | /// operator()(x) simply returns x. Used in sets, as opposed to maps. 119 | /// This is a template policy implementation; it is an alternative to 120 | /// the use_first template implementation. 121 | /// 122 | /// The existance of use_self may seem odd, given that it does nothing, 123 | /// but these kinds of things are useful, virtually required, for optimal 124 | /// generic programming. 125 | /// 126 | template 127 | struct use_self // : public unary_function // Perhaps we want to make it a subclass of unary_function. 128 | { 129 | typedef T result_type; 130 | 131 | const T& operator()(const T& x) const 132 | { return x; } 133 | }; 134 | 135 | /// use_first 136 | /// 137 | /// operator()(x) simply returns x.first. Used in maps, as opposed to sets. 138 | /// This is a template policy implementation; it is an alternative to 139 | /// the use_self template implementation. This is the same thing as the 140 | /// SGI SGL select1st utility. 141 | /// 142 | template 143 | struct use_first // : public unary_function // Perhaps we want to make it a subclass of unary_function. 144 | { 145 | typedef typename Pair::first_type result_type; 146 | 147 | const result_type& operator()(const Pair& x) const 148 | { return x.first; } 149 | }; 150 | 151 | /// use_second 152 | /// 153 | /// operator()(x) simply returns x.second. 154 | /// This is the same thing as the SGI SGL select2nd utility 155 | /// 156 | template 157 | struct use_second // : public unary_function // Perhaps we want to make it a subclass of unary_function. 158 | { 159 | typedef typename Pair::second_type result_type; 160 | 161 | const result_type& operator()(const Pair& x) const 162 | { return x.second; } 163 | }; 164 | 165 | 166 | 167 | 168 | 169 | /////////////////////////////////////////////////////////////////////// 170 | // pair 171 | /////////////////////////////////////////////////////////////////////// 172 | 173 | template 174 | inline pair::pair() 175 | : first(), second() 176 | { 177 | // Empty 178 | } 179 | 180 | 181 | template 182 | inline pair::pair(const T1& x) 183 | : first(x), second() 184 | { 185 | // Empty 186 | } 187 | 188 | 189 | template 190 | inline pair::pair(const T1& x, const T2& y) 191 | : first(x), second(y) 192 | { 193 | // Empty 194 | } 195 | 196 | 197 | template 198 | template 199 | inline pair::pair(const pair& p) 200 | : first(p.first), second(p.second) 201 | { 202 | // Empty 203 | } 204 | 205 | 206 | 207 | 208 | /////////////////////////////////////////////////////////////////////// 209 | // global operators 210 | /////////////////////////////////////////////////////////////////////// 211 | 212 | template 213 | inline bool operator==(const pair& a, const pair& b) 214 | { 215 | return ((a.first == b.first) && (a.second == b.second)); 216 | } 217 | 218 | 219 | template 220 | inline bool operator<(const pair& a, const pair& b) 221 | { 222 | // Note that we use only operator < in this expression. Otherwise we could 223 | // use the simpler: return (a.m1 == b.m1) ? (a.m2 < b.m2) : (a.m1 < b.m1); 224 | // The user can write a specialization for this operator to get around this 225 | // in cases where the highest performance is required. 226 | return ((a.first < b.first) || (!(b.first < a.first) && (a.second < b.second))); 227 | } 228 | 229 | 230 | template 231 | inline bool operator!=(const pair& a, const pair& b) 232 | { 233 | return !(a == b); 234 | } 235 | 236 | 237 | template 238 | inline bool operator>(const pair& a, const pair& b) 239 | { 240 | return b < a; 241 | } 242 | 243 | 244 | template 245 | inline bool operator>=(const pair& a, const pair& b) 246 | { 247 | return !(a < b); 248 | } 249 | 250 | 251 | template 252 | inline bool operator<=(const pair& a, const pair& b) 253 | { 254 | return !(b < a); 255 | } 256 | 257 | 258 | 259 | 260 | /////////////////////////////////////////////////////////////////////// 261 | /// make_pair / make_pair_ref 262 | /// 263 | /// make_pair is the same as std::make_pair specified by the C++ standard. 264 | /// If you look at the C++ standard, you'll see that it specifies T& instead of T. 265 | /// However, it has been determined that the C++ standard is incorrect and has 266 | /// flagged it as a defect (http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#181). 267 | /// In case you feel that you want a more efficient version that uses references, 268 | /// we provide the make_pair_ref function below. 269 | /// 270 | /// Note: You don't need to use make_pair in order to make a pair. The following 271 | /// code is equivalent, and the latter avoids one more level of inlining: 272 | /// return make_pair(charPtr, charPtr); 273 | /// return pair(charPtr, charPtr); 274 | /// 275 | template 276 | inline pair make_pair(T1 a, T2 b) 277 | { 278 | return pair(a, b); 279 | } 280 | 281 | 282 | template 283 | inline pair make_pair_ref(const T1& a, const T2& b) 284 | { 285 | return pair(a, b); 286 | } 287 | 288 | 289 | } // namespace eastl 290 | 291 | 292 | #ifdef _MSC_VER 293 | #pragma warning(pop) 294 | #endif 295 | 296 | 297 | #endif // Header include guard 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/allocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/allocator.cpp 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | #include 38 | #include 39 | 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // ReadMe 43 | // 44 | // This file implements the default application allocator. 45 | // You can replace this allocator.cpp file with a different one, 46 | // you can define EASTL_USER_DEFINED_ALLOCATOR below to ignore this file, 47 | // or you can modify the EASTL config.h file to redefine how allocators work. 48 | /////////////////////////////////////////////////////////////////////////////// 49 | 50 | 51 | #ifndef EASTL_USER_DEFINED_ALLOCATOR // If the user hasn't declared that he has defined an allocator implementation elsewhere... 52 | 53 | namespace eastl 54 | { 55 | 56 | /// gDefaultAllocator 57 | /// Default global allocator instance. 58 | EASTL_API allocator gDefaultAllocator; 59 | EASTL_API allocator* gpDefaultAllocator = &gDefaultAllocator; 60 | 61 | EASTL_API allocator* GetDefaultAllocator() 62 | { 63 | return gpDefaultAllocator; 64 | } 65 | 66 | EASTL_API allocator* SetDefaultAllocator(allocator* pAllocator) 67 | { 68 | allocator* const pPrevAllocator = gpDefaultAllocator; 69 | gpDefaultAllocator = pAllocator; 70 | return pPrevAllocator; 71 | } 72 | 73 | } // namespace eastl 74 | 75 | 76 | #endif // EASTL_USER_DEFINED_ALLOCATOR 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/assert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/assert.cpp 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | #if defined(EA_PLATFORM_MICROSOFT) 43 | #pragma warning(push, 0) 44 | #if defined _MSC_VER 45 | #include 46 | #endif 47 | #if defined(EA_PLATFORM_WINDOWS) 48 | #ifndef WIN32_LEAN_AND_MEAN 49 | #define WIN32_LEAN_AND_MEAN 50 | #endif 51 | #include 52 | #elif defined(EA_PLATFORM_XENON) 53 | #include 54 | #endif 55 | #pragma warning(pop) 56 | #else 57 | #include 58 | #endif 59 | 60 | 61 | 62 | 63 | namespace eastl 64 | { 65 | 66 | /// gpAssertionFailureFunction 67 | /// 68 | /// Global assertion failure function pointer. Set by SetAssertionFailureFunction. 69 | /// 70 | EASTL_API EASTL_AssertionFailureFunction gpAssertionFailureFunction = AssertionFailureFunctionDefault; 71 | EASTL_API void* gpAssertionFailureFunctionContext = NULL; 72 | 73 | 74 | 75 | /// SetAssertionFailureFunction 76 | /// 77 | /// Sets the function called when an assertion fails. If this function is not called 78 | /// by the user, a default function will be used. The user may supply a context parameter 79 | /// which will be passed back to the user in the function call. This is typically used 80 | /// to store a C++ 'this' pointer, though other things are possible. 81 | /// 82 | /// There is no thread safety here, so the user needs to externally make sure that 83 | /// this function is not called in a thread-unsafe way. The easiest way to do this is 84 | /// to just call this function once from the main thread on application startup. 85 | /// 86 | EASTL_API void SetAssertionFailureFunction(EASTL_AssertionFailureFunction pAssertionFailureFunction, void* pContext) 87 | { 88 | gpAssertionFailureFunction = pAssertionFailureFunction; 89 | gpAssertionFailureFunctionContext = pContext; 90 | } 91 | 92 | 93 | 94 | /// AssertionFailureFunctionDefault 95 | /// 96 | EASTL_API void AssertionFailureFunctionDefault(const char* pExpression, void* /*pContext*/) 97 | { 98 | #if defined(EA_DEBUG) || defined(_DEBUG) 99 | // We cannot use puts() because it appends a newline. 100 | // We cannot use printf(pExpression) because pExpression might have formatting statements. 101 | #if defined(EA_PLATFORM_MICROSOFT) 102 | OutputDebugStringA(pExpression); 103 | (void)pExpression; 104 | #else 105 | printf("%s", pExpression); // Write the message to stdout, which happens to be the trace view for many console debug machines. 106 | #endif 107 | #endif 108 | EASTL_DEBUG_BREAK(); 109 | } 110 | 111 | 112 | /// AssertionFailure 113 | /// 114 | EASTL_API void AssertionFailure(const char* pExpression) 115 | { 116 | if(gpAssertionFailureFunction) 117 | gpAssertionFailureFunction(pExpression, gpAssertionFailureFunctionContext); 118 | } 119 | 120 | 121 | } // namespace eastl 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/fixed_pool.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/fixed_pool.cpp 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | 38 | #include 39 | #include 40 | 41 | 42 | 43 | namespace eastl 44 | { 45 | 46 | 47 | void fixed_pool_base::init(void* pMemory, size_t memorySize, size_t nodeSize, 48 | size_t alignment, size_t /*alignmentOffset*/) 49 | { 50 | // To do: Support alignmentOffset. 51 | 52 | #if EASTL_FIXED_SIZE_TRACKING_ENABLED 53 | mnCurrentSize = 0; 54 | mnPeakSize = 0; 55 | #endif 56 | 57 | if(pMemory) 58 | { 59 | // Assert that alignment is a power of 2 value (e.g. 1, 2, 4, 8, 16, etc.) 60 | EASTL_ASSERT((alignment & (alignment - 1)) == 0); 61 | 62 | // Make sure alignment is a valid value. 63 | if(alignment < 1) 64 | alignment = 1; 65 | 66 | mpNext = (Link*)(((uintptr_t)pMemory + (alignment - 1)) & ~(alignment - 1)); 67 | memorySize -= (uintptr_t)mpNext - (uintptr_t)pMemory; 68 | pMemory = mpNext; 69 | 70 | // The node size must be at least as big as a Link, which itself is sizeof(void*). 71 | if(nodeSize < sizeof(Link)) 72 | nodeSize = ((sizeof(Link) + (alignment - 1))) & ~(alignment - 1); 73 | 74 | // If the user passed in a memory size that wasn't a multiple of the node size, 75 | // we need to chop down the memory size so that the last node is not a whole node. 76 | memorySize = (memorySize / nodeSize) * nodeSize; 77 | 78 | mpCapacity = (Link*)((uintptr_t)pMemory + memorySize); 79 | mpHead = NULL; 80 | mnNodeSize = nodeSize; 81 | } 82 | } 83 | 84 | 85 | } // namespace eastl 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/hashtable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/hashtable.cpp 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | 38 | #include 39 | #include 40 | #include // Not all compilers support and std::ceil(), which we need below. 41 | #include 42 | 43 | 44 | #ifdef _MSC_VER 45 | #pragma warning(disable: 4267) // 'argument' : conversion from 'size_t' to 'const uint32_t', possible loss of data. This is a bogus warning resulting from a bug in VC++. 46 | #endif 47 | 48 | 49 | namespace eastl 50 | { 51 | 52 | /// gpEmptyBucketArray 53 | /// 54 | /// A shared representation of an empty hash table. This is present so that 55 | /// a new empty hashtable allocates no memory. It has two entries, one for 56 | /// the first lone empty (NULL) bucket, and one for the non-NULL trailing sentinel. 57 | /// 58 | EASTL_API void* gpEmptyBucketArray[2] = { NULL, (void*)uintptr_t(~0) }; 59 | 60 | 61 | 62 | /// gPrimeNumberArray 63 | /// 64 | /// This is an array of prime numbers. This is the same set of prime 65 | /// numbers suggested by the C++ standard proposal. These are numbers 66 | /// which are separated by 8% per entry. 67 | /// 68 | /// To consider: Allow the user to specify their own prime number array. 69 | /// 70 | const uint32_t gPrimeNumberArray[] = 71 | { 72 | 2u, 3u, 5u, 7u, 11u, 13u, 17u, 19u, 23u, 29u, 31u, 73 | 37u, 41u, 43u, 47u, 53u, 59u, 61u, 67u, 71u, 73u, 79u, 74 | 83u, 89u, 97u, 103u, 109u, 113u, 127u, 137u, 139u, 149u, 75 | 157u, 167u, 179u, 193u, 199u, 211u, 227u, 241u, 257u, 76 | 277u, 293u, 313u, 337u, 359u, 383u, 409u, 439u, 467u, 77 | 503u, 541u, 577u, 619u, 661u, 709u, 761u, 823u, 887u, 78 | 953u, 1031u, 1109u, 1193u, 1289u, 1381u, 1493u, 1613u, 79 | 1741u, 1879u, 2029u, 2179u, 2357u, 2549u, 2753u, 2971u, 80 | 3209u, 3469u, 3739u, 4027u, 4349u, 4703u, 5087u, 5503u, 81 | 5953u, 6427u, 6949u, 7517u, 8123u, 8783u, 9497u, 10273u, 82 | 11113u, 12011u, 12983u, 14033u, 15173u, 16411u, 17749u, 83 | 19183u, 20753u, 22447u, 24281u, 26267u, 28411u, 30727u, 84 | 33223u, 35933u, 38873u, 42043u, 45481u, 49201u, 53201u, 85 | 57557u, 62233u, 67307u, 72817u, 78779u, 85229u, 92203u, 86 | 99733u, 107897u, 116731u, 126271u, 136607u, 147793u, 87 | 159871u, 172933u, 187091u, 202409u, 218971u, 236897u, 88 | 256279u, 277261u, 299951u, 324503u, 351061u, 379787u, 89 | 410857u, 444487u, 480881u, 520241u, 562841u, 608903u, 90 | 658753u, 712697u, 771049u, 834181u, 902483u, 976369u, 91 | 1056323u, 1142821u, 1236397u, 1337629u, 1447153u, 1565659u, 92 | 1693859u, 1832561u, 1982627u, 2144977u, 2320627u, 2510653u, 93 | 2716249u, 2938679u, 3179303u, 3439651u, 3721303u, 4026031u, 94 | 4355707u, 4712381u, 5098259u, 5515729u, 5967347u, 6456007u, 95 | 6984629u, 7556579u, 8175383u, 8844859u, 9569143u, 10352717u, 96 | 11200489u, 12117689u, 13109983u, 14183539u, 15345007u, 97 | 16601593u, 17961079u, 19431899u, 21023161u, 22744717u, 98 | 24607243u, 26622317u, 28802401u, 31160981u, 33712729u, 99 | 36473443u, 39460231u, 42691603u, 46187573u, 49969847u, 100 | 54061849u, 58488943u, 63278561u, 68460391u, 74066549u, 101 | 80131819u, 86693767u, 93793069u, 101473717u, 109783337u, 102 | 118773397u, 128499677u, 139022417u, 150406843u, 162723577u, 103 | 176048909u, 190465427u, 206062531u, 222936881u, 241193053u, 104 | 260944219u, 282312799u, 305431229u, 330442829u, 357502601u, 105 | 386778277u, 418451333u, 452718089u, 489790921u, 529899637u, 106 | 573292817u, 620239453u, 671030513u, 725980837u, 785430967u, 107 | 849749479u, 919334987u, 994618837u, 1076067617u, 1164186217u, 108 | 1259520799u, 1362662261u, 1474249943u, 1594975441u, 109 | 1725587117u, 1866894511u, 2019773507u, 2185171673u, 110 | 2364114217u, 2557710269u, 2767159799u, 2993761039u, 111 | 3238918481u, 3504151727u, 3791104843u, 4101556399u, 112 | 4294967291u, 113 | 4294967291u // Sentinel so we don't have to test result of lower_bound 114 | }; 115 | 116 | 117 | /// kPrimeCount 118 | /// 119 | /// The number of prime numbers in gPrimeNumberArray. 120 | /// 121 | const uint32_t kPrimeCount = (sizeof(gPrimeNumberArray) / sizeof(gPrimeNumberArray[0]) - 1); 122 | 123 | 124 | /// GetPrevBucketCountOnly 125 | /// Return a bucket count no greater than nBucketCountHint. 126 | /// 127 | uint32_t prime_rehash_policy::GetPrevBucketCountOnly(uint32_t nBucketCountHint) 128 | { 129 | const uint32_t nPrime = *(eastl::upper_bound(gPrimeNumberArray, gPrimeNumberArray + kPrimeCount, nBucketCountHint) - 1); 130 | return nPrime; 131 | } 132 | 133 | 134 | /// GetPrevBucketCount 135 | /// Return a bucket count no greater than nBucketCountHint. 136 | /// This function has a side effect of updating mnNextResize. 137 | /// 138 | uint32_t prime_rehash_policy::GetPrevBucketCount(uint32_t nBucketCountHint) const 139 | { 140 | const uint32_t nPrime = *(eastl::upper_bound(gPrimeNumberArray, gPrimeNumberArray + kPrimeCount, nBucketCountHint) - 1); 141 | 142 | mnNextResize = (uint32_t)ceil(nPrime * mfMaxLoadFactor); 143 | return nPrime; 144 | } 145 | 146 | 147 | /// GetNextBucketCount 148 | /// Return a prime no smaller than nBucketCountHint. 149 | /// This function has a side effect of updating mnNextResize. 150 | /// 151 | uint32_t prime_rehash_policy::GetNextBucketCount(uint32_t nBucketCountHint) const 152 | { 153 | const uint32_t nPrime = *eastl::lower_bound(gPrimeNumberArray, gPrimeNumberArray + kPrimeCount, nBucketCountHint); 154 | 155 | mnNextResize = (uint32_t)ceil(nPrime * mfMaxLoadFactor); 156 | return nPrime; 157 | } 158 | 159 | 160 | /// GetBucketCount 161 | /// Return the smallest prime p such that alpha p >= nElementCount, where alpha 162 | /// is the load factor. This function has a side effect of updating mnNextResize. 163 | /// 164 | uint32_t prime_rehash_policy::GetBucketCount(uint32_t nElementCount) const 165 | { 166 | const uint32_t nMinBucketCount = (uint32_t)(nElementCount / mfMaxLoadFactor); 167 | const uint32_t nPrime = *eastl::lower_bound(gPrimeNumberArray, gPrimeNumberArray + kPrimeCount, nMinBucketCount); 168 | 169 | mnNextResize = (uint32_t)ceil(nPrime * mfMaxLoadFactor); 170 | return nPrime; 171 | } 172 | 173 | 174 | /// GetRehashRequired 175 | /// Finds the smallest prime p such that alpha p > nElementCount + nElementAdd. 176 | /// If p > nBucketCount, return pair(true, p); otherwise return 177 | /// pair(false, 0). In principle this isn't very different from GetBucketCount. 178 | /// This function has a side effect of updating mnNextResize. 179 | /// 180 | eastl::pair 181 | prime_rehash_policy::GetRehashRequired(uint32_t nBucketCount, uint32_t nElementCount, uint32_t nElementAdd) const 182 | { 183 | if((nElementCount + nElementAdd) > mnNextResize) // It is significant that we specify > next resize and not >= next resize. 184 | { 185 | if(nBucketCount == 1) // We force rehashing to occur if the bucket count is < 2. 186 | nBucketCount = 0; 187 | 188 | float fMinBucketCount = (nElementCount + nElementAdd) / mfMaxLoadFactor; 189 | 190 | if(fMinBucketCount > (float)nBucketCount) 191 | { 192 | fMinBucketCount = eastl::max_alt(fMinBucketCount, mfGrowthFactor * nBucketCount); 193 | const uint32_t nPrime = *eastl::lower_bound(gPrimeNumberArray, gPrimeNumberArray + kPrimeCount, (uint32_t)fMinBucketCount); 194 | mnNextResize = (uint32_t)ceil(nPrime * mfMaxLoadFactor); 195 | 196 | return eastl::pair(true, nPrime); 197 | } 198 | else 199 | { 200 | mnNextResize = (uint32_t)ceil(nBucketCount * mfMaxLoadFactor); 201 | return eastl::pair(false, (uint32_t)0); 202 | } 203 | } 204 | 205 | return eastl::pair(false, (uint32_t)0); 206 | } 207 | 208 | 209 | } // namespace eastl 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // required by eastl (see 3rd-party/eastl/README) 5 | 6 | void* operator new[](size_t size, const char* /*name*/, int /*flags*/, unsigned /*debug_flags*/, const char* /*file*/, int /*line*/) 7 | { 8 | return new char[size]; 9 | } 10 | 11 | void* operator new[](size_t size, size_t /*alignment*/, size_t /*alignment_offset*/, const char* /*name*/, int /*flags*/, unsigned /*debug_flags*/, const char* /*file*/, int /*line*/) 12 | { 13 | return new char[size]; 14 | } 15 | -------------------------------------------------------------------------------- /3rd-party/eastl/src/string.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009-2010 Electronic Arts, Inc. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 14 | its contributors may be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // EASTL/string.cpp 31 | // 32 | // Copyright (c) 2005, Electronic Arts. All rights reserved. 33 | // Written and maintained by Paul Pedriana. 34 | /////////////////////////////////////////////////////////////////////////////// 35 | 36 | 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | 43 | namespace eastl 44 | { 45 | 46 | /// gEmptyString 47 | /// 48 | /// gEmptyString is used for empty strings. This allows us to avoid allocating 49 | /// memory for empty strings without having to add null pointer checks. 50 | /// The downside of this technique is that all empty strings share this same 51 | /// value and if any code makes an error and writes to this value with non-zero, 52 | /// then all existing empty strings will be wrecked and not just the one that 53 | /// was incorrectly overwritten. 54 | EASTL_API EmptyString gEmptyString = { 0 }; 55 | 56 | 57 | } // namespace eastl 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /CMAKE_NOTES.md: -------------------------------------------------------------------------------- 1 | ##cmake 2 | 3 | Search for all `.cpp` files in `src` directory, and add to `${SOURCES}` 4 | 5 | file(GLOB SOURCES "src/*.cpp") 6 | 7 | Create an executable called `app_name` from `${SOURCES}` 8 | 9 | add_executable(app_name ${SOURCES}) 10 | 11 | Create a static lib called `lib_name` from `${SOURCES}` 12 | 13 | add_library(lib_name STATIC ${SOURCES}) 14 | 15 | Link a library 16 | 17 | set(LIBS lib_foo.a) 18 | link_directories(../lib_foo/build) 19 | target_link_libraries(app_name ${LIBS}) 20 | 21 | ###Pull in CMakeLists from subdirectories 22 | 23 | add_subdirectory(foo) 24 | 25 | ###Create a version file 26 | 27 | set (FOO_VERSION_MAJOR 1) 28 | set (FOO_VERSION_MINOR 0) 29 | 30 | configure_file ( 31 | "${PROJECT_SOURCE_DIR}/version.h.in" 32 | "${PROJECT_BINARY_DIR}/version.h" 33 | ) 34 | 35 | Now create the `version.h.in` file with the following contents: 36 | 37 | #define FOO_VERSION_MAJOR @FOO_VERSION_MAJOR@ 38 | #define FOO_VERSION_MINOR @FOO_VERSION_MINOR@ 39 | 40 | ###Configurable options 41 | 42 | option(USE_FOO "Use feature foo" ON) 43 | 44 | if (USE_FOO) 45 | add_subdirectory(foo) 46 | set (EXTRA_LIBS ${EXTRA_LIBS} foo) 47 | endif() 48 | 49 | target_link_libraries(app_name, ${EXTRA_LIBS}) 50 | 51 | We can also add `#cmakedefine USE_FOO` to `version.h.in` to have a `#define` added if the option is enabled 52 | 53 | ###Generated files 54 | 55 | Generate `file.h` by running `FooCmd`: 56 | 57 | add_custom_command ( 58 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/file.h 59 | COMMAND FooCmd args 60 | DEPENDS FooCmd 61 | ) 62 | 63 | If `FooCmd` is created by `cmake`, then we can make the `custom_command` `DEPEND` on it 64 | 65 | Add generated `file.h` to a library: 66 | 67 | include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) 68 | add_library(FooLib, ${CMAKE_CURRENT_BINARY_DIR}/file.h) 69 | 70 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.2.2) 2 | project (cmake_test CXX) 3 | 4 | get_filename_component(CMAKE_SCRIPTS_DIR "${CMAKE_SOURCE_DIR}/scripts/cmake" ABSOLUTE) 5 | 6 | list (APPEND CMAKE_MODULE_PATH ${CMAKE_SCRIPTS_DIR}) 7 | include(all) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}) 10 | 11 | install_makefile() 12 | 13 | list (APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/projects") 14 | include(projects) 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cmake Project 2 | 3 | This is a small project I used to learn cmake while migrating an existing build system to [cmake](https://cmake.org/) 4 | 5 | ## Structure 6 | 7 | root 8 | | 9 | +---- foo # static library 10 | | | 11 | | +---- test # test for foo 12 | | 13 | +---- bar # static library, uses foo 14 | | | 15 | | +---- test # test for bar 16 | | 17 | +---- app # command line app, uses foo and bar 18 | | 19 | +---- gui # qt5 app, uses foo and bar 20 | 21 | ## Build 22 | 23 | - [cmake](https://cmake.org/) 24 | 25 | `mkdir build && cd build && cmake .. && make` 26 | 27 | ## Features 28 | 29 | ### version information 30 | 31 | Version information is generated and a version.cc file generated. 32 | 33 | The output of printing this information is similar to this: 34 | 35 | build variant : release 36 | build date : Feb 27 2018 10:56:11 37 | version : 083b581 38 | num_commits : 78 39 | branch : master 40 | ahead_by : 0 41 | num_untracked : 0 42 | user : steve 43 | hostname : ky-steve 44 | 45 | ### Tests 46 | 47 | Tests are run as part of the build process 48 | 49 | A failing test breaks the build 50 | 51 | All tests are run through valgrind 52 | 53 | A memory leak breaks the build 54 | 55 | **Files:** 56 | 57 | - `scripts/cmake/test.cmake`: cmake function which adds the test and configures it to run as part of the build 58 | 59 | ### Tagged binaries: 60 | 61 | Binaries can be installed to a specified destination as part of the build, and optionally have version information 62 | included in the filename 63 | 64 | Version information tagged onto a binary: 65 | 66 | - `branch` : branch name binary is built from 67 | - `commits` : number of commits in this branch 68 | - `dirty` : whether the branch is clean, or has uncommitted changes, untracked files etc 69 | 70 | **Files:** 71 | 72 | - `scripts/cmake/install.cmake`: cmake function which installs the binary, and tags it with version information (wip) 73 | 74 | ### Modules 75 | 76 | Related targets can be added to a "module", such that building the module builds all related targets 77 | 78 | eg: `foo` module contains `libfoo` static library and `foo_test`, tests which verify `libfoo` 79 | 80 | `foo` exists as a target in the makefiles. `make foo` builds all related targets. 81 | 82 | ## Build settings 83 | 84 | Top level `CMakeLists.txt` includes `all.cmake`, which pulls in all the custom cmake scripts. 85 | 86 | Additionally, `all.cmake` pulls in several scripts which configure the build 87 | 88 | - `scripts/cmake/ccache.cmake`: builds through `ccache` if it is found 89 | - `scripts/cmake/default_build.cmake`: sets the default build to `Debug` if it hasn't been specified 90 | - `scripts/cmake/compile_flags.cmake`: compiler flags set for the build 91 | - `scripts/cmake/dependencies.cmake`: pulls in 3rd party dependencies 92 | 93 | ## Quickstart 94 | 95 | There is a script `bootstrap` in the root directory which will set up the cmake files automatically. 96 | 97 | The bootstrap script will install 2 sets of makefiles, for debug and release builds. 98 | 99 | These are installed to `cmake_test/.build/debug` and `cmake_test/.build/release` respectively. 100 | 101 | The bootstrap script will also install makefiles into the source tree, allowing you to build from within the source tree. These makefiles delegate the build to the appropriate out-of-source makefiles. 102 | 103 | These in-source makefiles allow you to build either debug or release (debug is default), and to optionally list a target to build (default is all targets at-or-below the current location in the source tree) 104 | 105 | Examples 106 | 107 | $ make # builds all targets at-or-below the current location in the source tree in debug mode 108 | $ make release # builds all targets at-or-below the current location in the source tree in release mode 109 | $ make foo # builds the foo target in debug mode 110 | $ make foo release # builds the foo target in release mode 111 | 112 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | app 2 | app.[0-9]* 3 | version.cpp 4 | app*.[0-9]* 5 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | create_version("app" version.cpp) 2 | 3 | bin( 4 | NAME 5 | app 6 | 7 | SRCS 8 | main.cpp 9 | app.cpp 10 | version.cpp 11 | 12 | LIBS 13 | bar.lib 14 | ${LIB_BOOST_PROGRAM_OPTIONS} 15 | 16 | TAG 17 | ) 18 | 19 | # ensure that the version info is generated before we try compile version 20 | add_dependencies(app.bin version_info.app) 21 | -------------------------------------------------------------------------------- /app/app.cpp: -------------------------------------------------------------------------------- 1 | #include "app.h" 2 | #include 3 | #include "version.h" 4 | #include "foo/foo.h" 5 | #include "bar/bar.h" 6 | #include 7 | 8 | int App::run(int argc, char** argv) 9 | { 10 | namespace po = boost::program_options; 11 | 12 | po::options_description desc("allowed options"); 13 | desc.add_options() 14 | ("help,h" , "show this help message") 15 | ("version,v" , "print version information - then quits"); 16 | 17 | po::variables_map vm; 18 | po::store(po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(), vm); 19 | po::notify(vm); 20 | 21 | if (vm.count("help")) 22 | { 23 | std::cout << desc << std::endl; 24 | exit(0); 25 | } 26 | 27 | std::cout << 28 | "build variant : " << app::bin::variant() << '\n' << 29 | "build date : " << app::bin::date() << '\n' << 30 | "version : " << app::bin::version() << '\n' << 31 | "num_commits : " << app::bin::num_commits() << '\n' << 32 | "branch : " << app::bin::branch() << '\n' << 33 | "ahead_by : " << app::bin::ahead_by() << '\n' << 34 | "num_untracked : " << app::bin::num_untracked() << '\n' << 35 | "user : " << app::bin::user() << '\n' << 36 | "hostname : " << app::bin::hostname() << '\n'; 37 | 38 | if (vm.count("version")) 39 | exit(0); 40 | 41 | std::cout << "foo.size: " << foo().size() << '\n' 42 | << "bar: " << bar() << '\n'; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /app/app.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct App 4 | { 5 | int run(int argc, char** argv); 6 | }; -------------------------------------------------------------------------------- /app/main.cpp: -------------------------------------------------------------------------------- 1 | #include "app.h" 2 | 3 | int main(int argc, char** argv) 4 | { 5 | return App().run(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /app/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace app { namespace bin { 4 | 5 | const char* version(); 6 | const char* num_commits(); 7 | const char* date(); 8 | const char* variant(); 9 | const char* branch(); 10 | const char* ahead_by(); 11 | const char* num_untracked(); 12 | const char* user(); 13 | const char* hostname(); 14 | 15 | }} 16 | -------------------------------------------------------------------------------- /app2/.gitignore: -------------------------------------------------------------------------------- 1 | app2 2 | app2*.[0-9]* 3 | version.cpp 4 | -------------------------------------------------------------------------------- /app2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | create_version("app2" version.cpp) 2 | 3 | bin( 4 | NAME 5 | app2 6 | 7 | SRCS 8 | main.cpp 9 | app2.cpp 10 | version.cpp 11 | 12 | LIBS 13 | foo.lib 14 | ${LIB_BOOST_PROGRAM_OPTIONS} 15 | 16 | TAG 17 | ) 18 | 19 | # ensure that the version info is generated before we try compile version 20 | add_dependencies(app2.bin version_info.app2) 21 | -------------------------------------------------------------------------------- /app2/app2.cpp: -------------------------------------------------------------------------------- 1 | #include "app2.h" 2 | #include 3 | #include "version.h" 4 | #include "foo/foo.h" 5 | #include 6 | 7 | int App2::run(int argc, char** argv) 8 | { 9 | namespace po = boost::program_options; 10 | 11 | po::options_description desc("allowed options"); 12 | desc.add_options() 13 | ("help,h" , "show this help message") 14 | ("version,v" , "print version information - then quits"); 15 | 16 | po::variables_map vm; 17 | po::store(po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(), vm); 18 | po::notify(vm); 19 | 20 | if (vm.count("help")) 21 | { 22 | std::cout << desc << std::endl; 23 | exit(0); 24 | } 25 | 26 | std::cout << 27 | "build variant : " << app2::bin::variant() << '\n' << 28 | "build date : " << app2::bin::date() << '\n' << 29 | "version : " << app2::bin::version() << '\n' << 30 | "num_commits : " << app2::bin::num_commits() << '\n' << 31 | "branch : " << app2::bin::branch() << '\n' << 32 | "ahead_by : " << app2::bin::ahead_by() << '\n' << 33 | "num_untracked : " << app2::bin::num_untracked() << '\n' << 34 | "user : " << app2::bin::user() << '\n' << 35 | "hostname : " << app2::bin::hostname() << '\n'; 36 | 37 | if (vm.count("version")) 38 | exit(0); 39 | 40 | std::cout << "foo.size: " << foo().size() << '\n'; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /app2/app2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct App2 4 | { 5 | int run(int argc, char** argv); 6 | }; 7 | -------------------------------------------------------------------------------- /app2/main.cpp: -------------------------------------------------------------------------------- 1 | #include "app2.h" 2 | 3 | int main(int argc, char** argv) 4 | { 5 | return App2().run(argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /app2/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace app2 { namespace bin { 4 | 5 | const char* version(); 6 | const char* num_commits(); 7 | const char* date(); 8 | const char* variant(); 9 | const char* branch(); 10 | const char* ahead_by(); 11 | const char* num_untracked(); 12 | const char* user(); 13 | const char* hostname(); 14 | 15 | }} 16 | -------------------------------------------------------------------------------- /bar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | lib( 2 | NAME 3 | bar 4 | STATIC 5 | SRCS 6 | bar.cpp 7 | PROTO 8 | bar_msg.proto 9 | LIBS 10 | foo.lib 11 | ) 12 | 13 | add_subdirectory(test) 14 | -------------------------------------------------------------------------------- /bar/bar.cpp: -------------------------------------------------------------------------------- 1 | #include "bar.h" 2 | #include "bar_msg.pb.h" 3 | #include "foo/foo.h" 4 | 5 | std::string bar() 6 | { 7 | FooT f = foo(); 8 | 9 | BarMsg m; 10 | m.set_s(" bar"); 11 | m.mutable_f()->set_s(foo_msg().s()); 12 | 13 | std::string s; 14 | for (int i : f) 15 | s += std::to_string(i); 16 | 17 | return s + m.s() + " " + m.f().s(); 18 | } 19 | 20 | namespace 21 | { 22 | // protobuf does some stuff at static init time, and then leaks memory if we don't clean up behind it 23 | // this class forces the library to clean up at static destruction time 24 | struct ProtobufStaticShutdown 25 | { 26 | ~ProtobufStaticShutdown() 27 | { 28 | google::protobuf::ShutdownProtobufLibrary(); 29 | } 30 | } static_protobuf_shutdown; 31 | } 32 | -------------------------------------------------------------------------------- /bar/bar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | std::string bar(); 5 | -------------------------------------------------------------------------------- /bar/bar_msg.proto: -------------------------------------------------------------------------------- 1 | import "foo/foo_msg.proto"; 2 | 3 | message BarMsg 4 | { 5 | required string s = 1; 6 | required FooMsg f = 2; 7 | } -------------------------------------------------------------------------------- /bar/test/.gitignore: -------------------------------------------------------------------------------- 1 | bar_test 2 | -------------------------------------------------------------------------------- /bar/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | test( 2 | NAME bar_test 3 | MODULE bar 4 | SRCS main.cpp 5 | LIBS bar.lib 6 | ) 7 | -------------------------------------------------------------------------------- /bar/test/main.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_MAIN 2 | #include 3 | #include 4 | #include "bar/bar.h" 5 | 6 | BOOST_AUTO_TEST_CASE(bar_test) 7 | { 8 | std::cout << "testing bar\n"; 9 | 10 | BOOST_REQUIRE_EQUAL(bar(), "123 bar foo"); 11 | } 12 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | run_cmake() 4 | { 5 | if hash cmake3 2>/dev/null; then 6 | cmake3 "$@" 7 | else 8 | cmake "$@" 9 | fi 10 | } 11 | 12 | remove_cmake_files() 13 | { 14 | rm -rf CMakeCache.txt 15 | rm -rf CMakeFiles 16 | rm -rf CMakeScripts 17 | rm -rf Makefile 18 | rm -rf cmake_install.cmake 19 | rm -rf install_manifest.txt 20 | rm -rf CTestTestfile.cmake 21 | } 22 | 23 | bootstrap() 24 | { 25 | local variant=$1; shift 26 | 27 | echo "[ Generating ${variant} makefiles ]" 28 | 29 | mkdir -p .build/${variant} 30 | pushd .build/${variant} > /dev/null 31 | 32 | # remove any cached cmake variables that may exist, so we bootstrap a fresh environment 33 | remove_cmake_files 34 | 35 | # generate the build system 36 | run_cmake -Dbuild=${variant} -DCMAKE_EXPORT_COMPILE_COMMANDS=1 "$@" ../.. 37 | 38 | popd > /dev/null 39 | } 40 | 41 | bootstrap debug "$@" 42 | bootstrap release "$@" 43 | -------------------------------------------------------------------------------- /foo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | lib( 2 | NAME foo 3 | STATIC 4 | SRCS foo.cpp 5 | PROTO foo_msg.proto 6 | LIBS eastl.lib 7 | ) 8 | 9 | add_subdirectory(test) 10 | -------------------------------------------------------------------------------- /foo/foo.cpp: -------------------------------------------------------------------------------- 1 | #include "foo.h" 2 | 3 | FooT foo() 4 | { 5 | // uncomment to test that unused-local-typedefs are an error 6 | // byte = unsigned char; 7 | 8 | // uncomment to test that memory leaks break the build 9 | // purposeful memory leak to get valgrind to barf 10 | // const char* s = new char[5]; 11 | // (void)s; 12 | 13 | FooT f; 14 | 15 | // uncomment to test that failing tests break the build 16 | // return f; 17 | 18 | f.push_back(1); 19 | f.push_back(2); 20 | f.push_back(3); 21 | 22 | return f; 23 | } 24 | 25 | FooMsg foo_msg() 26 | { 27 | FooMsg msg; 28 | msg.set_s("foo"); 29 | return msg; 30 | } 31 | -------------------------------------------------------------------------------- /foo/foo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "foo_msg.pb.h" 4 | 5 | using FooT = eastl::fixed_vector; 6 | 7 | FooT foo(); 8 | 9 | FooMsg foo_msg(); 10 | 11 | -------------------------------------------------------------------------------- /foo/foo_msg.proto: -------------------------------------------------------------------------------- 1 | message FooMsg 2 | { 3 | required string s = 1; 4 | } -------------------------------------------------------------------------------- /foo/test/.gitignore: -------------------------------------------------------------------------------- 1 | foo_test 2 | -------------------------------------------------------------------------------- /foo/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | test( 2 | NAME foo_test 3 | MODULE foo 4 | SRCS main.cpp 5 | LIBS foo.lib 6 | ) 7 | -------------------------------------------------------------------------------- /foo/test/main.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_MAIN 2 | #include 3 | #include 4 | #include "foo/foo.h" 5 | 6 | BOOST_AUTO_TEST_CASE(foo_test) 7 | { 8 | std::cout << "testing foo\n"; 9 | 10 | FooT f = foo(); 11 | 12 | BOOST_REQUIRE_EQUAL(f.size(), 3); 13 | BOOST_REQUIRE_EQUAL(f[0], 1); 14 | BOOST_REQUIRE_EQUAL(f[1], 2); 15 | BOOST_REQUIRE_EQUAL(f[2], 3); 16 | } 17 | -------------------------------------------------------------------------------- /gui/.gitignore: -------------------------------------------------------------------------------- 1 | gui 2 | gui.*.[0-9]* 3 | -------------------------------------------------------------------------------- /gui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | qt_bin( 2 | NAME gui 3 | 4 | SRCS 5 | main.cpp 6 | 7 | MOC 8 | message.h 9 | 10 | RES 11 | resources.qrc 12 | 13 | LIBS bar_lib 14 | 15 | INSTALL TAG 16 | ) 17 | 18 | 19 | -------------------------------------------------------------------------------- /gui/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steve-lorimer/cmake_test/de2de7487933b41555f95e51f76b1b233a8db9fa/gui/icon.png -------------------------------------------------------------------------------- /gui/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "message.h" 7 | 8 | class App 9 | { 10 | public: 11 | App(int& argc, char** argv) 12 | : app(argc, argv) 13 | { } 14 | 15 | int exec() 16 | { 17 | QMainWindow* window = new QMainWindow; 18 | QWidget* widget = new QWidget; 19 | QVBoxLayout* layout = new QVBoxLayout; 20 | QPushButton* button = new QPushButton("go"); 21 | Message* msg = new Message; 22 | 23 | QIcon icon(":/res/icon.png"); 24 | app.setWindowIcon(icon); 25 | 26 | window->setCentralWidget(widget); 27 | widget->setLayout(layout); 28 | layout->addWidget(button); 29 | 30 | QObject::connect(button, &QPushButton::clicked, msg, &Message::onGo); 31 | 32 | window->show(); 33 | return app.exec(); 34 | } 35 | 36 | QApplication app; 37 | }; 38 | 39 | int main(int argc, char** argv) 40 | { 41 | return App(argc, argv).exec(); 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /gui/message.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "bar/bar.h" 5 | 6 | class Message : public QObject 7 | { 8 | Q_OBJECT 9 | public slots: 10 | void onGo() 11 | { 12 | QMessageBox( 13 | QMessageBox::Icon::Information, 14 | "bar output", 15 | QString::fromStdString(bar()), 16 | QMessageBox::StandardButton::NoButton, 17 | nullptr).exec(); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /gui/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /projects/project1.cmake: -------------------------------------------------------------------------------- 1 | add_subdirectory (3rd-party) 2 | add_subdirectory (foo) 3 | add_subdirectory (bar) 4 | add_subdirectory (app) 5 | add_subdirectory (app2) 6 | # add_subdirectory (gui) 7 | 8 | -------------------------------------------------------------------------------- /projects/project2.cmake: -------------------------------------------------------------------------------- 1 | add_subdirectory (3rd-party) 2 | add_subdirectory (foo) 3 | add_subdirectory (app2) 4 | -------------------------------------------------------------------------------- /projects/projects.cmake: -------------------------------------------------------------------------------- 1 | default_project(project1) 2 | 3 | add_project(project1) 4 | add_project(project2) 5 | -------------------------------------------------------------------------------- /scripts/cmake/.gitignore: -------------------------------------------------------------------------------- 1 | !makefile 2 | -------------------------------------------------------------------------------- /scripts/cmake/all.cmake: -------------------------------------------------------------------------------- 1 | include(include_guard) 2 | include_guard(__included_all) 3 | 4 | include(utils) 5 | include(message) 6 | include(settings) 7 | include(ccache) 8 | include(compile_flags) 9 | include(default_build) 10 | include(dependencies) 11 | include(version) 12 | include(build_config) 13 | 14 | include(project) 15 | include(module) 16 | include(find_lib) 17 | include(bin) 18 | include(lib) 19 | include(protoc) 20 | include(test) 21 | include(install) 22 | include(install_makefile) 23 | -------------------------------------------------------------------------------- /scripts/cmake/bin.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_bin) 2 | include(module) 3 | include(install) 4 | include(install_makefile) 5 | 6 | function(bin) 7 | # - creates a binary 8 | # 9 | # arguments: 10 | # NAME bin_name 11 | # MODULE module 12 | # SRCS sources* 13 | # PROTO protobuf files* 14 | # LIBS libraries* 15 | # TAG 16 | 17 | # parse arguments 18 | set(options TAG) 19 | set(values NAME MODULE RPATH SUFFIX PROTO_CPP_OUT PROTO_CWD) 20 | set(lists SRCS PROTO PROTO_INCLUDES LIBS) 21 | cmake_parse_arguments(ARG "${options}" "${values}" "${lists}" "${ARGN}") 22 | 23 | # if a target suffix hasn't been been specified, default to bin (tests build their binaries with a .test suffix) 24 | if(NOT ARG_SUFFIX) 25 | set(ARG_SUFFIX bin) 26 | endif() 27 | 28 | # all binaries have a suffix added, their name becomes a module to which they are added 29 | set(BIN_NAME ${ARG_NAME}.${ARG_SUFFIX}) 30 | 31 | if (DEBUG_CMAKE) 32 | message(STATUS "BIN: NAME=${ARG_NAME} SUFFIX=${ARG_SUFFIX} BIN_NAME=${BIN_NAME} MODULE=${ARG_MODULE} PROTO=${ARG_PROTO} PROTO_INCLUDES=${ARG_PROTO_INCLUDES} PROTO_CPP_OUT=${ARG_PROTO_CPP_OUT} PROTO_CWD=${ARG_PROTO_CWD} LIBS=${ARG_LIBS} TAG=${ARG_TAG} SRCS=${ARG_SRCS} RPATH=${ARG_RPATH}") 33 | endif() 34 | 35 | # generate protobuf files if required 36 | if (ARG_PROTO) 37 | protoc( 38 | PROTO_SRCS 39 | PROTO_HDRS 40 | PROTO_DIRS 41 | 42 | PROTO 43 | ${ARG_PROTO} 44 | 45 | INCLUDE 46 | ${ARG_PROTO_INCLUDES} 47 | 48 | CPP_OUT 49 | ${ARG_PROTO_CPP_OUT} 50 | 51 | CWD 52 | ${ARG_PROTO_CWD} 53 | ) 54 | 55 | set(PROTO_LIB ${LIB_PROTOBUF}) 56 | 57 | endif() 58 | 59 | if(NOT NO_GUI) 60 | # qt specific helpers 61 | if(ARG_MOC) 62 | qt5_wrap_cpp(ARG_MOC_OUT ${ARG_MOC}) 63 | endif() 64 | 65 | if(ARG_RES) 66 | qt5_add_resources(ARG_RES_OUT ${ARG_RES}) 67 | endif() 68 | 69 | if(ARG_UI) 70 | qt5_wrap_ui(ARG_UI_OUT ${ARG_UI}) 71 | endif() 72 | endif() 73 | 74 | add_executable(${BIN_NAME} 75 | ${ARG_SRCS} ${PROTO_SRCS} ${PROTO_HDRS} ${ARG_MOC_OUT} ${ARG_RES_OUT} ${ARG_UI_OUT} 76 | ) 77 | 78 | if (ARG_LIBS) 79 | clean_link_libs(ARG_LIBS_OUT "${ARG_LIBS}") 80 | target_link_libraries(${BIN_NAME} ${ARG_LIBS_OUT}) 81 | endif() 82 | 83 | target_link_libraries(${BIN_NAME} 84 | ${PROTO_LIB} 85 | pthread 86 | rt 87 | ) 88 | 89 | # don't link tcmalloc in debug builds, it can hide memory leaks from valgrind 90 | if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") 91 | target_link_libraries(${BIN_NAME} 92 | ${LIB_TCMALLOC} 93 | ) 94 | endif() 95 | 96 | if(ARG_RPATH) 97 | set_target_properties(${BIN_NAME} PROPERTIES LINK_FLAGS "-Wl,-rpath,${ARG_RPATH}") 98 | endif() 99 | 100 | # add bin as a dependency of module, so 'make module' will build the bin 101 | add_to_module( 102 | ${ARG_NAME} 103 | ${BIN_NAME} 104 | ) 105 | 106 | # if parent module has been specified, add this module to the parent 107 | if(ARG_MODULE) 108 | add_to_module( 109 | ${ARG_MODULE} 110 | ${ARG_NAME} 111 | ) 112 | endif() 113 | 114 | # install the binary, and optionally a tagged binary, if requested 115 | if(ARG_TAG) 116 | set(TAG "TAG") 117 | endif() 118 | 119 | install( 120 | FILE 121 | ${CMAKE_CURRENT_BINARY_DIR}/${BIN_NAME} 122 | 123 | MODULE 124 | ${ARG_NAME} 125 | 126 | DEST 127 | ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_NAME} 128 | 129 | ${TAG} 130 | ) 131 | 132 | install_makefile() 133 | 134 | add_dependencies(${BIN_NAME} build_config) 135 | endfunction() 136 | -------------------------------------------------------------------------------- /scripts/cmake/build_config.cmake: -------------------------------------------------------------------------------- 1 | add_custom_target( 2 | build_config 3 | ALL 4 | DEPENDS 5 | build_config.command 6 | ) 7 | 8 | add_custom_command( 9 | OUTPUT 10 | build_config.command 11 | COMMAND 12 | ${CMAKE_COMMAND} 13 | -DCMAKE_MODULE_PATH=${CMAKE_SCRIPTS_DIR} 14 | -DCMAKE_SCRIPTS_DIR=${CMAKE_SCRIPTS_DIR} 15 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 16 | -DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID} 17 | -P ${CMAKE_SCRIPTS_DIR}/print_build_config.cmake 18 | ) 19 | -------------------------------------------------------------------------------- /scripts/cmake/ccache.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_ccache) 2 | include(message) 3 | 4 | # if ccache is found on the path, build through it 5 | 6 | find_program(CCACHE_FOUND ccache) 7 | 8 | if (NO_CCACHE) 9 | return() 10 | endif() 11 | 12 | if (CCACHE_FOUND) 13 | 14 | message (STATUS "Using ccache") 15 | 16 | set_property( 17 | GLOBAL PROPERTY 18 | RULE_LAUNCH_COMPILE 19 | ccache 20 | ) 21 | 22 | set_property( 23 | GLOBAL PROPERTY 24 | RULE_LAUNCH_LINK 25 | ccache 26 | ) 27 | else() 28 | 29 | message (INFO "ccache not found - consider installing it for faster incremental builds") 30 | 31 | endif() 32 | -------------------------------------------------------------------------------- /scripts/cmake/compile_flags.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_compile_flags) 2 | include(default_build) 3 | 4 | # helper macros for setting flags 5 | 6 | macro(add_flag FLAG) 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}" ) 8 | endmacro() 9 | 10 | macro(add_debug_flag FLAG) 11 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}" ) 12 | endmacro() 13 | 14 | macro(add_release_flag FLAG) 15 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAG}" ) 16 | endmacro() 17 | 18 | macro(add_linker_flag FLAG) 19 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}" ) 20 | endmacro() 21 | 22 | macro(add_debug_linker_flag FLAG) 23 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FLAG}" ) 24 | endmacro() 25 | 26 | macro(add_release_linker_flag FLAG) 27 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${FLAG}" ) 28 | endmacro() 29 | 30 | # reset all flags before adding our own, so we don't inadvertently get something cmake sets by default 31 | 32 | set(CMAKE_CXX_FLAGS "") 33 | set(CMAKE_CXX_FLAGS_DEBUG "") 34 | set(CMAKE_CXX_FLAGS_RELEASE "") 35 | set(CMAKE_EXE_LINKER_FLAGS "") 36 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "") 37 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "") 38 | 39 | ########################################################################## 40 | # global 41 | ########################################################################## 42 | 43 | add_flag (-Werror) 44 | add_flag (-Wall) 45 | add_flag (-Wextra) 46 | add_flag (-m64) 47 | add_flag (-msse2) 48 | add_flag (-msse4.2) 49 | add_flag (-mfpmath=sse) 50 | add_flag (-ftemplate-depth-128) 51 | add_flag (-Wno-unused-parameter) 52 | add_flag (-Wno-strict-aliasing) # libev breaks strict-aliasing rules 53 | add_flag (-pthread) 54 | add_flag (-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG) # enable nanosecond resolution 55 | add_linker_flag(-m64) 56 | add_linker_flag(-rdynamic) # required for backtrace 57 | 58 | # TODO: libtins leaks memory 59 | # if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.1) 60 | # add_flag (-fsanitize=leak) 61 | # add_flag (-fno-omit-frame-pointer) 62 | # endif() 63 | 64 | ########################################################################## 65 | # debug mode 66 | ########################################################################## 67 | 68 | add_debug_flag(-g) 69 | add_debug_flag(-ggdb3) 70 | add_debug_flag(-O0) 71 | add_debug_flag(-fno-inline) 72 | 73 | ########################################################################## 74 | # release mode 75 | ########################################################################## 76 | 77 | add_release_flag(-ggdb2) 78 | add_release_flag(-DNDEBUG) 79 | add_release_flag(-O3) 80 | add_release_flag(-funroll-loops) 81 | add_release_flag(-fdevirtualize) 82 | add_release_flag(-finline-functions) 83 | add_release_flag(-fno-builtin-malloc) 84 | add_release_flag(-fno-builtin-calloc) 85 | add_release_flag(-fno-builtin-realloc) 86 | add_release_flag(-fno-builtin-free) 87 | 88 | ########################################################################## 89 | 90 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 91 | message(STATUS "${CMAKE_BUILD_TYPE} build: CXX_FLAGS:${CMAKE_CXX_FLAGS}${CMAKE_CXX_FLAGS_DEBUG}") 92 | message(STATUS "${CMAKE_BUILD_TYPE} build: LINKER_FLAGS:${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_DEBUG}") 93 | else() 94 | message(STATUS "${CMAKE_BUILD_TYPE} build: CXX_FLAGS:${CMAKE_CXX_FLAGS}${CMAKE_CXX_FLAGS_RELEASE}") 95 | message(STATUS "${CMAKE_BUILD_TYPE} build: LINKER_FLAGS:${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 96 | endif() 97 | 98 | ############### CFLAGS ############# 99 | 100 | macro(add_cflag FLAG) 101 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}" ) 102 | endmacro() 103 | 104 | macro(add_debug_cflag FLAG) 105 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}" ) 106 | endmacro() 107 | 108 | macro(add_release_cflag FLAG) 109 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${FLAG}" ) 110 | endmacro() 111 | 112 | set(CMAKE_C_FLAGS "") 113 | set(CMAKE_C_FLAGS_DEBUG "") 114 | set(CMAKE_C_FLAGS_RELEASE "") 115 | 116 | ########################################################################## 117 | # global 118 | ########################################################################## 119 | 120 | add_cflag (-Werror) 121 | add_cflag (-Wall) 122 | add_cflag (-Wextra) 123 | add_cflag (-m64) 124 | add_cflag (-msse2) 125 | add_cflag (-msse4.2) 126 | add_cflag (-mfpmath=sse) 127 | add_cflag (-Wno-unused-parameter) 128 | add_cflag (-Wno-strict-aliasing) # libev breaks strict-aliasing rules 129 | add_cflag (-pthread) 130 | 131 | ########################################################################## 132 | # debug mode 133 | ########################################################################## 134 | 135 | add_debug_cflag(-g) 136 | add_debug_cflag(-ggdb3) 137 | add_debug_cflag(-O0) 138 | add_debug_cflag(-fno-inline) 139 | 140 | ########################################################################## 141 | # release mode 142 | ########################################################################## 143 | 144 | add_release_cflag(-ggdb2) 145 | add_release_cflag(-DNDEBUG) 146 | add_release_cflag(-O3) 147 | add_release_cflag(-funroll-loops) 148 | add_release_cflag(-fdevirtualize) 149 | add_release_cflag(-finline-functions) 150 | add_release_cflag(-fno-builtin-malloc) 151 | add_release_cflag(-fno-builtin-calloc) 152 | add_release_cflag(-fno-builtin-realloc) 153 | add_release_cflag(-fno-builtin-free) 154 | 155 | ########################################################################## 156 | # compiler-specific flags 157 | ########################################################################## 158 | 159 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 160 | 161 | # this is not enabled in clang by default 162 | add_flag(-fsized-deallocation) 163 | 164 | # TODO: fix these please 165 | add_flag(-Wno-unused-function) 166 | add_flag(-Wno-unused-const-variable) 167 | add_flag(-Wno-unused-private-field) 168 | add_flag(-Wno-mismatched-tags) 169 | add_flag(-Wno-missing-braces) 170 | add_flag(-Wno-sometimes-uninitialized) 171 | add_flag(-Wno-return-stack-address) 172 | add_flag(-Wno-overloaded-virtual) 173 | 174 | add_cflag(-Wno-unused-function) 175 | add_cflag(-Wno-unused-const-variable) 176 | add_cflag(-Wno-unused-private-field) 177 | add_cflag(-Wno-mismatched-tags) 178 | add_cflag(-Wno-missing-braces) 179 | add_cflag(-Wno-sometimes-uninitialized) 180 | add_cflag(-Wno-return-stack-address) 181 | add_cflag(-Wno-overloaded-virtual) 182 | 183 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 184 | 185 | # gcc doesn't do well with boost::optional 186 | add_flag(-Wno-maybe-uninitialized) 187 | add_cflag(-Wno-maybe-uninitialized) 188 | if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.3) 189 | add_flag(-Wno-misleading-indentation) 190 | add_flag(-Wduplicated-cond) 191 | add_cflag(-Wno-misleading-indentation) 192 | add_cflag(-Wduplicated-cond) 193 | endif() 194 | 195 | # this is a gnu extension - used in boost float128... 196 | add_flag(-fext-numeric-literals) 197 | 198 | 199 | endif() 200 | 201 | -------------------------------------------------------------------------------- /scripts/cmake/create_version.cmake: -------------------------------------------------------------------------------- 1 | include(message) 2 | 3 | if(NOT CMAKE_SCRIPTS_DIR) 4 | message(FATAL_ERROR "no cmake scripts dir specified") 5 | endif() 6 | if(NOT CMAKE_BUILD_TYPE) 7 | message(FATAL_ERROR "no build type specified") 8 | endif() 9 | if(NOT PURPOSE) 10 | message(FATAL_ERROR "no purpose specified") 11 | endif() 12 | if(NOT DEST_FILE) 13 | message(FATAL_ERROR "no destination file specified") 14 | endif() 15 | 16 | if(WIN32) 17 | set(COUNT_LINES find /c /v "") 18 | else() 19 | set(COUNT_LINES wc -l) 20 | endif() 21 | 22 | if (CMAKE_BUILD_TYPE STREQUAL "Debug") 23 | 24 | set(VERSION "skipped due to debug build") 25 | set(NUM_COMMITS "skipped due to debug build") 26 | set(BRANCH "skipped due to debug build") 27 | set(AHEAD_BY "skipped due to debug build") 28 | set(NUM_UNTRACKED "skipped due to debug build") 29 | set(USER "skipped due to debug build") 30 | set(HOSTNAME "skipped due to debug build") 31 | 32 | else() 33 | 34 | # git version 35 | execute_process( 36 | OUTPUT_VARIABLE VERSION 37 | COMMAND git rev-parse --short HEAD 38 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 39 | OUTPUT_STRIP_TRAILING_WHITESPACE 40 | ) 41 | 42 | # number of commits 43 | execute_process( 44 | OUTPUT_VARIABLE NUM_COMMITS 45 | COMMAND git rev-list HEAD 46 | COMMAND ${COUNT_LINES} 47 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 48 | OUTPUT_STRIP_TRAILING_WHITESPACE 49 | ) 50 | 51 | # branch 52 | execute_process( 53 | OUTPUT_VARIABLE BRANCH 54 | COMMAND git rev-parse --abbrev-ref HEAD 55 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 56 | OUTPUT_STRIP_TRAILING_WHITESPACE 57 | ) 58 | 59 | # ahead by 60 | execute_process( 61 | OUTPUT_VARIABLE AHEAD_BY 62 | COMMAND git log --oneline origin/${BRANCH}..${BRANCH} 63 | COMMAND ${COUNT_LINES} 64 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 65 | OUTPUT_STRIP_TRAILING_WHITESPACE 66 | ) 67 | 68 | # num untracked 69 | execute_process( 70 | OUTPUT_VARIABLE NUM_UNTRACKED 71 | COMMAND git ls-files --exclude-standard --others --full-name -- . 72 | COMMAND ${COUNT_LINES} 73 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 74 | OUTPUT_STRIP_TRAILING_WHITESPACE 75 | ) 76 | 77 | # user 78 | execute_process( 79 | OUTPUT_VARIABLE USER 80 | COMMAND whoami 81 | OUTPUT_STRIP_TRAILING_WHITESPACE 82 | ) 83 | 84 | # hostname 85 | execute_process( 86 | OUTPUT_VARIABLE HOSTNAME 87 | COMMAND hostname 88 | OUTPUT_STRIP_TRAILING_WHITESPACE 89 | ) 90 | endif() 91 | 92 | # build variant 93 | string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_VARIANT) 94 | 95 | # get filename component for include file 96 | get_filename_component(FILENAME ${DEST_FILE} NAME_WE) 97 | 98 | set(TMP_OUTPUT_FILE ${CMAKE_BINARY_DIR}/version.cc.tmp) 99 | 100 | # create temporary version file 101 | configure_file( 102 | ${CMAKE_SCRIPTS_DIR}/version.cc.in 103 | ${TMP_OUTPUT_FILE} 104 | ) 105 | 106 | # compare with the real version file 107 | execute_process( 108 | COMMAND 109 | ${CMAKE_COMMAND} -E compare_files 110 | ${TMP_OUTPUT_FILE} 111 | ${DEST_FILE} 112 | RESULT_VARIABLE 113 | VERSION_NEEDS_UPDATING 114 | 115 | OUTPUT_QUIET 116 | ERROR_QUIET 117 | ) 118 | 119 | # update the real version file if necessary 120 | if(VERSION_NEEDS_UPDATING) 121 | execute_process( 122 | COMMAND 123 | ${CMAKE_COMMAND} -E copy 124 | ${TMP_OUTPUT_FILE} 125 | ${DEST_FILE} 126 | ) 127 | set(UPDATED "(updated)") 128 | endif() 129 | 130 | message(STATUS "${PURPOSE}: branch=${BRANCH} version=${VERSION} commits=${NUM_COMMITS} ahead_by=${AHEAD_BY} untracked=${NUM_UNTRACKED} variant=${BUILD_VARIANT} ${UPDATED}") 131 | -------------------------------------------------------------------------------- /scripts/cmake/default_build.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_default_build) 2 | 3 | # allow users to specify build variant several ways: 4 | # 5 | # all of the following are equivalent: 6 | # 7 | # cmake -Dbuild=debug .. 8 | # cmake -DBUILD=debug .. 9 | # cmake -DVARIANT=debug .. 10 | # cmake -DCMAKE_BUILD_TYPE=debug .. 11 | 12 | if(variant) 13 | set(CMAKE_BUILD_TYPE ${variant}) 14 | endif() 15 | 16 | if(build) 17 | set(CMAKE_BUILD_TYPE ${build}) 18 | endif() 19 | 20 | if(Variant) 21 | set(CMAKE_BUILD_TYPE ${Variant}) 22 | endif() 23 | 24 | if(Build) 25 | set(CMAKE_BUILD_TYPE ${Build}) 26 | endif() 27 | 28 | if(VARIANT) 29 | set(CMAKE_BUILD_TYPE ${VARIANT}) 30 | endif() 31 | 32 | if(BUILD) 33 | set(CMAKE_BUILD_TYPE ${BUILD}) 34 | endif() 35 | 36 | # if no build variant has been specified, default to debug 37 | if (NOT CMAKE_BUILD_TYPE) 38 | set(CMAKE_BUILD_TYPE "Debug") 39 | endif() 40 | 41 | # allow debug/release to be specified in any case 42 | string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_VARIANT) 43 | 44 | # set the requested build variant 45 | if (BUILD_VARIANT STREQUAL "DEBUG") 46 | set(CMAKE_BUILD_TYPE "Debug") 47 | elseif (BUILD_VARIANT STREQUAL "RELEASE") 48 | set(CMAKE_BUILD_TYPE "Release") 49 | elseif (BUILD_VARIANT STREQUAL "RELWITHDEBINFO") 50 | set(CMAKE_BUILD_TYPE "Release") 51 | elseif (BUILD_VARIANT STREQUAL "MINSIZEREL") 52 | set(CMAKE_BUILD_TYPE "Release") 53 | else() 54 | message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}") 55 | endif() 56 | -------------------------------------------------------------------------------- /scripts/cmake/dependencies.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_dependencies) 2 | include(find_lib) 3 | 4 | # static libraries 5 | find_static_lib(boost_unit_test_framework LIB_BOOST_UNIT_TEST_FRAMEWORK) 6 | find_static_lib(boost_program_options LIB_BOOST_PROGRAM_OPTIONS) 7 | find_static_lib(boost_date_time LIB_BOOST_DATE_TIME) 8 | find_static_lib(boost_filesystem LIB_BOOST_FILESYSTEM) 9 | find_static_lib(boost_thread LIB_BOOST_THREAD) 10 | find_static_lib(boost_system LIB_BOOST_SYSTEM) 11 | find_static_lib(boost_regex LIB_BOOST_REGEX) 12 | find_static_lib(boost_iostreams LIB_BOOST_IOSTREAMS) 13 | find_static_lib(protobuf LIB_PROTOBUF) 14 | find_static_lib(tcmalloc_minimal LIB_TCMALLOC) 15 | 16 | # shared libraries 17 | find_shared_lib(pcap LIB_PCAP) 18 | find_shared_lib(zmq LIB_ZMQ) 19 | 20 | # third_party libs built in tree 21 | use_in_tree_lib(cpp-netlib LIB_CPPNET) 22 | use_in_tree_lib(eastl LIB_EASTL) 23 | use_in_tree_lib(libev LIB_EV) 24 | use_in_tree_lib(gmock LIB_GMOCK) 25 | use_in_tree_lib(gtest LIB_GTEST) 26 | use_in_tree_lib(libtins LIB_TINS) 27 | use_in_tree_lib(zlib LIB_Z) 28 | 29 | # optional libraries 30 | find_shared_lib(pq LIB_PQ OPTIONAL) 31 | find_shared_lib(pqxx LIB_PQXX OPTIONAL) 32 | find_gcc_lib (quadmath LIB_QUADMATH) 33 | 34 | -------------------------------------------------------------------------------- /scripts/cmake/find_lib.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_find_lib) 2 | 3 | function(do_find_lib LIB_NAME SUFFIX OUT) 4 | # - searches for a library with a given suffix, optionally in paths 5 | # 6 | # arguments: 7 | # LIB_NAME lib_name 8 | # SUFFIX suffix 9 | # OUT output variable 10 | # PATHS search paths* 11 | 12 | # parse arguments 13 | set(options OPTIONAL) 14 | set(values) 15 | set(lists PATHS) 16 | cmake_parse_arguments(FIND "${options}" "${values}" "${lists}" "${ARGN}") 17 | 18 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${SUFFIX}) 19 | 20 | find_library( 21 | FOUND_${LIB_NAME}${SUFFIX} 22 | ${LIB_NAME} 23 | PATHS 24 | ${FIND_PATHS} 25 | ) 26 | 27 | if (FOUND_${LIB_NAME}${SUFFIX}) 28 | get_filename_component(ABS_FILE ${FOUND_${LIB_NAME}${SUFFIX}} ABSOLUTE) 29 | message(STATUS "Found library ${ABS_FILE}") 30 | elseif(NOT ${FIND_OPTIONAL}) 31 | message(SEND_ERROR "Unable to find library ${LIB_NAME}") 32 | endif() 33 | 34 | set(${OUT} ${ABS_FILE} PARENT_SCOPE) 35 | 36 | endfunction() 37 | 38 | ##################################################################################### 39 | 40 | function(find_static_lib LIB_NAME OUT) 41 | # arguments: 42 | # LIB_NAME lib_name 43 | # OUT output variable 44 | # PATHS search paths* 45 | 46 | # parse arguments 47 | set(options OPTIONAL) 48 | set(values) 49 | set(lists PATHS) 50 | cmake_parse_arguments(FIND "${options}" "${values}" "${lists}" "${ARGN}") 51 | 52 | if(FIND_OPTIONAL) 53 | set(OPTIONAL "OPTIONAL") 54 | endif() 55 | 56 | do_find_lib( 57 | ${LIB_NAME} 58 | ${CMAKE_STATIC_LIBRARY_SUFFIX} 59 | FOUND 60 | PATHS 61 | ${FIND_PATHS} 62 | ${OPTIONAL}) 63 | 64 | set(${OUT} ${FOUND} PARENT_SCOPE) 65 | 66 | endfunction() 67 | 68 | ##################################################################################### 69 | 70 | function(find_shared_lib LIB_NAME OUT) 71 | # arguments: 72 | # LIB_NAME lib_name 73 | # OUT output variable 74 | # PATHS search paths* 75 | 76 | # parse arguments 77 | set(options OPTIONAL) 78 | set(values) 79 | set(lists PATHS) 80 | cmake_parse_arguments(FIND "${options}" "${values}" "${lists}" "${ARGN}") 81 | 82 | if(FIND_OPTIONAL) 83 | set(OPTIONAL "OPTIONAL") 84 | endif() 85 | 86 | do_find_lib( 87 | ${LIB_NAME} 88 | ${CMAKE_SHARED_LIBRARY_SUFFIX} 89 | FOUND 90 | PATHS 91 | ${FIND_PATHS} 92 | ${OPTIONAL}) 93 | 94 | set(${OUT} ${FOUND} PARENT_SCOPE) 95 | 96 | endfunction() 97 | 98 | ##################################################################################### 99 | # Finds a gcc-specific library (e.g. quadmath, asan, lsan etc) 100 | # Location will depend on the compiler version in use 101 | # This allows portability across dev and build machines with different gcc compilers 102 | ##################################################################################### 103 | macro(find_gcc_lib LIB_NAME OUT) 104 | # arguments: 105 | # LIB_NAME library name within compiler tree 106 | # OUT output variable 107 | 108 | if (CMAKE_COMPILER_IS_GNUCC) 109 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-libgcc-file-name OUTPUT_VARIABLE LIB_GCC_FILE) 110 | get_filename_component(LIB_GCC_DIR ${LIB_GCC_FILE} DIRECTORY) 111 | find_static_lib(${LIB_NAME} ${OUT} OPTIONAL PATHS ${LIB_GCC_DIR}) 112 | if (NOT ${OUT}) 113 | find_shared_lib(${LIB_NAME} ${OUT} OPTIONAL PATHS ${LIB_GCC_DIR}) 114 | endif() 115 | endif() 116 | endmacro() 117 | 118 | ##################################################################################### 119 | # Alias the library to the in-tree version 120 | # This will allow us to easily switch to out-of-tree versions for faster builds 121 | ##################################################################################### 122 | function(use_in_tree_lib LIB_NAME OUT) 123 | # arguments: 124 | # LIB_NAME library name within viv source tree 125 | # OUT output variable 126 | 127 | set(FULL_LIB_NAME ${LIB_NAME}.lib) 128 | message(STATUS "Using ${OUT}=${FULL_LIB_NAME}") 129 | 130 | set(${OUT} ${FULL_LIB_NAME} PARENT_SCOPE) 131 | 132 | endfunction() 133 | 134 | -------------------------------------------------------------------------------- /scripts/cmake/include_guard.cmake: -------------------------------------------------------------------------------- 1 | # helper to prevent scripts being included multiple times 2 | macro(include_guard VAR) 3 | if(${VAR}) 4 | return() 5 | endif() 6 | set(${VAR} YES) 7 | endmacro() -------------------------------------------------------------------------------- /scripts/cmake/install.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_install) 2 | include(module) 3 | include(version) 4 | include(message) 5 | 6 | function(install) 7 | # arguments: 8 | # FILE file 9 | # MODULE module 10 | # DEST destination 11 | # DEPS dependencies* 12 | # TAG 13 | 14 | # parse arguments 15 | set(options TAG) 16 | set(values FILE MODULE DEST) 17 | set(lists DEPS) 18 | cmake_parse_arguments(ARG "${options}" "${values}" "${lists}" "${ARGN}") 19 | 20 | if(DEBUG_CMAKE) 21 | message(STATUS "INSTALL: FILE=${ARG_FILE} MODULE=${ARG_MODULE} DEST=${ARG_DEST} TAG=${ARG_TAG} DEPS=${ARG_DEPS}") 22 | endif() 23 | 24 | get_filename_component(SRC_FILENAME ${ARG_FILE} NAME_WE) 25 | get_filename_component(ABS_SRC_FILE ${ARG_FILE} ABSOLUTE) 26 | 27 | get_filename_component(DST_FILENAME ${ARG_DEST} NAME_WE) 28 | get_filename_component(INSTALL_DIR ${ARG_DEST} DIRECTORY) 29 | 30 | # sanity check - does a folder already exist with the same name as the destination file? 31 | if(IS_DIRECTORY ${ARG_DEST}) 32 | message(FATAL_ERROR "Unable to install target with the same name as preexisting directory ${ARG_DEST}") 33 | endif() 34 | 35 | # install the file 36 | add_custom_command( 37 | OUTPUT 38 | ${ARG_DEST} 39 | 40 | COMMAND 41 | ${CMAKE_COMMAND} -E make_directory ${INSTALL_DIR} 42 | 43 | COMMAND 44 | ${CMAKE_COMMAND} -E create_symlink ${ABS_SRC_FILE} ${ARG_DEST} 45 | 46 | COMMENT 47 | "Installing ${SRC_FILENAME}" 48 | 49 | DEPENDS 50 | ${ARG_FILE} 51 | ) 52 | 53 | string(REPLACE ${CMAKE_SOURCE_DIR}/ "" FILE_STEM ${ARG_DEST}) 54 | string(REPLACE "/" "." INSTALL_TARGET ${FILE_STEM}) 55 | 56 | # variable which hold a list of installed targets (normal installed target and tagged installed target) 57 | set(INSTALLED_TARGETS ${ARG_DEST}) 58 | 59 | # install a tagged file if requested 60 | if(ARG_TAG) 61 | 62 | add_custom_target( 63 | ${INSTALL_TARGET}.tag 64 | 65 | ALL 66 | 67 | COMMAND 68 | ${CMAKE_COMMAND} 69 | -DSRC_FILE=${ABS_SRC_FILE} 70 | -DDEST_FILE=${ARG_DEST} 71 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 72 | -DCMAKE_MODULE_PATH=${CMAKE_SCRIPTS_DIR} 73 | -DINSTALL_TAGGED_AS_COPY=${INSTALL_TAGGED_AS_COPY} 74 | -P ${CMAKE_SCRIPTS_DIR}/install_tagged.cmake 75 | 76 | DEPENDS 77 | ${ARG_FILE} 78 | ) 79 | 80 | set(INSTALLED_TARGETS "${INSTALLED_TARGETS} ${INSTALL_TARGET}.tag") 81 | endif() 82 | 83 | # make clean will remove the installed file 84 | set_directory_properties( 85 | PROPERTIES 86 | ADDITIONAL_MAKE_CLEAN_FILES 87 | ${INSTALL_DIR}/${ABS_SRC_FILE}.[0-9]*) 88 | 89 | # required for add_custom_target 90 | separate_arguments(INSTALLED_TARGETS) 91 | 92 | # add an install target to ALL 93 | add_custom_target(${INSTALL_TARGET}.install 94 | ALL 95 | DEPENDS 96 | ${INSTALLED_TARGETS} 97 | ) 98 | 99 | if(ARG_DEPS) 100 | add_dependencies(${INSTALL_TARGET}.install ${ARG_DEPS}) 101 | endif() 102 | 103 | # if we're installing to a location inside the source tree, ensure the installed binaries are 104 | # in a local .gitignore file 105 | string(FIND ${INSTALL_DIR} ${CMAKE_SOURCE_DIR} INSTALL_IS_IN_SRC) 106 | 107 | if(INSTALL_IS_IN_SRC GREATER -1) 108 | set(GITIGNORE_FILENAME ${INSTALL_DIR}/.gitignore) 109 | 110 | if(EXISTS ${GITIGNORE_FILENAME}) 111 | file(READ ${GITIGNORE_FILENAME} GITIGNORE) 112 | endif() 113 | 114 | # search for the installed filename in the gitignore 115 | if(GITIGNORE) 116 | string(FIND ${GITIGNORE} ${DST_FILENAME} INSTALL_IS_IN_GITIGNORE) 117 | endif() 118 | 119 | if(NOT DEFINED INSTALL_IS_IN_GITIGNORE OR NOT INSTALL_IS_IN_GITIGNORE GREATER -1) 120 | file(APPEND ${GITIGNORE_FILENAME} "${DST_FILENAME}\n") 121 | endif() 122 | 123 | # if we're also installing tagged binaries, make sure a globbing pattern exists in gitignore too 124 | if (ARG_TAG) 125 | set(TAG_PATTERN "${DST_FILENAME}*.[0-9]*") 126 | 127 | # search for the destination filename in the gitignore 128 | if(GITIGNORE) 129 | string(FIND ${GITIGNORE} ${TAG_PATTERN} INSTALL_TAG_IS_IN_GITIGNORE) 130 | endif() 131 | 132 | if(NOT DEFINED INSTALL_TAG_IS_IN_GITIGNORE OR NOT INSTALL_TAG_IS_IN_GITIGNORE GREATER -1) 133 | file(APPEND ${GITIGNORE_FILENAME} "${TAG_PATTERN}\n") 134 | endif() 135 | endif() 136 | endif() 137 | 138 | # if this is part of a module, add the install step to it 139 | if(ARG_MODULE) 140 | add_to_module( 141 | ${ARG_MODULE} 142 | ${INSTALL_TARGET}.install 143 | ) 144 | endif() 145 | 146 | endfunction() 147 | -------------------------------------------------------------------------------- /scripts/cmake/install_makefile.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_install_makefile) 2 | 3 | # copy the makefile into the source tree to mimic in-source builds 4 | function(install_makefile) 5 | if(NOT DISABLE_IN_SOURCE_BUILD) 6 | configure_file(${CMAKE_SCRIPTS_DIR}/makefile ${CMAKE_CURRENT_SOURCE_DIR}/makefile COPYONLY) 7 | endif() 8 | endfunction() 9 | -------------------------------------------------------------------------------- /scripts/cmake/install_tagged.cmake: -------------------------------------------------------------------------------- 1 | include(message) 2 | 3 | if(NOT SRC_FILE) 4 | message(FATAL_ERROR "no input file specified") 5 | endif() 6 | 7 | if(NOT EXISTS ${SRC_FILE}) 8 | message(FATAL_ERROR "input file ${SRC_FILE} doesn't exist") 9 | endif() 10 | 11 | if(NOT DEST_FILE) 12 | message(FATAL_ERROR "no output file specified") 13 | endif() 14 | 15 | get_filename_component(INSTALL_DIR ${DEST_FILE} DIRECTORY) 16 | 17 | # number of commits 18 | execute_process( 19 | OUTPUT_VARIABLE COMMITS 20 | COMMAND git rev-list HEAD 21 | COMMAND wc -l 22 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 23 | OUTPUT_STRIP_TRAILING_WHITESPACE 24 | ) 25 | 26 | # branch name 27 | execute_process( 28 | OUTPUT_VARIABLE BRANCH 29 | COMMAND git rev-parse --abbrev-ref HEAD 30 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 31 | OUTPUT_STRIP_TRAILING_WHITESPACE 32 | ) 33 | 34 | # dirty tag 35 | execute_process( 36 | OUTPUT_VARIABLE DIRTY 37 | COMMAND git diff --shortstat 38 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 39 | OUTPUT_STRIP_TRAILING_WHITESPACE 40 | ) 41 | 42 | # build variant 43 | string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD) 44 | 45 | if(BRANCH STREQUAL "master") 46 | unset(BRANCH) 47 | else() 48 | set(BRANCH .${BRANCH}) 49 | endif() 50 | 51 | if(BUILD STREQUAL "release") 52 | unset(BUILD) 53 | else() 54 | set(BUILD .${BUILD}) 55 | endif() 56 | 57 | if(DIRTY) 58 | set(DIRTY .dirty) 59 | endif() 60 | 61 | file(GLOB EXISTING_TAGGED_FILES ${DEST_FILE}*.[0-9]*) 62 | 63 | set(TAGGED_DEST_FILE ${DEST_FILE}${BRANCH}.${COMMITS}${BUILD}${DIRTY}) 64 | 65 | # default install operation is to to create a symlink, as this uses the least amount of disk space 66 | # - allow users to copy the file, at the expense of additional space 67 | if(INSTALL_TAGGED_AS_COPY) 68 | set(INSTALL_TYPE copy) 69 | else() 70 | set(INSTALL_TYPE create_symlink) 71 | endif() 72 | 73 | # don't reinstall if there is only 1 tagged file there, it's name matches, and it's newer than the source file 74 | if(NOT EXISTING_TAGGED_FILES STREQUAL TAGGED_DEST_FILE OR ${SRC_FILE} IS_NEWER_THAN ${TAGGED_DEST_FILE}) 75 | 76 | if (EXISTING_TAGGED_FILES) 77 | execute_process( 78 | COMMAND 79 | ${CMAKE_COMMAND} -E remove ${EXISTING_TAGGED_FILES} 80 | ) 81 | endif() 82 | 83 | message(STATUS "installing ${TAGGED_DEST_FILE}") 84 | 85 | execute_process( 86 | COMMAND 87 | ${CMAKE_COMMAND} -E make_directory ${INSTALL_DIR} 88 | 89 | COMMAND 90 | ${CMAKE_COMMAND} -E ${INSTALL_TYPE} ${SRC_FILE} ${TAGGED_DEST_FILE} 91 | 92 | COMMAND 93 | ${CMAKE_COMMAND} -E touch ${TAGGED_DEST_FILE} # update the timestamp so subsequent installs aren't repeated unnecessarily 94 | ) 95 | endif() 96 | -------------------------------------------------------------------------------- /scripts/cmake/lib.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_lib) 2 | include(module) 3 | include(install) 4 | include(install_makefile) 5 | 6 | function(lib) 7 | # - creates a library 8 | # 9 | # arguments: 10 | # NAME lib_name 11 | # [STATIC]/SHARED 12 | # MODULE module 13 | # SRCS sources* 14 | # PROTO protobuf files* 15 | # PROTO_INCLUDES additional search paths passed to protoc 16 | # LIBS dependencies* 17 | # TAG also install tagged 18 | 19 | # parse arguments 20 | set(options STATIC SHARED TAG) 21 | set(values NAME MODULE PROTO_CPP_OUT PROTO_CWD) 22 | set(lists SRCS PROTO PROTO_INCLUDES LIBS MOC RES UI) 23 | cmake_parse_arguments(ARG "${options}" "${values}" "${lists}" "${ARGN}") 24 | 25 | # link type 26 | if(ARG_SHARED) 27 | set(LINK SHARED) 28 | 29 | # all shared libs have a .so suffix added, their name becomes a module to which they are added 30 | set(LIB_NAME ${ARG_NAME}.so) 31 | else() 32 | # default to STATIC if nothing is specified 33 | set(LINK STATIC) 34 | 35 | # all static libs have a .lib suffix added, their name becomes a module to which they are added 36 | set(LIB_NAME ${ARG_NAME}.lib) 37 | endif() 38 | 39 | if(DEBUG_CMAKE) 40 | message(STATUS "LIB: NAME=${ARG_NAME} LIB_NAME=${LIB_NAME} MODULE=${ARG_MODULE} PROTO=${ARG_PROTO} PROTO_INCLUDES=${ARG_PROTO_INCLUDES} PROTO_CPP_OUT=${ARG_PROTO_CPP_OUT} PROTO_CWD=${ARG_PROTO_CWD} LIBS=${ARG_LIBS} SRCS=${ARG_SRCS}") 41 | endif() 42 | 43 | # generate protobuf files if required 44 | if (ARG_PROTO) 45 | protoc( 46 | PROTO_SRCS 47 | PROTO_HDRS 48 | PROTO_DIRS 49 | 50 | PROTO 51 | ${ARG_PROTO} 52 | 53 | INCLUDE 54 | ${ARG_PROTO_INCLUDES} 55 | 56 | CPP_OUT 57 | ${ARG_PROTO_CPP_OUT} 58 | 59 | CWD 60 | ${ARG_PROTO_CWD} 61 | ) 62 | 63 | if(NOT ARG_SHARED) 64 | set(PROTO_LIB ${LIB_PROTOBUF}) 65 | endif() 66 | 67 | endif() 68 | 69 | if(NOT NO_GUI) 70 | # qt specific helpers 71 | if(ARG_MOC) 72 | qt5_wrap_cpp(ARG_MOC_OUT ${ARG_MOC}) 73 | endif() 74 | 75 | if(ARG_RES) 76 | qt5_add_resources(ARG_RES_OUT ${ARG_RES}) 77 | endif() 78 | 79 | if(ARG_UI) 80 | qt5_wrap_ui(ARG_UI_OUT ${ARG_UI}) 81 | endif() 82 | endif() 83 | 84 | add_library( 85 | ${LIB_NAME} 86 | ${LINK} 87 | ${ARG_SRCS} ${PROTO_SRCS} ${PROTO_HDRS} ${ARG_MOC_OUT} ${ARG_RES_OUT} ${ARG_UI_OUT} 88 | ) 89 | 90 | if (ARG_LIBS) 91 | clean_link_libs(ARG_LIBS_OUT "${ARG_LIBS}") 92 | target_link_libraries(${LIB_NAME} ${ARG_LIBS_OUT}) 93 | endif() 94 | 95 | target_link_libraries(${LIB_NAME} 96 | ${PROTO_LIB}) 97 | 98 | # remove the .so suffix we added to the target name from the generated library 99 | if(ARG_SHARED AND NOT WIN32) 100 | set_target_properties(${LIB_NAME} PROPERTIES OUTPUT_NAME ${ARG_NAME}) 101 | endif() 102 | 103 | # add lib as a dependency of module, so 'make module' will build the lib 104 | add_to_module( 105 | ${ARG_NAME} 106 | ${LIB_NAME} 107 | ) 108 | 109 | # if parent module has been specified, add this module to the parent 110 | if(ARG_MODULE) 111 | add_to_module( 112 | ${ARG_MODULE} 113 | ${ARG_NAME} 114 | ) 115 | endif() 116 | 117 | install_makefile() 118 | 119 | add_dependencies(${LIB_NAME} build_config) 120 | endfunction() 121 | 122 | -------------------------------------------------------------------------------- /scripts/cmake/makefile: -------------------------------------------------------------------------------- 1 | #------------ ensure valid commands ------ 2 | 3 | # 0: target is "all" and build variant is "debug" 4 | # 1: if command is one of the valid build variants, target is "all" and build variant is whatever is specified 5 | # or, if command is not a build variant, target is whatever is specified and build variant is "debug" 6 | # 2: both target and build variant are whatever has been specified 7 | 8 | ifeq ($(findstring $(words $(MAKECMDGOALS)),0 1 2), ) 9 | $(error invalid commands passed to make; require 0, 1 or 2 commands) 10 | endif 11 | 12 | #------------ build variant -------------- 13 | 14 | build := 15 | build_variants := debug release 16 | default_build := debug 17 | 18 | # if there are 2 commands, 1 of them has to be a build variant 19 | ifeq ($(findstring $(words $(MAKECMDGOALS)),2),2) 20 | build := $(filter $(build_variants),$(MAKECMDGOALS)) 21 | ifeq "$(build)" "" 22 | $(error 2 commands passed to make, 1 must be the build variant. Specify one of [$(strip $(build_variants))]) 23 | endif 24 | # if there is only 1 command, it might be the build variant (and implicit all) 25 | else ifeq ($(findstring $(words $(MAKECMDGOALS)),1),1) 26 | build := $(filter $(build_variants),$(MAKECMDGOALS)) 27 | endif 28 | 29 | # if no build has been specified, then we will build the default build 30 | ifeq "$(build)" "" 31 | build:=$(default_build) 32 | endif 33 | 34 | building := $(if $(filter $(build_variants),$(build)),1,0) 35 | ifneq "$(building)" "1" 36 | $(error Invalid build variant, specify one of [$(subst $(space),$(,) ,$(strip $(build_variants)))]) 37 | endif 38 | 39 | #------------ target --------------------- 40 | 41 | target := $(filter-out $(build),$(MAKECMDGOALS)) 42 | 43 | #------------ build dir ------------------ 44 | 45 | define find_project_root 46 | $(if $(wildcard $1/.git),$1,$(call find_project_root,$(abspath $1/..))) 47 | endef 48 | 49 | project_root := $(strip $(call find_project_root,$(shell pwd))) 50 | build_stem := $(subst $(project_root),,$(shell pwd)) 51 | build_root := $(project_root)/.build/$(build) 52 | build_dir := $(build_root)$(build_stem) 53 | 54 | #----------------------------------------- 55 | 56 | .PHONY: all $(target) $(build_variants) 57 | 58 | all: 59 | @$(MAKE) --no-print-directory -C $(build_dir) 60 | 61 | $(target): 62 | @$(MAKE) --no-print-directory -C $(build_root) $(target) 63 | 64 | $(build): $(if $(target),,all) 65 | @touch /dev/null # rule which does nothing; suppresses "Nothing to be done for target" 66 | -------------------------------------------------------------------------------- /scripts/cmake/message.cmake: -------------------------------------------------------------------------------- 1 | include(include_guard) 2 | include_guard(__included_message) 3 | 4 | if(NOT WIN32) 5 | string(ASCII 27 Esc) 6 | set(col_reset "${Esc}[m") 7 | set(col_bold "${Esc}[1m") 8 | set(red "${Esc}[31m") 9 | set(green "${Esc}[32m") 10 | set(yellow "${Esc}[33m") 11 | set(blue "${Esc}[34m") 12 | set(magenta "${Esc}[35m") 13 | set(cyan "${Esc}[36m") 14 | set(white "${Esc}[37m") 15 | set(bold_red "${Esc}[1;31m") 16 | set(bold_green "${Esc}[1;32m") 17 | set(bold_yellow "${Esc}[1;33m") 18 | set(bold_blue "${Esc}[1;34m") 19 | set(bold_magenta "${Esc}[1;35m") 20 | set(bold_cyan "${Esc}[1;36m") 21 | set(bold_white "${Esc}[1;37m") 22 | endif() 23 | 24 | function(message) 25 | # FATAL_ERROR / SEND_ERROR : red 26 | # WARNING : yellow 27 | # AUTHOR_WARNING : cyan 28 | # STATUS : green 29 | 30 | set(ALL_ARGS ${ARGV}) 31 | list(GET ARGV 0 MSG_TYPE) 32 | list(REMOVE_AT ARGV 0) 33 | 34 | if(MSG_TYPE STREQUAL FATAL_ERROR OR MSG_TYPE STREQUAL SEND_ERROR) 35 | 36 | _message(${MSG_TYPE} "${bold_red}${ARGV}${col_reset}") 37 | 38 | elseif(MSG_TYPE STREQUAL WARNING) 39 | 40 | _message(${MSG_TYPE} "${bold_yellow}${ARGV}${col_reset}") 41 | 42 | elseif(MSG_TYPE STREQUAL AUTHOR_WARNING) 43 | 44 | _message(${MSG_TYPE} "${bold_cyan}${ARGV}${col_reset}") 45 | 46 | elseif(MSG_TYPE STREQUAL STATUS) 47 | 48 | _message(${MSG_TYPE} "${bold_blue}${ARGV}${col_reset}") 49 | 50 | elseif(MSG_TYPE STREQUAL REVIEW) 51 | 52 | _message("${red}${ARGV}${col_reset}") 53 | 54 | elseif(MSG_TYPE STREQUAL INFO) 55 | 56 | _message("${bold_magenta}${ARGV}${col_reset}") 57 | 58 | elseif(MSG_TYPE STREQUAL TRACE) 59 | 60 | _message("${cyan}${ARGV}${col_reset}") 61 | 62 | else() 63 | 64 | _message("${ALL_ARGS}") 65 | 66 | endif() 67 | endfunction() 68 | -------------------------------------------------------------------------------- /scripts/cmake/module.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_module) 2 | 3 | function(module MODULE) 4 | 5 | # create a phony target MODULE if it doesn't already exist 6 | if (NOT TARGET ${MODULE}) 7 | add_custom_target(${MODULE} 8 | ALL 9 | ) 10 | endif() 11 | 12 | endfunction() 13 | 14 | function(add_to_module PARENT DEPENDENCY) 15 | 16 | module(${PARENT}) 17 | 18 | # add the dependency to be built when PARENT is built 19 | add_dependencies(${PARENT} 20 | ${DEPENDENCY} 21 | ) 22 | 23 | endfunction() 24 | -------------------------------------------------------------------------------- /scripts/cmake/print_build_config.cmake: -------------------------------------------------------------------------------- 1 | include(message) 2 | 3 | # build variant 4 | string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_VARIANT) 5 | 6 | # compiler and version 7 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 8 | 9 | set(COMPILER "clang") 10 | execute_process( 11 | OUTPUT_VARIABLE COMPILER_VERSION 12 | COMMAND clang -dumpversion 13 | OUTPUT_STRIP_TRAILING_WHITESPACE 14 | ) 15 | 16 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 17 | 18 | set(COMPILER "gcc") 19 | execute_process( 20 | OUTPUT_VARIABLE COMPILER_VERSION 21 | COMMAND gcc -dumpversion 22 | OUTPUT_STRIP_TRAILING_WHITESPACE 23 | ) 24 | 25 | endif() 26 | 27 | message(STATUS "build=${BUILD_VARIANT} compiler=${COMPILER}-${COMPILER_VERSION}") 28 | -------------------------------------------------------------------------------- /scripts/cmake/project.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_project) 2 | 3 | function(default_project PROJECT_NAME) 4 | if(NOT BUILD_PROJECT) 5 | set(BUILD_PROJECT "${PROJECT_NAME}" PARENT_SCOPE) 6 | elseif(NOT EXISTS ${CMAKE_SOURCE_DIR}/projects/${BUILD_PROJECT}.cmake) 7 | message(FATAL_ERROR "Unknown project \"${BUILD_PROJECT}\"") 8 | endif() 9 | endfunction() 10 | 11 | function(add_project PROJECT_NAME) 12 | if(BUILD_PROJECT STREQUAL "${PROJECT_NAME}") 13 | 14 | message(TRACE "[ building ${PROJECT_NAME} ]") 15 | include(${PROJECT_NAME}) 16 | 17 | endif() 18 | endfunction() 19 | -------------------------------------------------------------------------------- /scripts/cmake/protoc.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_protoc) 2 | 3 | # Google's provided vcproj files generate libraries with a "lib" prefix on Windows 4 | if(MSVC) 5 | set(PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") 6 | set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "") 7 | 8 | find_path(PROTOBUF_SRC_ROOT_FOLDER protobuf.pc.in) 9 | endif() 10 | 11 | # Find the include directory 12 | find_path(PROTOBUF_INCLUDE_DIR 13 | google/protobuf/service.h 14 | PATHS ${PROTOBUF_SRC_ROOT_FOLDER}/src 15 | ) 16 | 17 | # Find the protoc compiler 18 | find_program(PROTOBUF_PROTOC_EXECUTABLE 19 | NAMES 20 | protoc 21 | 22 | DOC 23 | "The Google Protocol Buffers Compiler" 24 | 25 | PATHS 26 | ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Release 27 | ${PROTOBUF_SRC_ROOT_FOLDER}/vsprojects/${_PROTOBUF_ARCH_DIR}Debug 28 | ) 29 | 30 | # These are internal variables, don't display them in cmake guis 31 | mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE) 32 | mark_as_advanced(PROTOBUF_INCLUDE_DIR) 33 | 34 | function(protoc SRCS_OUT HDRS_OUT DIRS_OUT) 35 | 36 | set(options) 37 | set(values CPP_OUT CWD) 38 | set(lists INCLUDE PROTO) 39 | cmake_parse_arguments(ARG "${options}" "${values}" "${lists}" "${ARGN}") 40 | 41 | if (NOT ARG_CPP_OUT) 42 | set(ARG_CPP_OUT ${CMAKE_SOURCE_DIR}) 43 | endif() 44 | 45 | if (NOT ARG_CWD) 46 | set(ARG_CWD ${CMAKE_SOURCE_DIR}) 47 | endif() 48 | 49 | set(PROTOC_INCLUDE_PATHS -I ${ARG_CWD}) 50 | 51 | set(ARG_INCLUDE ${ARG_INCLUDE} ${DEFAULT_PROTO_INCLUDES}) 52 | 53 | foreach(PATH ${ARG_INCLUDE}) 54 | list(FIND PROTOC_INCLUDE_PATHS ${PATH} exists) 55 | if(${exists} EQUAL -1) 56 | list(APPEND PROTOC_INCLUDE_PATHS -I ${PATH}) 57 | endif() 58 | endforeach() 59 | 60 | if(DEBUG_CMAKE) 61 | message(STATUS "PROTOC: INCLUDE=${ARG_INCLUDE} PROTO=${ARG_PROTO} CPP_OUT=${ARG_CPP_OUT} CWD=${ARG_CWD}") 62 | endif() 63 | 64 | set(GENERATED_SRCS) 65 | set(GENERATED_HDRS) 66 | set(GENERATED_DIRS) 67 | 68 | foreach(FILE ${ARG_PROTO}) 69 | 70 | get_filename_component(ABS_FILE ${FILE} ABSOLUTE) 71 | 72 | string(REPLACE ${ARG_CWD} ${ARG_CPP_OUT} PROTO_DEST ${ABS_FILE}) 73 | 74 | get_filename_component(FILE_WE ${PROTO_DEST} NAME_WE) 75 | get_filename_component(DEST_DIR ${PROTO_DEST} DIRECTORY) 76 | 77 | list(FIND GENERATED_DIRS ${DEST_DIR} exists) 78 | if(${exists} EQUAL -1) 79 | list(APPEND GENERATED_DIRS ${DEST_DIR}) 80 | endif() 81 | 82 | set(GENERATED_SRC "${DEST_DIR}/${FILE_WE}.pb.cc") 83 | set(GENERATED_HDR "${DEST_DIR}/${FILE_WE}.pb.h") 84 | 85 | add_custom_command( 86 | OUTPUT 87 | ${GENERATED_SRC} 88 | ${GENERATED_HDR} 89 | 90 | COMMAND 91 | ${PROTOBUF_PROTOC_EXECUTABLE} 92 | 93 | ARGS 94 | --cpp_out ${ARG_CPP_OUT} ${PROTOC_INCLUDE_PATHS} ${ABS_FILE} 95 | 96 | WORKING_DIRECTORY 97 | ${ARG_CWD} 98 | 99 | DEPENDS 100 | ${ABS_FILE} 101 | ${PROTOBUF_PROTOC_EXECUTABLE} 102 | 103 | COMMENT 104 | "Running C++ protocol buffer compiler on ${FILE}" 105 | 106 | VERBATIM 107 | ) 108 | 109 | set_source_files_properties(${GENERATED_SRC} PROPERTIES GENERATED TRUE) 110 | set_source_files_properties(${GENERATED_HDR} PROPERTIES GENERATED TRUE) 111 | 112 | list(APPEND GENERATED_SRCS ${GENERATED_SRC}) 113 | list(APPEND GENERATED_HDRS ${GENERATED_HDR}) 114 | 115 | endforeach() 116 | 117 | if(DEBUG_CMAKE) 118 | message(STATUS "PROTOC: GENERATED_SRCS=${GENERATED_SRCS} GENERATED_HDRS=${GENERATED_HDRS} GENERATED_DIRS=${GENERATED_DIRS}") 119 | endif() 120 | 121 | set(${SRCS_OUT} ${GENERATED_SRCS} PARENT_SCOPE) 122 | set(${HDRS_OUT} ${GENERATED_HDRS} PARENT_SCOPE) 123 | set(${DIRS_OUT} ${GENERATED_DIRS} PARENT_SCOPE) 124 | 125 | endfunction() 126 | 127 | -------------------------------------------------------------------------------- /scripts/cmake/settings.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_settings) 2 | 3 | # set(DEBUG_CMAKE "TRUE") 4 | #set(NO_CCACHE "TRUE") 5 | 6 | # we set the -rdynamic compiler flag, which exports all our symbols, because we use backtrace 7 | # to log a stack trace when we dump core. This variable suppresses a warning about this behaviour 8 | set(CMAKE_ENABLE_EXPORTS true) 9 | 10 | set(CMAKE_CXX_STANDARD 14) 11 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 12 | set(CMAKE_CXX_EXTENSIONS OFF) 13 | -------------------------------------------------------------------------------- /scripts/cmake/string.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_string) 2 | 3 | function(word_count INPUT_STRING NUM_WORDS) 4 | 5 | if (INPUT_STRING STREQUAL "") 6 | 7 | # empty string = 0 words 8 | set (len 0) 9 | 10 | else() 11 | 12 | # convert string into list 13 | string(REPLACE " " ";" input_list ${INPUT_STRING}) 14 | string(REPLACE "\n" ";" input_list ${input_list}) 15 | 16 | # get length of list 17 | list (LENGTH input_list len) 18 | 19 | endif() 20 | 21 | # store result in NUM_WORDS 22 | set(${NUM_WORDS} ${len} PARENT_SCOPE) 23 | 24 | endfunction() 25 | -------------------------------------------------------------------------------- /scripts/cmake/test.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_test) 2 | include(module) 3 | include(bin) 4 | 5 | enable_testing() 6 | 7 | function(test) 8 | # - creates a test executable 9 | # - adds it to ctest 10 | # - automatically runs the tests and creates a test.passed sentinal file when they pass 11 | # - optionally adds the tests to 'module' target 12 | # 13 | # arguments: 14 | # NAME [test_name] 15 | # ARGS [test args*] 16 | # SRCS [sources*] 17 | # PROTO [protobuf files*] 18 | # LIBS [dependencies*] 19 | # MODULE [module] 20 | # SUPPRESSIONS [filename] filename in current directory for suppressions 21 | # NO_VALGRIND don't run the test through valgrind 22 | 23 | # parse arguments 24 | set(options NO_VALGRIND SUPPRESS_NO_VALGRIND_WARNING) 25 | set(values NAME MODULE SUPPRESSIONS RPATH) 26 | set(lists ARGS SRCS PROTO PROTO_INCLUDES LIBS) 27 | cmake_parse_arguments(ARG "${options}" "${values}" "${lists}" "${ARGN}") 28 | 29 | # all tests have a .test suffix added, their name becomes a module to which they are added 30 | set(TEST_NAME ${ARG_NAME}.test) 31 | 32 | # since boost 1.60 a unit test executable requires a "--" between the boost 33 | # framework args and the args passed to the unit test 34 | # boost1.57 doesn't work if that separator is used 35 | if(Boost_MINOR_VERSION LESS 60) 36 | set(ARGS_SEP) 37 | else() 38 | set(ARGS_SEP --) 39 | endif() 40 | 41 | # create the test executable, linked against dependencies and boost-test 42 | bin( 43 | # pass ARG_NAME to bin, but specify SUFFIX=test, so the binary target matches TEST_NAME 44 | NAME 45 | ${ARG_NAME} 46 | SUFFIX 47 | test 48 | 49 | MODULE 50 | ${ARG_MODULE} 51 | 52 | SRCS 53 | ${ARG_SRCS} 54 | 55 | PROTO 56 | ${ARG_PROTO} 57 | 58 | PROTO_INCLUDES 59 | ${ARG_PROTO_INCLUDES} 60 | 61 | LIBS 62 | ${ARG_LIBS} 63 | ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} 64 | 65 | RPATH 66 | ${ARG_RPATH} 67 | ) 68 | 69 | # make tests run through valgrind by default 70 | if (NOT ARG_NO_VALGRIND) 71 | set(VALGRIND_BIN "valgrind") 72 | set(VALGRIND_OPTS "--leak-check=full --track-origins=yes --error-exitcode=1 --quiet --soname-synonyms=somalloc=tcmalloc") 73 | 74 | if (ARG_SUPPRESSIONS) 75 | set(VALGRIND_OPTS "${VALGRIND_OPTS} --suppressions=${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SUPPRESSIONS}") 76 | endif() 77 | 78 | set(VALGRIND_CMD "${VALGRIND_BIN} ${VALGRIND_OPTS}") 79 | separate_arguments(VALGRIND_CMD) 80 | elseif(NOT ARG_SUPPRESS_NO_VALGRIND_WARNING) 81 | message(REVIEW "${TEST_NAME} will not run through valgrind") 82 | endif() 83 | 84 | # add the test to ctest 85 | add_test( 86 | NAME 87 | ${TEST_NAME} 88 | 89 | COMMAND 90 | ${VALGRIND_CMD} $ ${ARG_ARGS} 91 | 92 | WORKING_DIRECTORY 93 | ${CMAKE_CURRENT_SOURCE_DIR} 94 | ) 95 | 96 | set(OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}.output) 97 | set(PASSED_FILE ${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}.passed) 98 | 99 | # create test.passed command which runs this test and creates a sentinel file if it passes 100 | add_custom_command( 101 | OUTPUT 102 | ${PASSED_FILE} 103 | 104 | WORKING_DIRECTORY 105 | ${CMAKE_CURRENT_SOURCE_DIR} 106 | 107 | COMMAND 108 | echo "\"${VALGRIND_BIN} ${VALGRIND_OPTS} $ --report_level=detailed ${ARGS_SEP} ${ARG_ARGS}\"" > ${OUTPUT_FILE} 109 | 110 | COMMAND 111 | echo "-----------------------------" >> ${OUTPUT_FILE} 112 | 113 | COMMAND 114 | # the FastClock init often fails under valgrind so disable the exception 115 | export "SUPPRESS_VIV_FASTCLOCK_INIT_FAILURE=1" && ${VALGRIND_CMD} $ --report_level=detailed ${ARGS_SEP} ${ARG_ARGS} >> ${OUTPUT_FILE} 2>&1 || (cat ${OUTPUT_FILE} && false) 116 | 117 | COMMAND 118 | ${CMAKE_COMMAND} -E touch ${PASSED_FILE} 119 | 120 | COMMENT 121 | "Running ${ARG_NAME} tests" 122 | 123 | DEPENDS 124 | ${TEST_NAME} 125 | 126 | USES_TERMINAL 127 | ) 128 | 129 | # create test.run target which depends on test.passed 130 | add_custom_target(${ARG_NAME}.run 131 | ALL 132 | DEPENDS ${PASSED_FILE} 133 | ) 134 | 135 | # add the test.run command as a dependency of module, so 'make module' will build and run the test 136 | add_to_module( 137 | ${ARG_NAME} 138 | ${ARG_NAME}.run 139 | ) 140 | 141 | endfunction() 142 | -------------------------------------------------------------------------------- /scripts/cmake/utils.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_utils) 2 | 3 | function(add_unique ITEM LIST) 4 | list(FIND ${LIST} ${ITEM} exists) 5 | if(${exists} EQUAL -1) 6 | list(APPEND ${LIST} ${ITEM}) 7 | endif() 8 | set(${LIST} ${${LIST}} PARENT_SCOPE) 9 | endfunction() 10 | 11 | ##################################################################################### 12 | # Work around CMP0003: Libraries linked via full path no longer produce linker search paths 13 | # Don't link with absolute paths, just link using the library name, and add the path to the library 14 | # search path 15 | # This is only relevant for shared libraries 16 | ##################################################################################### 17 | # arguments: 18 | # LIBS libraries with absolute paths 19 | # OUT output variable - relevant library paths will be split 20 | 21 | function(clean_link_libs OUT LIBS) 22 | 23 | foreach(LIB ${LIBS}) 24 | get_filename_component(EXTENSION ${LIB} EXT) 25 | if ("${EXTENSION}" STREQUAL ${CMAKE_SHARED_LIBRARY_SUFFIX}) 26 | get_filename_component(DIR ${LIB} DIRECTORY) 27 | if(DIR) 28 | # Add path to the linker search path 29 | add_unique(-L${DIR} OUT) 30 | endif() 31 | 32 | get_filename_component(FILE ${LIB} NAME) 33 | add_unique(${FILE} OUT) 34 | else() 35 | add_unique(${LIB} OUT) 36 | endif() 37 | endforeach() 38 | 39 | set(${OUT} ${${OUT}} PARENT_SCOPE) 40 | 41 | endfunction() 42 | 43 | -------------------------------------------------------------------------------- /scripts/cmake/version.cc.in: -------------------------------------------------------------------------------- 1 | #include "${FILENAME}.h" 2 | 3 | /* 4 | * Version information 5 | * 6 | * - This is a generated file - do not edit 7 | */ 8 | 9 | namespace ${PURPOSE} { namespace bin { 10 | 11 | const char* version() { return "${VERSION}"; } 12 | const char* num_commits() { return "${NUM_COMMITS}"; } 13 | const char* date() { return __DATE__ " " __TIME__; } 14 | const char* variant() { return "${BUILD_VARIANT}"; } 15 | const char* branch() { return "${BRANCH}"; } 16 | const char* ahead_by() { return "${AHEAD_BY}"; } 17 | const char* num_untracked() { return "${NUM_UNTRACKED}"; } 18 | const char* user() { return "${USER}"; } 19 | const char* hostname() { return "${HOSTNAME}"; } 20 | 21 | }} 22 | -------------------------------------------------------------------------------- /scripts/cmake/version.cmake: -------------------------------------------------------------------------------- 1 | include_guard(__included_version) 2 | 3 | function(create_version PURPOSE DEST_FILE) 4 | 5 | get_filename_component(DEST_FILE ${DEST_FILE} ABSOLUTE) 6 | 7 | add_custom_target( 8 | version_info.${PURPOSE} 9 | ALL 10 | COMMAND 11 | ${CMAKE_COMMAND} 12 | -DCMAKE_MODULE_PATH=${CMAKE_SCRIPTS_DIR} 13 | -DCMAKE_SCRIPTS_DIR=${CMAKE_SCRIPTS_DIR} 14 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 15 | -DPURPOSE=${PURPOSE} 16 | -DDEST_FILE=${DEST_FILE} 17 | -P ${CMAKE_SCRIPTS_DIR}/create_version.cmake 18 | ) 19 | 20 | set_source_files_properties(${DEST_FILE} PROPERTIES GENERATED TRUE) 21 | 22 | endfunction() 23 | --------------------------------------------------------------------------------