From c7ad18cb6cf97d92cce22d972ea8eaadacfd68f7 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Fri, 21 Feb 2025 10:38:04 -0800 Subject: [PATCH 1/2] Support sanitizer for C++ projects --- cmake/AwsSanitizers.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/AwsSanitizers.cmake b/cmake/AwsSanitizers.cmake index 54202006e..998eb70d2 100644 --- a/cmake/AwsSanitizers.cmake +++ b/cmake/AwsSanitizers.cmake @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0. include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) option(ENABLE_SANITIZERS "Enable sanitizers in debug builds" OFF) set(SANITIZERS "address;undefined" CACHE STRING "List of sanitizers to build with") @@ -32,7 +33,12 @@ function(aws_check_sanitizer sanitizer) # Need to set this here so that the flag is passed to the linker set(CMAKE_REQUIRED_FLAGS ${sanitizer_test_flag}) - check_c_compiler_flag(${sanitizer_test_flag} ${out_variable}) + if(${CMAKE_C_COMPILER_LOADED}) + check_c_compiler_flag(${sanitizer_test_flag} ${out_variable}) + endif() + if(${CMAKE_CXX_COMPILER_LOADED}) + check_cxx_compiler_flag(${sanitizer_test_flag} ${out_variable}) + endif() else() set(${out_variable} 0 PARENT_SCOPE) endif() From 2b5ed5ef558c6fed04585c7b53a119fde15d4e7c Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Fri, 21 Feb 2025 11:04:13 -0800 Subject: [PATCH 2/2] Add message that sanitizer check failed --- cmake/AwsSanitizers.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/AwsSanitizers.cmake b/cmake/AwsSanitizers.cmake index 998eb70d2..ca1be9e02 100644 --- a/cmake/AwsSanitizers.cmake +++ b/cmake/AwsSanitizers.cmake @@ -39,6 +39,10 @@ function(aws_check_sanitizer sanitizer) if(${CMAKE_CXX_COMPILER_LOADED}) check_cxx_compiler_flag(${sanitizer_test_flag} ${out_variable}) endif() + + if(NOT ${out_variable}) + message(STATUS "Check ${out_variable} failed") + endif() else() set(${out_variable} 0 PARENT_SCOPE) endif()