target_compile_options(${PROJECT_NAME}
PRIVATE
# Enable All Warnings
$<$<CXX_COMPILER_ID:MSVC>:/W4 /sdl>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic>
PRIVATE
# Enable Optimizations
$<$<CXX_COMPILER_ID:MSVC>:
$<$<CONFIG:Debug>:/Od /GS /RTC1>
$<$<CONFIG:Release>:/O2 /Oi /Ot /GL /Gy>
>
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:
$<$<CONFIG:Debug>:-O0>
$<$<CONFIG:Release>:-O3 -march=native>
>
PRIVATE
# Enable Address Sanitizer
$<$<CXX_COMPILER_ID:GNU,Clang>:
$<$<VERSION_GREATER:${CMAKE_VERSION},3.12>:
$<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>
$<$<CONFIG:RelWithDebInfo>:-fsanitize=address -fno-omit-frame-pointer>
>
>
)
if (${CMAKE_VERSION} VERSION_GREATER 3.12)
target_link_options(${PROJECT_NAME}
PRIVATE
# Enable Address Sanitizer
$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:
$<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>
$<$<CONFIG:RelWithDebInfo>:-fsanitize=address -fno-omit-frame-pointer>
>
)
endif()
标签:Enable,CMake,Configure,Generator,frame,PRIVATE,fsanitize,address,pointer
From: https://www.cnblogs.com/fang-d/p/16795582.html