Skip to content

Commit

Permalink
Add CMake option to use C++11 features
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Aug 2, 2014
1 parent 2cc1ffc commit 88df29a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions TileGenerator.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
18 changes: 16 additions & 2 deletions TileGenerator.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -105,11 +119,11 @@ class TileGenerator
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];

Expand Down
2 changes: 2 additions & 0 deletions cmake_config.h.in
Expand Up @@ -6,5 +6,7 @@
#define USE_LEVELDB @USE_LEVELDB@
#define USE_REDIS @USE_REDIS@

#define USE_CXX11 @USE_CXX11@

#endif

3 changes: 3 additions & 0 deletions config.h
Expand Up @@ -19,4 +19,7 @@
#include "cmake_config.h"
#else
#define USE_LEVELDB 0
#define USE_REDIS 0

#define USE_CXX11 0
#endif

0 comments on commit 88df29a

Please sign in to comment.