Add Asan profile, fix multiple bugs.

Added Asan profile to help catch and fix various bugs (and indeed, there
were few of them).

Additionally, fixed bhunit macro to process arguments only once.
This commit is contained in:
2025-01-29 09:19:34 +03:00
parent 47c21a2035
commit 6ede63e18f
8 changed files with 78 additions and 21 deletions

View File

@@ -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