Skip to content

Commit 88df29a

Browse files
committedAug 2, 2014
Add CMake option to use C++11 features
1 parent 2cc1ffc commit 88df29a

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed
 

‎CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ set(VERSION_MAJOR 1)
77
set(VERSION_MINOR 0)
88
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}")
99

10-
set(CMAKE_CXX_FLAGS_RELEASE "-std=c++0x -Wall -DNDEBUG")
11-
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -std=c++0x -Wall -Wextra -DDEBUG")
10+
11+
if(NOT CMAKE_BUILD_TYPE)
12+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build.")
13+
endif()
14+
15+
option(USE_CXX11 "Use C++11" FALSE)
16+
if(USE_CXX11)
17+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -std=c++11 -Wall -DNDEBUG")
18+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -std=c++11 -Wall -Wextra")
19+
else(USE_CXX11)
20+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -DNDEBUG")
21+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g2 -Wall -Wextra")
22+
endif(USE_CXX11)
1223

1324
# Find libgd
1425
find_library(LIBGD_LIBRARY gd)

‎TileGenerator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ inline void TileGenerator::renderMapBlock(const ustring &mapBlock, const BlockPo
513513
if (content == m_blockIgnoreId || content == m_blockAirId) {
514514
continue;
515515
}
516-
std::map<int, std::string>::iterator blockName = m_nameMap.find(content);
516+
NameMap::iterator blockName = m_nameMap.find(content);
517517
if (blockName == m_nameMap.end())
518518
continue;
519519
const string &name = blockName->second;
@@ -688,7 +688,7 @@ void TileGenerator::printUnknown()
688688
{
689689
if (m_unknownNodes.size() > 0) {
690690
std::cerr << "Unknown nodes:" << std::endl;
691-
for (std::set<std::string>::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) {
691+
for (NameSet::iterator node = m_unknownNodes.begin(); node != m_unknownNodes.end(); ++node) {
692692
std::cerr << *node << std::endl;
693693
}
694694
}

‎TileGenerator.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
#include <gd.h>
55
#include <iosfwd>
66
#include <list>
7+
#include <config.h>
8+
#if USE_CXX11
9+
#include <unordered_map>
10+
#include <unordered_set>
11+
#else
712
#include <map>
813
#include <set>
14+
#endif
915
#include <stdint.h>
1016
#include <string>
1117
#include "PixelAttributes.h"
@@ -37,7 +43,15 @@ struct ColorEntry {
3743
class TileGenerator
3844
{
3945
private:
46+
#if USE_CXX11
47+
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
48+
typedef std::unordered_map<int, std::string> NameMap;
49+
typedef std::unordered_set<std::string> NameSet;
50+
#else
4051
typedef std::map<std::string, ColorEntry> ColorMap;
52+
typedef std::map<int, std::string> NameMap;
53+
typedef std::set<std::string> NameSet;
54+
#endif
4155

4256
public:
4357
TileGenerator();
@@ -105,11 +119,11 @@ class TileGenerator
105119
int m_mapWidth;
106120
int m_mapHeight;
107121
std::list<std::pair<int, int> > m_positions;
108-
std::map<int, std::string> m_nameMap;
122+
NameMap m_nameMap;
109123
ColorMap m_colors;
110124
uint16_t m_readedPixels[16];
111125
uint16_t m_readInfo[16];
112-
std::set<std::string> m_unknownNodes;
126+
NameSet m_unknownNodes;
113127
Color m_col[16][16];
114128
uint8_t m_th[16][16];
115129

‎cmake_config.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
#define USE_LEVELDB @USE_LEVELDB@
77
#define USE_REDIS @USE_REDIS@
88

9+
#define USE_CXX11 @USE_CXX11@
10+
911
#endif
1012

‎config.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
#include "cmake_config.h"
2020
#else
2121
#define USE_LEVELDB 0
22+
#define USE_REDIS 0
23+
24+
#define USE_CXX11 0
2225
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.