Skip to content

Commit

Permalink
Merge branch 'dev' into Resistance_tickfix2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhobean committed Feb 13, 2025
2 parents 66e37a9 + b5a5994 commit 593075e
Show file tree
Hide file tree
Showing 20 changed files with 339 additions and 209 deletions.
39 changes: 19 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ option(USE_UBSAN "Enable Undefined Behavior Sanitizer." FALSE)
option(USE_LSAN "Enable LeakSanitizer." FALSE)
option(USE_MSAN "Enable MemorySanitizer." FALSE)

set(ENABLED_SANITIZER CACHE INTERNAL BOOL FALSE)
set(ENABLED_SANITIZER FALSE CACHE INTERNAL BOOL "Am i using a sanitizer?")
if(USE_ASAN OR USE_MSAN OR USE_LSAN OR USE_MSAN)
set(ENABLED_SANITIZER TRUE)
endif()
Expand Down Expand Up @@ -197,6 +197,11 @@ if(SINGLE_TARGET)
#set_target_properties(spheresvr_release PROPERTIES CXX_EXTENSIONS OFF)
#target_compile_features(spheresvr_release PUBLIC cxx_std_20)
target_precompile_headers(spheresvr_release ${pch_options})

add_custom_command(TARGET spheresvr_release POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:spheresvr_release>
COMMENT "Stripping executable"
)
endif()
if(("${CMAKE_BUILD_TYPE}" STREQUAL "") OR (${CMAKE_BUILD_TYPE} MATCHES "(N|n?)ightly"))
set(TARGETS ${TARGETS} spheresvr_nightly)
Expand All @@ -210,6 +215,11 @@ if(SINGLE_TARGET)
#set_target_properties(spheresvr_nightly PROPERTIES CXX_EXTENSIONS OFF)
#target_compile_features(spheresvr_nightly PUBLIC cxx_std_20)
target_precompile_headers(spheresvr_nightly ${pch_options})

add_custom_command(TARGET spheresvr_nightly POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:spheresvr_nightly>
COMMENT "Stripping executable"
)
endif()
if(("${CMAKE_BUILD_TYPE}" STREQUAL "") OR (${CMAKE_BUILD_TYPE} MATCHES "(D|d?)ebug"))
set(TARGETS ${TARGETS} spheresvr_debug)
Expand All @@ -233,30 +243,19 @@ else(SINGLE_TARGET)
#set_target_properties(spheresvr PROPERTIES CXX_EXTENSIONS OFF)
#target_compile_features(spheresvr PUBLIC cxx_std_20)
target_precompile_headers(spheresvr ${pch_options})

# To be tested
#add_custom_command(TARGET spheresvr POST_BUILD
# $<$<CONFIG:Release>:COMMAND ${CMAKE_STRIP} $<TARGET_FILE:spheresvr>>
# $<$<CONFIG:Nightly>:COMMAND ${CMAKE_STRIP} $<TARGET_FILE:spheresvr>>
# COMMENT "Stripping executable"
#)
endif(SINGLE_TARGET)

# --------------------

message(STATUS)
include("${CMAKE_SOURCE_DIR}/cmake/CompilerFlagsChecker.cmake")

# --------------------

if(USE_ASAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} ADDRESS_SANITIZER)
endif()
if(USE_UBSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} UNDEFINED_BEHAVIOR_SANITIZER)
endif()
if(USE_LSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} LEAK_SANITIZER)
endif()
if(USE_MSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} MEMORY_SANITIZER)
endif()
if(ENABLED_SANITIZER)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} _SANITIZERS)
endif()
include("${CMAKE_SOURCE_DIR}/cmake/CommonCompilerFlags.cmake")

# --------------------

Expand Down
22 changes: 22 additions & 0 deletions cmake/CommonCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(list_explicit_compiler_options_all CACHE INTERNAL STRING)
set(list_explicit_linker_options_all CACHE INTERNAL STRING)
include("${CMAKE_SOURCE_DIR}/cmake/CompilerFlagsBase.cmake")
include("${CMAKE_SOURCE_DIR}/cmake/CompilerFlagsChecker.cmake")

