mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
build: Enabled various hardening flags on GCC and Clang
This commit is contained in:
@@ -628,21 +628,24 @@ endmacro()
|
||||
|
||||
macro(setupCompilerFlags target)
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
addCommonFlag("/W4" ${target})
|
||||
addCommonFlag("/wd4242" ${target})
|
||||
addCommonFlag("/wd4244" ${target})
|
||||
addCommonFlag("/wd4267" ${target})
|
||||
addCommonFlag("/wd4996" ${target})
|
||||
addCommonFlag("/wd4127" ${target})
|
||||
|
||||
if (IMHEX_STRICT_WARNINGS)
|
||||
addCommonFlag("/W4" ${target})
|
||||
addCommonFlag("/wd4242" ${target})
|
||||
addCommonFlag("/wd4244" ${target})
|
||||
addCommonFlag("/wd4267" ${target})
|
||||
addCommonFlag("/wd4996" ${target})
|
||||
addCommonFlag("/wd4127" ${target})
|
||||
addCommonFlag("/WX" ${target})
|
||||
endif()
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
addCommonFlag("-Wall" ${target})
|
||||
addCommonFlag("-Wextra" ${target})
|
||||
addCommonFlag("-Wpedantic" ${target})
|
||||
|
||||
# Define strict compilation flags
|
||||
if (IMHEX_STRICT_WARNINGS)
|
||||
addCommonFlag("-Wall" ${target})
|
||||
addCommonFlag("-Wextra" ${target})
|
||||
addCommonFlag("-Wpedantic" ${target})
|
||||
addCommonFlag("-Werror" ${target})
|
||||
addCommonFlag("-Werror" ${target})
|
||||
endif()
|
||||
|
||||
if (UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
@@ -656,6 +659,11 @@ macro(setupCompilerFlags target)
|
||||
addCCXXFlag("-Wno-array-bounds" ${target})
|
||||
addCCXXFlag("-Wno-deprecated-declarations" ${target})
|
||||
addCCXXFlag("-Wno-unknown-pragmas" ${target})
|
||||
|
||||
# Enable hardening flags
|
||||
addCommonFlag("-U_FORTIFY_SOURCE" ${target})
|
||||
addCommonFlag("-D_FORTIFY_SOURCE=3" ${target})
|
||||
addCommonFlag("-fstack-protector-strong" ${target})
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
@@ -669,6 +677,12 @@ macro(setupCompilerFlags target)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LLVM_PREFIX}/lib/c++")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${LLVM_PREFIX}/lib/c++")
|
||||
addCCXXFlag("-Wno-unknown-warning-option" ${target})
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_compile_definitions(_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
|
||||
else()
|
||||
add_compile_definitions(_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
|
||||
Reference in New Issue
Block a user