Set compiler flags for building with C++20

This commit is contained in:
Jack Andersen 2020-04-10 19:05:55 -10:00
parent 89e2e65100
commit 26f272735d
9 changed files with 57 additions and 46 deletions

View File

@ -40,8 +40,8 @@ project(urde VERSION 0.1.0)
# when available. GCC and Clang posess no such flag, and must be
# manually enforced. CMake, curiously, also doesn't have a "latest"
# standard flag either.
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_STANDARD 17)
if (NOT MSVC)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
@ -86,30 +86,41 @@ if(MSVC)
add_compile_options(/IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4068
/wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 /wd4309 /wd4805 ${VS_OPTIONS})
if(WINDOWS_STORE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /AI\"$ENV{PROGRAMFILES\(X86\)}/Microsoft Visual Studio/2017/Community/Common7/IDE/VC/vcpackages\" /AI\"$ENV{PROGRAMFILES\(X86\)}/Windows Kits/10/UnionMetadata\"")
set(HAVE_WORDS_BIGENDIAN_EXITCODE 0)
endif()
add_compile_options(
# Disable exceptions
$<$<COMPILE_LANGUAGE:CXX>:/EHsc>
add_compile_options(/EHsc)
# Enforce various standards compliant behavior.
$<$<COMPILE_LANGUAGE:CXX>:/permissive->
# Enable standard volatile semantics.
$<$<COMPILE_LANGUAGE:CXX>:/volatile:iso>
# Reports the proper value for the __cplusplus preprocessor macro.
$<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>
# Use latest C++ standard.
$<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Flags for MSVC (not clang-cl)
add_compile_options(
/std:c++latest # Use latest C++ standard.
/permissive- # Enforce various standards compliance features.
/Zc:externConstexpr # Allow extern constexpr variables according to the standard.
/Zc:throwingNew # Assume new throws, allowing for better code generation.
# Allow constexpr variables to have explicit external linkage.
$<$<COMPILE_LANGUAGE:CXX>:/Zc:externConstexpr>
# Assume that new throws exceptions, allowing better code generation.
$<$<COMPILE_LANGUAGE:CXX>:/Zc:throwingNew>
# Link-time Code Generation for Release builds
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:/GL>
)
# Link-time Code Generation for Release builds (excluding clang-cl)
set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy /MD")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy /MD")
# Link-time Code Generation for Release builds
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "/LTCG")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "/LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()
else()
@ -144,21 +155,19 @@ else()
endif()
if(URDE_MSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
add_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fsanitize-recover=all)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++> -fsanitize=memory
-fsanitize-memory-track-origins -fsanitize-recover=all)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
add_compile_options(-Wall -Wno-multichar -Werror=implicit-fallthrough -Wno-unknown-warning-option
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
-Wall -Wno-multichar -Werror=implicit-fallthrough -Wno-unknown-warning-option
-Wno-lto-type-mismatch -Wno-unused-variable -Wno-unused-private-field
-Wno-unused-function -Wno-sign-compare -Wno-unknown-pragmas -Werror)
add_compile_definitions(FMT_EXCEPTIONS=0)
if(APPLE)
add_compile_options(-Wno-error=deprecated-declarations)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=thin")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto=thin")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=thin")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto=thin")
add_compile_options(-Wno-error=deprecated-declarations
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-flto=thin>)
endif()
endif()

View File