# --------------------

if(USE_ASAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} ADDRESS_SANITIZER)
endif()
if(USE_UBSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} UNDEFINED_BEHAVIOR_SANITIZER)
endif()
if(USE_LSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} LEAK_SANITIZER)
endif()
if(USE_MSAN)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} MEMORY_SANITIZER)
endif()
if(ENABLED_SANITIZER)
set(PREPROCESSOR_DEFS_EXTRA ${PREPROCESSOR_DEFS_EXTRA} _SANITIZERS)
endif()
98 changes: 98 additions & 0 deletions cmake/CompilerFlagsBase.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
message(STATUS "Setting base compiler flags...")

if(NOT MSVC)
# Compiler option flags (minimum).
list(
APPEND
compiler_options_base
-pthread
-fexceptions
-fnon-call-exceptions
-pipe
-ffast-math
# Place each function and variable into its own section, allowing the linker to remove unused ones.
#-ffunction-sections
#-fdata-sections
#-flto # Supported even by ancient compilers... also needed to benefit the most from the two flags above.
)
list(
APPEND
compiler_options_warning_base
-Werror
-Wall
-Wextra
-Wpedantic
)

# Linker option flags (minimum).
list(
APPEND
linker_options_base
-pthread
-dynamic
#-flto
)

message(STATUS "Adding the following base compiler options: ${compiler_options_base}.")
message(STATUS "Adding the following base compiler warning options: ${compiler_options_warning_base}.")
message(STATUS "Adding the following base linker options: ${linker_options_base}.")

#-- Store once the compiler flags, only the ones specific per build type.

if("${ENABLED_SANITIZER}" STREQUAL "TRUE")
# -fno-omit-frame-pointer disables a good optimization which might corrupt the debugger stack trace.
set(local_compile_options_nondebug -ggdb3 -Og -fno-omit-frame-pointer -fno-inline)
set(local_link_options_nondebug)
else()
# If using ThinLTO: -flto=thin -fsplit-lto-unit
# If using classic/monolithic LTO: -flto=full -fvirtual-function-elimination
# Probably useful when using lto: -ffunction-sections -fdata-sections
set(local_compile_options_nondebug -O3)# -flto)
set(local_link_options_nondebug)#-flto)
endif()

set(custom_compile_options_release
${local_compile_options_nondebug}
-flto=full
-fvirtual-function-elimination
-ffunction-sections
-fdata-sections
CACHE INTERNAL STRING
)
set(custom_compile_options_nightly
${local_compile_options_nondebug}
CACHE INTERNAL STRING
)
set(custom_compile_options_debug
-ggdb3 -O0 -fno-omit-frame-pointer -fno-inline
CACHE INTERNAL STRING
)

set(custom_link_options_release
${local_link_options_nondebug}
-flto=full
CACHE INTERNAL STRING
)
set(custom_link_options_nightly
${local_link_options_nondebug}
CACHE INTERNAL STRING
)
set(custom_link_options_debug
""
CACHE INTERNAL STRING
)

if(TARGET spheresvr_release)
message(STATUS "Adding the following compiler options specific to 'Release' build: ${custom_compile_options_release}.")
message(STATUS "Adding the following linker options specific to 'Release' build: ${custom_link_options_release}.")
endif()
if(TARGET spheresvr_nightly)
message(STATUS "Adding the following compiler options specific to 'Nightly' build: ${custom_compile_options_nightly}.")
message(STATUS "Adding the following linker options specific to 'Nightly' build: ${custom_link_options_nightly}.")
endif()
if(TARGET spheresvr_debug)
message(STATUS "Adding the following compiler options specific to 'Debug' build: ${custom_compile_options_debug}.")
message(STATUS "Adding the following linker options specific to 'Debug' build: ${custom_link_options_debug}.")
endif()

