Add CMake option to use C++11 features

This commit is contained in:
sfan5 2014-08-02 16:30:52 +02:00
parent 2cc1ffc543
commit 88df29a6b3
5 changed files with 36 additions and 6 deletions

View File

@ -7,8 +7,19 @@ set(VERSION_MAJOR 1)
set(VERSION_MINOR 0) set(VERSION_MINOR 0)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}") 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 libgd
find_library(LIBGD_LIBRARY gd) find_library(LIBGD_LIBRARY gd)

View File

@ -513,7 +513,7 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
if (content == m_blockIgnoreId || content == m_blockAirId) { if (content == m_blockIgnoreId || content == m_blockAirId) {
continue; continue;
} }
std::map<int, std::string>::iterator blockName = m_nameMap.find(content); NameMap::iterator blockName = m_nameMap.find(content);
if (blockName == m_nameMap.end()) if (blockName == m_nameMap.end())
continue; continue;
const string &name = blockName->second; const string &name = blockName->second;
@ -688,7 +688,7 @@ void TileGenerator::printUnknown()
{ {
if (m_unknownNodes.size() > 0) { if (m_unknownNodes.size() > 0) {
std::cerr << "Unknown nodes:" << std::endl; std::cerr << "Unknown nodes:" << std::endl;
for (std::set<std::string>::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; std::cerr << *node << std::endl;
} }
} }

View File

@ -4,8 +4,14 @@
#include <gd.h> #include <gd.h>
#include <iosfwd> #include <iosfwd>
#include <list> #include <list>
#include <config.h>
#if USE_CXX11
#include <unordered_map>
#include <unordered_set>
#else
#include <map> #include <map>
#include <set> #include <set>
#endif
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include "PixelAttributes.h" #include "PixelAttributes.h"
@ -37,7 +43,15 @@ struct ColorEntry {
class TileGenerator class TileGenerator
{ {
private: private:
#if USE_CXX11
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
typedef std::unordered_map<int, std::string> NameMap;
typedef std::unordered_set<std::string> NameSet;
#else
typedef std::map<std::string, ColorEntry> ColorMap; typedef std::map<std::string, ColorEntry> ColorMap;
typedef std::map<int, std::string> NameMap;
typedef std::set<std::string> NameSet;
#endif
public: public:
TileGenerator(); TileGenerator();
@ -105,11 +119,11 @@ private:
int m_mapWidth; int m_mapWidth;
int m_mapHeight; int m_mapHeight;
std::list<std::pair<int, int> > m_positions; std::list<std::pair<int, int> > m_positions;
std::map<int, std::string> m_nameMap; NameMap m_nameMap;
ColorMap m_colors; ColorMap m_colors;
uint16_t m_readedPixels[16]; uint16_t m_readedPixels[16];
uint16_t m_readInfo[16]; uint16_t m_readInfo[16];
std::set<std::string> m_unknownNodes; NameSet m_unknownNodes;
Color m_col[16][16]; Color m_col[16][16];
uint8_t m_th[16][16]; uint8_t m_th[16][16];

View File

@ -6,5 +6,7 @@
#define USE_LEVELDB @USE_LEVELDB@ #define USE_LEVELDB @USE_LEVELDB@
#define USE_REDIS @USE_REDIS@ #define USE_REDIS @USE_REDIS@
#define USE_CXX11 @USE_CXX11@
#endif #endif

View File

@ -19,4 +19,7 @@
#include "cmake_config.h" #include "cmake_config.h"
#else #else
#define USE_LEVELDB 0 #define USE_LEVELDB 0
#define USE_REDIS 0
#define USE_CXX11 0
#endif #endif