diff --git a/CMakeLists.txt b/CMakeLists.txt index 67f87693e075ce4c992db8c295074d438bf8e300..377bbb6a9d201792c68edd662804b9ea9340d025 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) @@ -192,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 )