endif()
37 changes: 11 additions & 26 deletions cmake/CompilerFlagsChecker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ message(STATUS "Checking available compiler flags...")
if(NOT MSVC)
message(STATUS "-- Compilation options:")

# Compiler option flags.
list(
APPEND
compiler_options_base
-pthread
-fexceptions
-fnon-call-exceptions
-pipe
-ffast-math
)
list(APPEND base_compiler_options_warning -Werror;-Wall;-Wextra;-Wpedantic)

# Linker flags (warnings)
# Linker flags (warnings).
#check_cxx_compiler_flag("-Wl,--fatal-warnings" COMP_LINKER_HAS_FATAL_WARNINGS_V1)
#check_cxx_compiler_flag("-Wl,-fatal_warnings" COMP_LINKER_HAS_FATAL_WARNINGS_V2)
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
Expand Down Expand Up @@ -213,6 +201,10 @@ if(NOT MSVC)
list(APPEND checked_linker_options_all "-Wl,-fatal_warnings")
endif()

#if(COMP_HAS_LTO)
# list(APPEND checked_compiler_options "-flto")
#endif()

if(COMP_HAS_FNO_EXPENSIVE_OPTIMIZATIONS)
list(APPEND checked_compiler_options "-fno-expensive-optimizations")
endif()
Expand Down Expand Up @@ -456,8 +448,6 @@ if(NOT MSVC)
list(
APPEND
list_explicit_compiler_options_all
${compiler_options_base}
${base_compiler_options_warning}
${checked_compiler_options}
${checked_compiler_options_asan}
${checked_compiler_options_ubsan}
Expand All @@ -468,18 +458,14 @@ if(NOT MSVC)
${checked_compiler_warnings_disabled}
)

list(APPEND list_explicit_linker_options_all ${checked_linker_options_all};-pthread;-dynamic)

#string(JOIN " " string_checked_compiler_options_all ${list_checked_compiler_options_all})
#set(string_checked_compiler_options_all CACHE INTERNAL STRING)
set(list_explicit_compiler_options_all CACHE INTERNAL STRING)
set(list_explicit_linker_options_all CACHE INTERNAL STRING)
list(
APPEND
list_explicit_linker_options_all
${checked_linker_options_all}
)

# --

message(STATUS "Adding the following base compiler options: ${compiler_options_base}")
message(STATUS "Adding the following base compiler warning options: ${base_compiler_options_warning}")

message(STATUS "Adding the following conditional compiler options: ${checked_compiler_options}.")
if(COMP_HAS_ASAN)
message(STATUS "Adding the following conditional compiler options for ASan: ${checked_compiler_options_asan}.")
Expand Down Expand Up @@ -507,13 +493,12 @@ if(NOT MSVC)
STATUS
"Adding the following conditional compiler warnings ignore options: ${checked_compiler_warnings_disabled}."
)
message(STATUS "Adding the following linker options: ${list_explicit_linker_options_all}.")
message(STATUS "Adding the following conditional linker options: ${checked_linker_options_all}.")

elseif(MSVC)
list(
APPEND
list_explicit_compiler_options_all
${base_compiler_options_msvc}
${checked_compiler_options_msvc}
)

Expand Down
36 changes: 17 additions & 19 deletions cmake/toolchains/include/Linux-Clang_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function(toolchain_exe_stuff_common)
#-- Validate sanitizers options and store them between the common compiler flags.

# From https://clang.llvm.org/docs/ClangCommandLineReference.html
# -static-libsan Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)
# -static-libsan Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on Darwin)

#string(REPLACE ";" " " CXX_FLAGS_EXTRA "${CXX_FLAGS_EXTRA}")

Expand All @@ -27,29 +27,14 @@ function(toolchain_exe_stuff_common)

#-- Apply compiler flags, only the ones specific per build type.

