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

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

@ -513,7 +513,7 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
if (content == m_blockIgnoreId || content == m_blockAirId) {
continue;
}
std::map<int, std::string>::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<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;
}
}

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

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

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