@ -601,7 +601,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
DLReader::DLPrimVert maxIdxs;
std::vector<atInt16> skinIndices;
DLReader::ExtraVertTracker extraTracker;
for (size_t s = 0; s < lastDlSec; ++s) {
for (atUint32 s = 0; s < lastDlSec; ++s) {
atUint64 secStart = reader.position();
if (s < matSecCount) {
if (!s) {
@ -683,7 +683,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
unsigned createdUVLayers = 0;
unsigned surfIdx = 0;
for (size_t s = 0; s < lastDlSec; ++s) {
for (atUint32 s = 0; s < lastDlSec; ++s) {
atUint64 secStart = reader.position();
if (s < matSecCount) {
MaterialSet matSet;
@ -698,7 +698,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
atUint32 vertCount = maxIdxs.pos + 1;
std::vector<atVec3f> positions;
positions.reserve(vertCount);
for (size_t i = 0; i <= maxIdxs.pos; ++i) {
for (atUint16 i = 0; i <= maxIdxs.pos; ++i) {
positions.push_back(reader.readVec3fBig());
const atVec3f& pos = positions.back();
os.format(fmt("vert = bm.verts.new(({},{},{}))\n"), pos.simd[0], pos.simd[1], pos.simd[2]);
@ -712,7 +712,7 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
if (rp.first.second && SurfaceHeader::UseMatrixSkinning() && !skinIndices.empty())
vertCount += extraTracker.sendAdditionalVertsToBlender(os, rp, 0);
os.format(fmt("two_face_vert = {}\n"), vertCount);
for (size_t i = 0; i <= maxIdxs.pos; ++i) {
for (atUint16 i = 0; i <= maxIdxs.pos; ++i) {
const atVec3f& pos = positions[i];
os.format(fmt("vert = bm.verts.new(({},{},{}))\n"), pos.simd[0], pos.simd[1], pos.simd[2]);
if (rp.first.second) {
@ -730,16 +730,16 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
/* Normals */
os << "norm_list = []\n";
if (shortNormals) {
size_t normCount = secSizes[s] / 6;
for (size_t i = 0; i < normCount; ++i) {
atUint32 normCount = secSizes[s] / 6;
for (atUint32 i = 0; i < normCount; ++i) {
float x = reader.readInt16Big() / 16384.0f;
float y = reader.readInt16Big() / 16384.0f;
float z = reader.readInt16Big() / 16384.0f;
os.format(fmt("norm_list.append(({},{},{}))\n"), x, y, z);
}
} else {
size_t normCount = secSizes[s] / 12;
for (size_t i = 0; i < normCount; ++i) {
atUint32 normCount = secSizes[s] / 12;
for (atUint32 i = 0; i < normCount; ++i) {
const atVec3f norm = reader.readVec3fBig();
os.format(fmt("norm_list.append(({},{},{}))\n"), norm.simd[0], norm.simd[1], norm.simd[2]);
}
@ -753,8 +753,8 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
case 3: {
/* Float UVs */
os << "uv_list = []\n";
size_t uvCount = secSizes[s] / 8;
for (size_t i = 0; i < uvCount; ++i) {
atUint32 uvCount = secSizes[s] / 8;
for (atUint32 i = 0; i < uvCount; ++i) {
const atVec2f uv = reader.readVec2fBig();
os.format(fmt("uv_list.append(({},{}))\n"), uv.simd[0], uv.simd[1]);
}
@ -768,8 +768,8 @@ atUint32 ReadGeomSectionsToBlender(hecl::blender::PyOutStream& os, athena::io::I
/* Short UVs */
os << "suv_list = []\n";
if (shortUVs) {
size_t uvCount = secSizes[s] / 4;
for (size_t i = 0; i < uvCount; ++i) {
atUint32 uvCount = secSizes[s] / 4;
for (atUint32 i = 0; i < uvCount; ++i) {
float x = reader.readInt16Big() / 32768.0f;
float y = reader.readInt16Big() / 32768.0f;
os.format(fmt("suv_list.append(({},{}))\n"), x, y);
@ -1085,7 +1085,7 @@ void NameCMDL(athena::io::IStreamReader& reader, PAKRouter& pakRouter, typename
if (head.matSetCount)
matSecCount = MaterialSet::OneSection() ? 1 : head.matSetCount;
atUint32 lastDlSec = head.secCount;
for (size_t s = 0; s < lastDlSec; ++s) {
for (atUint32 s = 0; s < lastDlSec; ++s) {
atUint64 secStart = reader.position();
if (s < matSecCount) {
MaterialSet matSet;

2
amuse

@ -1 +1 @@
Subproject commit 9c75aeccbec4d344b9481bc3c312a50241f5ecb1
Subproject commit 40efdcc38cc59dbb66a8c12d96583f2133d534f7

2
hecl

@ -1 +1 @@
Subproject commit 87ad5cbc81dad92d54c60d388157ca6300475c19
Subproject commit 8f31e8bb7d5f3d0fde26e17824456d1b88fb084d

2
jbus

@ -1 +1 @@
Subproject commit d72163ad27c4a8b4d993e1a29d758a3548d92bed
Subproject commit b8e1e4673e66d45876d87439faf463a7301ee05c

@ -1 +1 @@
Subproject commit 35e5c7c90f9d368f29ab191a005d30f91774e50e
Subproject commit 6d8d389459243a38efc585dc03b877b4697cdcf2

2
nod

@ -1 +1 @@
Subproject commit f147e1235646b849f78a8574a6d554214b70792d
Subproject commit dffcac50c5fe3eb67fdee222553fc508cd241579

@ -1 +1 @@
Subproject commit 27eb476b05efeb1b94329eb85f36a1fd83858870
Subproject commit a2c154db8fde276206ae87628d6baa40f1e399a9

View File

@ -2,8 +2,10 @@ if(NOT WINDOWS_STORE)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17
project(visigen)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT MSVC)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
add_executable(visigen