aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt38
1 files changed, 37 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 761929d..e7f39c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,6 +5,42 @@ project(bhlib LANGUAGES C)
set(CMAKE_C_STANDARD 90)
set(CMAKE_C_STANDARD_REQUIRED ON)
+# Asan profile
+get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+
+if(isMultiConfig)
+ if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
+ list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
+ endif()
+else()
+ set(allowedBuildTypes Asan Debug Release RelWithDebInfo MinSizeRel)
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
+
+ if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
+ message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
+ endif()
+endif()
+
+set(CMAKE_C_FLAGS_ASAN
+ "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address,undefined -fno-omit-frame-pointer" CACHE STRING
+ "Flags used by the C compiler for Asan build type or configuration." FORCE
+)
+
+set(CMAKE_CXX_FLAGS_ASAN
+ "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined -fno-omit-frame-pointer" CACHE STRING
+ "Flags used by the C++ compiler for Asan build type or configuration." FORCE
+)
+
+set(CMAKE_EXE_LINKER_FLAGS_ASAN
+ "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined -static-libasan" CACHE STRING
+ "Linker flags to be used to create executables for Asan build type." FORCE
+)
+
+set(CMAKE_SHARED_LINKER_FLAGS_ASAN
+ "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined -static-libasan" CACHE STRING
+ "Linker lags to be used to create shared libraries for Asan build type." FORCE
+)
+
# Project includes
include(CheckIPOSupported)
include(CheckIncludeFile)
@@ -84,7 +120,7 @@ target_link_libraries(bhlib PUBLIC m)
if(MSVC)
target_compile_options(bhlib PRIVATE /W4 /WX)
else()
- target_compile_options(bhlib PRIVATE -Wall -Wextra -Wpedantic -Werror)
+ target_compile_options(bhlib PRIVATE -Wall -Wextra -Wpedantic -Werror -fstrict-aliasing)
endif()
# Coverage