From bb84044718f0c5097e6148a71e2fd6bcbe135fc6 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Thu, 14 Jul 2022 17:51:36 +0200 Subject: [PATCH 1/2] Add ASan build type to CMake --- CMakeLists.txt | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67f87693..65faf31d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,13 @@ project( # Set default build type and also populate a list of available options get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -if (NOT is_multi_config) +if (is_multi_config) + if(NOT "ASan" IN_LIST CMAKE_CONFIGURATION_TYPES) + list(APPEND CMAKE_CONFIGURATION_TYPES ASan) + endif() +elseif (NOT is_multi_config) set(default_build_type "Release") - set(allowed_build_types Debug Release MinSizeRel RelWithDebInfo) + set(allowed_build_types ASan Debug Release MinSizeRel RelWithDebInfo) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowed_build_types}") @@ -50,10 +54,32 @@ if (NOT is_multi_config) CACHE STRING "Choose the type of build." FORCE ) elseif (NOT CMAKE_BUILD_TYPE IN_LIST allowed_build_types) - message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}") + message(WARNING "Unknown build type '${CMAKE_BUILD_TYPE}'. " + "Defaulting to '${default_build_type}'") + set(CMAKE_BUILD_TYPE "${default_build_type}" + CACHE STRING "Choose the type of build." FORCE + ) endif () endif () +# define the desired flags for the ASan build type +set(CMAKE_C_FLAGS_ASAN + "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -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 -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_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address" 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" CACHE STRING + "Linker lags to be used to create shared libraries for ASan build type." FORCE) + + # make sure that debug versions for targets are used (if provided) in Debug mode set_property(GLOBAL APPEND PROPERTY DEBUG_CONFIGURATIONS Debug) -- GitLab From 748bde5ed553f890cab34b88a2f1ea9b5a3f7536 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Thu, 14 Jul 2022 18:57:53 +0200 Subject: [PATCH 2/2] Update file_options --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65faf31d..377bbb6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,7 +218,7 @@ message(STATUS "[${PROJECT_NAME}] Downloading and building file_options") FetchContent_Declare( file_options GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/file_options - GIT_TAG b2de92b3755e3391595bb368573b82abed16978d # v0.1.0-pre + GIT_TAG 240028735a4c28fd188a83ff9b8f350c0094c43d # v0.1.0-pre GIT_SHALLOW ON GIT_PROGRESS ON ) -- GitLab