Skip to content

Commit ce0d1d2

Browse files
authored
[CMake] Add cmake option for enabling address sanitizer (#604)
1 parent 6656e84 commit ce0d1d2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cmake/compilers.cmake

+11
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ if (NOT IS_VS6_BUILD)
3737
add_compile_options(/Zc:__cplusplus)
3838
endif()
3939
endif()
40+
41+
if(GENZH_BUILD_OPTION_ASAN)
42+
if(MSVC)
43+
set(ENV{ASAN_OPTIONS} "shadow_scale=2")
44+
add_compile_options(/fsanitize=address)
45+
add_link_options(/fsanitize=address)
46+
else()
47+
add_compile_options(-fsanitize=address)
48+
add_link_options(-fsanitize=address)
49+
endif()
50+
endif()

cmake/config.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ option(GENZH_BUILD_GENERALS "Build Generals code." ON)
66
option(GENZH_BUILD_INTERNAL "Build code with the \"Internal\" configuration." OFF)
77
option(GENZH_BUILD_PROFILE "Build code with the \"Profile\" configuration." OFF)
88
option(GENZH_BUILD_DEBUG "Build code with the \"Debug\" configuration." OFF)
9+
option(GENZH_BUILD_OPTION_ASAN "Build code with Address Sanitizer." OFF)
910

1011
if(NOT GENZH_BUILD_ZEROHOUR AND NOT GENZH_BUILD_GENERALS)
1112
set(GENZH_BUILD_ZEROHOUR TRUE)
@@ -17,6 +18,7 @@ add_feature_info(GeneralsStuff GENZH_BUILD_GENERALS "Build Generals code")
1718
add_feature_info(InternalBuild GENZH_BUILD_INTERNAL "Building as an \"Internal\" build")
1819
add_feature_info(ProfileBuild GENZH_BUILD_PROFILE "Building as a \"Profile\" build")
1920
add_feature_info(DebugBuild GENZH_BUILD_DEBUG "Building as a \"Debug\" build")
21+
add_feature_info(AddressSanitizer GENZH_BUILD_OPTION_ASAN "Building with address sanitizer")
2022

2123

2224
### GAME MEMORY OPTIONS ###

0 commit comments

Comments
 (0)