Enable C++17 in build
This commit is contained in:
parent
e6634ed26c
commit
1123c95cf2
@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.7)
|
||||
cmake_minimum_required (VERSION 3.12.4)
|
||||
|
||||
if (POLICY CMP0054)
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
@ -120,6 +120,10 @@ else() # GCC or Clang, so get compiler version directly since CMAKE_CXX_COMPILE
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(BUILD_TOOLS OFF CACHE BOOL "")
|
||||
set(SELF_TEST OFF CACHE BOOL "")
|
||||
|
||||
|
@ -74,11 +74,6 @@ macro(set_flags)
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
|
||||
|
||||
#on os x clang adds pthread for us but we need to add it for gcc
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
add_flags_cxx("-stdlib=libc++")
|
||||
@ -87,11 +82,6 @@ macro(set_flags)
|
||||
add_flags_cxx("-pthread")
|
||||
endif()
|
||||
elseif (ANDROID)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
|
||||
|
||||
add_flags_cxx("-fsigned-char")
|
||||
else()
|
||||
# Let gcc / clang know that we're compiling a multi-threaded app:
|
||||
@ -107,11 +97,6 @@ macro(set_flags)
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11")
|
||||
|
||||
# We use a signed char (fixes #640 on RasPi)
|
||||
add_flags_cxx("-fsigned-char")
|
||||
|
||||
|
@ -234,6 +234,13 @@ T Clamp(T a_Value, T a_Min, T a_Max)
|
||||
return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto ToUnsigned(T a_Val)
|
||||
{
|
||||
ASSERT(a_Val >= 0);
|
||||
return static_cast<std::make_unsigned_t<T>>(a_Val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -230,3 +230,10 @@ T Clamp(T a_Value, T a_Min, T a_Max)
|
||||
{
|
||||
return (a_Value < a_Min) ? a_Min : ((a_Value > a_Max) ? a_Max : a_Value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto ToUnsigned(T a_Val)
|
||||
{
|
||||
ASSERT(a_Val >= 0);
|
||||
return static_cast<std::make_unsigned_t<T>>(a_Val);
|
||||
}
|
||||
|
@ -2086,7 +2086,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
||||
// Try to allocate the new storage
|
||||
if ((a_DataTypes & baTypes) != 0)
|
||||
{
|
||||
NewBlocks.reset(new BLOCKTYPE[a_SizeX * a_SizeY * a_SizeZ]);
|
||||
NewBlocks.reset(new BLOCKTYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
||||
if (NewBlocks == nullptr)
|
||||
{
|
||||
return false;
|
||||
@ -2094,7 +2094,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
||||
}
|
||||
if ((a_DataTypes & baMetas) != 0)
|
||||
{
|
||||
NewMetas.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
|
||||
NewMetas.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
||||
if (NewMetas == nullptr)
|
||||
{
|
||||
return false;
|
||||
@ -2102,7 +2102,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
||||
}
|
||||
if ((a_DataTypes & baLight) != 0)
|
||||
{
|
||||
NewLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
|
||||
NewLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
||||
if (NewLight == nullptr)
|
||||
{
|
||||
return false;
|
||||
@ -2110,7 +2110,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
|
||||
}
|
||||
if ((a_DataTypes & baSkyLight) != 0)
|
||||
{
|
||||
NewSkyLight.reset(new NIBBLETYPE[a_SizeX * a_SizeY * a_SizeZ]);
|
||||
NewSkyLight.reset(new NIBBLETYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
||||
if (NewSkyLight == nullptr)
|
||||
{
|
||||
return false;
|
||||
@ -2270,7 +2270,7 @@ void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int
|
||||
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
|
||||
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
|
||||
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
|
||||
BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[NewSizeX * NewSizeY * NewSizeZ] };
|
||||
BLOCKARRAY NewBlockTypes{ new BLOCKTYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
|
||||
size_t idx = 0;
|
||||
for (int y = 0; y < NewSizeY; y++)
|
||||
{
|
||||
@ -2295,7 +2295,7 @@ void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX
|
||||
int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
|
||||
int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
|
||||
int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
|
||||
NIBBLEARRAY NewNibbles{ new NIBBLETYPE[NewSizeX * NewSizeY * NewSizeZ] };
|
||||
NIBBLEARRAY NewNibbles{ new NIBBLETYPE[ToUnsigned(NewSizeX * NewSizeY * NewSizeZ)] };
|
||||
size_t idx = 0;
|
||||
for (int y = 0; y < NewSizeY; y++)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@
|
||||
cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
|
||||
m_Width(a_Width),
|
||||
m_Height(a_Height),
|
||||
m_Items(new cItem[a_Width * a_Height])
|
||||
m_Items(new cItem[ToUnsigned(a_Width * a_Height)])
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,9 +27,7 @@ cCraftingGrid::cCraftingGrid(int a_Width, int a_Height) :
|
||||
|
||||
|
||||
cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
|
||||
m_Width(a_Width),
|
||||
m_Height(a_Height),
|
||||
m_Items(new cItem[a_Width * a_Height])
|
||||
cCraftingGrid(a_Width, a_Height)
|
||||
{
|
||||
for (int i = a_Width * a_Height - 1; i >= 0; i--)
|
||||
{
|
||||
@ -42,9 +40,7 @@ cCraftingGrid::cCraftingGrid(const cItem * a_Items, int a_Width, int a_Height) :
|
||||
|
||||
|
||||
cCraftingGrid::cCraftingGrid(const cCraftingGrid & a_Original) :
|
||||
m_Width(a_Original.m_Width),
|
||||
m_Height(a_Original.m_Height),
|
||||
m_Items(new cItem[a_Original.m_Width * a_Original.m_Height])
|
||||
cCraftingGrid(a_Original.m_Width, a_Original.m_Height)
|
||||
{
|
||||
for (int i = m_Width * m_Height - 1; i >= 0; i--)
|
||||
{
|
||||
|
@ -332,8 +332,8 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) :
|
||||
m_Underlying(a_Underlying),
|
||||
m_CacheSize(a_CacheSize),
|
||||
m_CacheOrder(new int[a_CacheSize]),
|
||||
m_CacheData(new sCacheData[a_CacheSize]),
|
||||
m_CacheOrder(new int[ToUnsigned(a_CacheSize)]),
|
||||
m_CacheData(new sCacheData[ToUnsigned(a_CacheSize)]),
|
||||
m_NumHits(0),
|
||||
m_NumMisses(0),
|
||||
m_TotalChain(0)
|
||||
|
@ -390,6 +390,13 @@ using cTickTimeLong = std::chrono::duration<Int64, cTickTime::period>;
|
||||
#error TOLUA_EXPOSITION should never actually be defined
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
auto ToUnsigned(T a_Val)
|
||||
{
|
||||
ASSERT(a_Val >= 0);
|
||||
return static_cast<std::make_unsigned_t<T>>(a_Val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
{
|
||||
if (m_Array == nullptr)
|
||||
{
|
||||
m_Array.reset(new T[m_Size]);
|
||||
m_Array.reset(new T[ToUnsigned(m_Size)]);
|
||||
}
|
||||
return m_Array.get();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
|
||||
if (a_Workspace == nullptr)
|
||||
{
|
||||
workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY]);
|
||||
workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY)]);
|
||||
a_Workspace = workspaceHeap.get();
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ public:
|
||||
std::unique_ptr<NOISE_DATATYPE[]> workspaceHeap;
|
||||
if (a_Workspace == nullptr)
|
||||
{
|
||||
workspaceHeap.reset(new NOISE_DATATYPE[a_SizeX * a_SizeY * a_SizeZ]);
|
||||
workspaceHeap.reset(new NOISE_DATATYPE[ToUnsigned(a_SizeX * a_SizeY * a_SizeZ)]);
|
||||
a_Workspace = workspaceHeap.get();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ bool cDelayedFluidSimulatorChunkData::cSlot::Add(int a_RelX, int a_RelY, int a_R
|
||||
// cDelayedFluidSimulatorChunkData:
|
||||
|
||||
cDelayedFluidSimulatorChunkData::cDelayedFluidSimulatorChunkData(int a_TickDelay) :
|
||||
m_Slots(new cSlot[a_TickDelay])
|
||||
m_Slots(new cSlot[ToUnsigned(a_TickDelay)])
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user