# -fno-omit-frame-pointer disables a good optimization which may corrupt the debugger stack trace.
set(local_compile_options_extra)
if(ENABLED_SANITIZER OR TARGET spheresvr_debug)
set(local_compile_options_extra -fno-omit-frame-pointer -fno-inline)
endif()
if(TARGET spheresvr_release)
target_compile_options(
spheresvr_release
PUBLIC -O3 -flto=full -fvirtual-function-elimination ${local_compile_options_extra}
)
target_compile_options(spheresvr_release PUBLIC ${custom_compile_options_release})
endif()
if(TARGET spheresvr_nightly)
if(ENABLED_SANITIZER)
target_compile_options(spheresvr_nightly PUBLIC -ggdb3 -Og ${local_compile_options_extra})
else()
target_compile_options(
spheresvr_nightly
PUBLIC -O3 -flto=full -fvirtual-function-elimination ${local_compile_options_extra}
)
endif()
target_compile_options(spheresvr_nightly PUBLIC ${custom_compile_options_nightly})
endif()
if(TARGET spheresvr_debug)
target_compile_options(spheresvr_debug PUBLIC -ggdb3 -O0 ${local_compile_options_extra})
target_compile_options(spheresvr_debug PUBLIC ${custom_compile_options_debug})
endif()

#-- Store common linker flags.
Expand All @@ -62,6 +47,19 @@ function(toolchain_exe_stuff_common)
-static-libgcc> # no way to safely statically link against libc
)

#-- Apply linker flags, only the ones specific per build type.

if(TARGET spheresvr_release)
target_link_options(spheresvr_release PUBLIC ${custom_link_options_release})
endif()
if(TARGET spheresvr_nightly)
target_link_options(spheresvr_nightly PUBLIC ${custom_link_options_nightly})
endif()
if(TARGET spheresvr_debug)
target_link_options(spheresvr_debug PUBLIC ${custom_link_options_debug})
endif()


#-- Store common define macros.

set(cxx_compiler_definitions_common
Expand Down
27 changes: 15 additions & 12 deletions cmake/toolchains/include/Linux-GNU_common.inc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,14 @@ function(toolchain_exe_stuff_common)

#-- Apply compiler flags, only the ones specific per build type.

# -fno-omit-frame-pointer disables a good optimization which may corrupt the debugger stack trace.
set(local_compile_options_extra)
if(ENABLED_SANITIZER OR TARGET spheresvr_debug)
set(local_compile_options_extra -fno-omit-frame-pointer -fno-inline)
endif()
if(TARGET spheresvr_release)
target_compile_options(spheresvr_release PUBLIC -s -O3 ${local_compile_options_extra})
target_compile_options(spheresvr_release PUBLIC ${custom_compile_options_release})
endif()
if(TARGET spheresvr_nightly)
if(ENABLED_SANITIZER)
target_compile_options(spheresvr_nightly PUBLIC -ggdb3 -Og ${local_compile_options_extra})
else()
target_compile_options(spheresvr_nightly PUBLIC -O3 ${local_compile_options_extra})
endif()
target_compile_options(spheresvr_nightly PUBLIC ${custom_compile_options_nightly})
endif()
if(TARGET spheresvr_debug)
target_compile_options(spheresvr_debug PUBLIC -ggdb3 -O0 ${local_compile_options_extra})
target_compile_options(spheresvr_debug PUBLIC ${custom_compile_options_debug})
endif()

#-- Store common linker flags.
Expand All @@ -52,6 +43,18 @@ function(toolchain_exe_stuff_common)
>
)

#-- Apply linker flags, only the ones specific per build type.

if(TARGET spheresvr_release)
target_link_options(spheresvr_release PUBLIC ${custom_link_options_release})
endif()
if(TARGET spheresvr_nightly)
target_link_options(spheresvr_nightly PUBLIC ${custom_link_options_nightly})
endif()
if(TARGET spheresvr_debug)
target_link_options(spheresvr_debug PUBLIC ${custom_link_options_debug})
endif()

#-- Store common define macros.

set(cxx_compiler_definitions_common
Expand Down
Loading

0 comments on commit 593075e

Please sign in to comment.