Skip to content

Commit

Permalink
cmake: don't check c++ compiler flags for asan when CXX is not enabled
Browse files Browse the repository at this point in the history
Backport of fd2b9c0 to SDL2
  • Loading branch information
cgutman committed Sep 21, 2024
1 parent c43b976 commit a4a8a29
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3210,9 +3210,11 @@ macro(check_add_debug_flag FLAG SUFFIX)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif()

check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
if (HAS_CXX_${SUFFIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
if(CMAKE_CXX_COMPILER)
check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
if (HAS_CXX_${SUFFIX})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endif()
endmacro()

Expand All @@ -3231,18 +3233,20 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG)

set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})

check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
if (HAS_C_FLAG_${ASAN_FLAG})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
endif()

if (HAS_CXX_${ASAN_FLAG})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
if(CMAKE_CXX_COMPILER)
check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
if (HAS_CXX_${ASAN_FLAG})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
endif()
endif()

set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
set(HAVE_ASAN ON)
endif()
Expand Down

0 comments on commit a4a8a29

Please sign in to comment.