From 88df29a6b3005856262006f96baff4babd2ded72 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 2 Aug 2014 16:30:52 +0200 Subject: [PATCH] Add CMake option to use C++11 features --- CMakeLists.txt | 15 +++++++++++++-- TileGenerator.cpp | 4 ++-- TileGenerator.h | 18 ++++++++++++++++-- cmake_config.h.in | 2 ++ config.h | 3 +++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce358de..f3fae5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,19 @@ set(VERSION_MAJOR 1) set(VERSION_MINOR 0) set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}") -set(CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -Wall -DNDEBUG") -set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -std=c++0x -Wall -Wextra -DDEBUG") + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build.") +endif() + +option(USE_CXX11 "Use C++11" FALSE) +if(USE_CXX11) + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -std=c++11 -Wall -DNDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -std=c++11 -Wall -Wextra") +else(USE_CXX11) + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -DNDEBUG") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -Wall -Wextra") +endif(USE_CXX11) # Find libgd find_library(LIBGD_LIBRARY gd) diff --git a/TileGenerator.cpp b/TileGenerator.cpp index f46a880..fceaf47 100644 --- a/TileGenerator.cpp +++ b/TileGenerator.cpp @@ -513,7 +513,7 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo if (content == m_blockIgnoreId || content == m_blockAirId) { continue; } - std::map::iterator blockName = m_nameMap.find(content); + NameMap::iterator blockName = m_nameMap.find(content); if (blockName == m_nameMap.end()) continue; const string &name = blockName->second; @@ -688,7 +688,7 @@ void TileGenerator::printUnknown() { if (m_unknownNodes.size() > 0) { std::cerr << "Unknown nodes:" << std::endl; - for (std::set::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) { + for (NameSet::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) { std::cerr << *node << std::endl; } } diff --git a/TileGenerator.h b/TileGenerator.h index cc243bb..258a822 100644 --- a/TileGenerator.h +++ b/TileGenerator.h @@ -4,8 +4,14 @@ #include #include #include +#include +#if USE_CXX11 +#include +#include +#else #include #include +#endif #include #include #include "PixelAttributes.h" @@ -37,7 +43,15 @@ struct ColorEntry { class TileGenerator { private: +#if USE_CXX11 + typedef std::unordered_map ColorMap; + typedef std::unordered_map NameMap; + typedef std::unordered_set NameSet; +#else typedef std::map ColorMap; + typedef std::map NameMap; + typedef std::set NameSet; +#endif public: TileGenerator(); @@ -105,11 +119,11 @@ private: int m_mapWidth; int m_mapHeight; std::list > m_positions; - std::map m_nameMap; + NameMap m_nameMap; ColorMap m_colors; uint16_t m_readedPixels[16]; uint16_t m_readInfo[16]; - std::set m_unknownNodes; + NameSet m_unknownNodes; Color m_col[16][16]; uint8_t m_th[16][16]; diff --git a/cmake_config.h.in b/cmake_config.h.in index fbe6387..6858456 100644 --- a/cmake_config.h.in +++ b/cmake_config.h.in @@ -6,5 +6,7 @@ #define USE_LEVELDB @USE_LEVELDB@ #define USE_REDIS @USE_REDIS@ +#define USE_CXX11 @USE_CXX11@ + #endif diff --git a/config.h b/config.h index f7536a2..c7a37b5 100644 --- a/config.h +++ b/config.h @@ -19,4 +19,7 @@ #include "cmake_config.h" #else #define USE_LEVELDB 0 +#define USE_REDIS 0 + +#define USE_CXX11 0 #endif