Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# Macro which contains all bits to setup the compile flags correctly.
|
|
|
|
#
|
|
|
|
# compile_flags()
|
|
|
|
#
|
|
|
|
macro(compile_flags)
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MSVC)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# "If /Zc:rvalueCast is specified, the compiler follows section 5.4 of the
|
|
|
|
# C++11 standard". We need C++11 for the way we use threads.
|
|
|
|
add_compile_options(/Zc:rvalueCast)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2021-05-11 19:43:43 +00:00
|
|
|
add_compile_options(
|
|
|
|
/MP # Enable multi-threaded compilation.
|
|
|
|
/FC # Display the full path of source code files passed to the compiler in diagnostics.
|
|
|
|
)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
2024-01-16 21:33:53 +00:00
|
|
|
# Our strings are UTF-8.
|
|
|
|
if(MSVC)
|
|
|
|
add_compile_options(/utf-8)
|
|
|
|
else()
|
|
|
|
add_compile_options(-finput-charset=utf-8)
|
|
|
|
endif()
|
|
|
|
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# Add some -D flags for Debug builds. We cannot use add_definitions(), because
|
|
|
|
# it does not appear to support the $<> tags.
|
|
|
|
add_compile_options(
|
|
|
|
"$<$<CONFIG:Debug>:-D_DEBUG>"
|
2020-06-27 11:17:05 +00:00
|
|
|
"$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2>" # FORTIFY_SOURCE should only be used in non-debug builds (requires -O1+)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
)
|
2022-10-22 11:10:40 +00:00
|
|
|
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
add_compile_options(-DFEWER_ASSERTS)
|
|
|
|
endif()
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MINGW)
|
2020-06-27 23:18:28 +00:00
|
|
|
add_link_options(
|
|
|
|
"$<$<NOT:$<CONFIG:Debug>>:-fstack-protector>" # Prevent undefined references when _FORTIFY_SOURCE > 0
|
|
|
|
)
|
2021-12-28 20:08:09 +00:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
2022-11-06 10:24:35 +00:00
|
|
|
add_compile_options(
|
|
|
|
"$<$<CONFIG:Debug>:-Wa,-mbig-obj>" # Switch to pe-bigobj-x86-64 as x64 Debug builds push pe-x86-64 to the limits (linking errors with ASLR, ...)
|
2021-12-28 20:08:09 +00:00
|
|
|
)
|
|
|
|
endif()
|
2024-06-12 12:23:30 +00:00
|
|
|
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
|
|
|
# Fix MinGW's incorrect assumption that the incoming stack at function calls is 16-byte aligned
|
|
|
|
# The Win32 API/calling convention only requires and guarantees 4-byte alignment, leading to alignment problems with SSE/AVX/etc
|
|
|
|
add_compile_options(-mincoming-stack-boundary=2 -mpreferred-stack-boundary=2)
|
|
|
|
endif()
|
2024-03-09 22:38:48 +00:00
|
|
|
add_compile_options(-Wno-stringop-overflow) # This warning false-positives on some MinGW versions so just turn it off
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
# Prepare a generator that checks if we are not a debug, and don't have asserts
|
|
|
|
# on. We need this later on to set some compile options for stable releases.
|
2020-06-27 18:27:21 +00:00
|
|
|
#set(IS_STABLE_RELEASE "$<AND:$<NOT:$<CONFIG:Debug>>,$<NOT:$<BOOL:${OPTION_USE_ASSERTS}>>>")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(MSVC)
|
2023-09-16 23:08:15 +00:00
|
|
|
add_compile_options(
|
|
|
|
/W3
|
2023-11-20 22:26:57 +00:00
|
|
|
#/w34100 # 'identifier' : unreferenced formal parameter
|
2023-09-16 23:08:15 +00:00
|
|
|
/w34189 # 'identifier' : local variable is initialized but not referenced
|
|
|
|
)
|
2023-08-09 19:43:34 +00:00
|
|
|
if(MSVC_VERSION GREATER 1929 AND MSVC_VERSION LESS 1937 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
# Starting with version 19.30 (fixed in version 19.37), there is an optimisation bug, see #9966 for details
|
2022-09-13 10:27:49 +00:00
|
|
|
# This flag disables the broken optimisation to work around the bug
|
|
|
|
add_compile_options(/d2ssa-rse-)
|
|
|
|
endif()
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
add_compile_options(
|
|
|
|
-W
|
|
|
|
-Wall
|
|
|
|
-Wcast-qual
|
|
|
|
-Wextra
|
|
|
|
-Wsign-compare
|
|
|
|
-Wundef
|
|
|
|
-Wpointer-arith
|
|
|
|
-Wwrite-strings
|
|
|
|
-Wredundant-decls
|
|
|
|
-Wformat-security
|
|
|
|
-Wformat=2
|
|
|
|
-Winit-self
|
2022-01-02 20:34:40 +00:00
|
|
|
"$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>"
|
2023-11-20 22:26:57 +00:00
|
|
|
"$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>"
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
|
|
|
# Often parameters are unused, which is fine.
|
|
|
|
-Wno-unused-parameter
|
|
|
|
# We use 'ABCD' multichar for SaveLoad chunks identifiers
|
|
|
|
-Wno-multichar
|
|
|
|
)
|
|
|
|
|
2023-08-17 12:59:48 +00:00
|
|
|
if(OPTION_TRIM_PATH_PREFIX)
|
|
|
|
add_compile_options("-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=/")
|
|
|
|
endif(OPTION_TRIM_PATH_PREFIX)
|
|
|
|
|
2020-06-27 18:28:54 +00:00
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
# Sensible default if no build type specified
|
2022-11-03 19:00:25 +00:00
|
|
|
add_compile_options(-O2)
|
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
add_compile_options(-DNDEBUG)
|
|
|
|
endif()
|
2020-06-27 18:28:54 +00:00
|
|
|
endif(NOT CMAKE_BUILD_TYPE)
|
|
|
|
|
2020-06-04 12:38:56 +00:00
|
|
|
# Ninja processes the output so the output from the compiler
|
|
|
|
# isn't directly to a terminal; hence, the default is
|
|
|
|
# non-coloured output. We can override this to get nicely
|
|
|
|
# coloured output, but since that might yield odd results with
|
|
|
|
# IDEs, we extract it to an option.
|
2020-09-25 11:55:25 +00:00
|
|
|
if(OPTION_FORCE_COLORED_OUTPUT)
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2020-06-04 12:38:56 +00:00
|
|
|
add_compile_options (-fdiagnostics-color=always)
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
2020-06-04 12:38:56 +00:00
|
|
|
add_compile_options (-fcolor-diagnostics)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-flifetime-dse=1" LIFETIME_DSE_FOUND)
|
|
|
|
|
|
|
|
add_compile_options(
|
|
|
|
# GCC 4.2+ automatically assumes that signed overflows do
|
|
|
|
# not occur in signed arithmetics, whereas we are not
|
|
|
|
# sure that they will not happen. It furthermore complains
|
|
|
|
# about its own optimized code in some places.
|
|
|
|
"-fno-strict-overflow"
|
|
|
|
|
|
|
|
# Prevent optimisation supposing enums are in a range specified by the standard
|
|
|
|
# For details, see http://gcc.gnu.org/PR43680
|
|
|
|
"-fno-tree-vrp"
|
|
|
|
|
|
|
|
# -flifetime-dse=2 (default since GCC 6) doesn't play
|
|
|
|
# well with our custom pool item allocator
|
|
|
|
"$<$<BOOL:${LIFETIME_DSE_FOUND}>:-flifetime-dse=1>"
|
2023-05-10 17:35:11 +00:00
|
|
|
|
|
|
|
# We have a fight between clang wanting std::move() and gcc not wanting it
|
|
|
|
# and of course they both warn when the other compiler is happy
|
|
|
|
"$<$<COMPILE_LANGUAGE:CXX>:-Wno-redundant-move>"
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
)
|
2024-02-24 22:58:31 +00:00
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11)
|
|
|
|
add_compile_options(
|
|
|
|
# GCC >= 11 has false positives if operator new is inlined but operator delete isn't, or vice versa
|
|
|
|
"-Wno-mismatched-new-delete"
|
|
|
|
)
|
|
|
|
endif()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2020-06-27 13:50:13 +00:00
|
|
|
|
2021-01-02 00:09:11 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
2021-01-07 16:04:01 +00:00
|
|
|
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
|
2021-01-02 00:09:11 +00:00
|
|
|
add_compile_options(
|
2021-02-01 17:07:34 +00:00
|
|
|
-fno-stack-check
|
2021-01-02 00:09:11 +00:00
|
|
|
)
|
2021-02-01 17:07:34 +00:00
|
|
|
|
2021-01-07 16:04:01 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-mno-sse4" NO_SSE4_FOUND)
|
|
|
|
|
|
|
|
if(NO_SSE4_FOUND)
|
|
|
|
add_compile_options(
|
|
|
|
# Don't use SSE4 for general sources to increase compatibility.
|
|
|
|
-mno-sse4
|
|
|
|
)
|
|
|
|
endif()
|
2021-01-02 00:09:11 +00:00
|
|
|
endif()
|
2020-10-14 16:38:23 +00:00
|
|
|
endif()
|
2022-06-25 11:05:00 +00:00
|
|
|
|
2023-02-20 17:44:54 +00:00
|
|
|
if(OPTION_COMPRESS_DEBUG)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-gz" GZ_FOUND)
|
|
|
|
|
|
|
|
if(GZ_FOUND)
|
|
|
|
# Compress debug sections.
|
|
|
|
add_compile_options(-gz)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -gz")
|
|
|
|
endif()
|
|
|
|
endif(OPTION_COMPRESS_DEBUG)
|
|
|
|
|
2023-02-20 21:11:30 +00:00
|
|
|
if(OPTION_LTO)
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-flto" LTO_FOUND)
|
|
|
|
|
|
|
|
if(LTO_FOUND)
|
|
|
|
# Enable LTO.
|
|
|
|
add_compile_options(-flto)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
|
|
|
|
endif()
|
|
|
|
endif(OPTION_LTO)
|
|
|
|
|
2022-06-25 11:05:00 +00:00
|
|
|
if (OPTION_NO_WARN_UNINIT)
|
|
|
|
add_compile_options(-Wno-maybe-uninitialized -Wno-uninitialized)
|
|
|
|
endif (OPTION_NO_WARN_UNINIT)
|
2023-03-05 13:23:08 +00:00
|
|
|
|
|
|
|
if (EMSCRIPTEN)
|
|
|
|
add_compile_options(-Wno-deprecated-builtins)
|
|
|
|
endif()
|
2020-09-25 11:55:25 +00:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
add_compile_options(
|
|
|
|
-Wall
|
|
|
|
# warning #873: function ... ::operator new ... has no corresponding operator delete ...
|
|
|
|
-wd873
|
|
|
|
# warning #1292: unknown attribute "fallthrough"
|
|
|
|
-wd1292
|
|
|
|
# warning #1899: multicharacter character literal (potential portability problem)
|
|
|
|
-wd1899
|
|
|
|
# warning #2160: anonymous union qualifier is ignored
|
|
|
|
-wd2160
|
|
|
|
)
|
2020-09-25 11:55:25 +00:00
|
|
|
else()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
message(FATAL_ERROR "No warning flags are set for this compiler yet; please consider creating a Pull Request to add support for this compiler.")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
|
2021-05-20 22:21:38 +00:00
|
|
|
if(NOT WIN32 AND NOT HAIKU)
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
# rdynamic is used to get useful stack traces from crash reports.
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2023-01-02 18:58:53 +00:00
|
|
|
|
|
|
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
# workaround for MacOS 10.13 and below which does not support std::variant, etc
|
|
|
|
add_definitions(-D_LIBCPP_DISABLE_AVAILABILITY)
|
|
|
|
endif()
|
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.
Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.
This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.
Addtiionally, this heavily improves our detection of libraries, etc.
2019-04-07 09:57:55 +00:00
|
|
|
endmacro()
|