Unverified Commit 8f4e18ba authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

change logic of selecting and allowing sanitizer options to be compatible with...

change logic of selecting and allowing sanitizer options to be compatible with unsupported compilers
parent 0249cf75
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
    endif()
  endif()
endif()
if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))

set(ENABLE_SANITIZER "none" CACHE STRING "Select a code sanitizer option (none (default), address, thread, undefined)")
mark_as_advanced(ENABLE_SANITIZER)
set(ENABLE_SANITIZER_VALUES none address thread undefined)
@@ -263,6 +263,7 @@ if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQU
validate_option(ENABLE_SANITIZER ENABLE_SANITIZER_VALUES)
string(TOLOWER ${ENABLE_SANITIZER} ENABLE_SANITIZER)
if(NOT ENABLE_SANITIZER STREQUAL "none")
  if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
    if(CMAKE_VERSION VERSION_LESS 3.13)
      if(CMAKE_CXX_FLAGS)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}")
@@ -273,6 +274,9 @@ if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQU
      target_compile_options(lammps PUBLIC -fsanitize=${ENABLE_SANITIZER})
      target_link_options(lammps PUBLIC -fsanitize=${ENABLE_SANITIZER})
    endif()
  else()
    message(WARNING "ENABLE_SANITIZER option not supported by ${CMAKE_CXX_COMPILER_ID} compilers. Ignoring.")
    set(ENABLE_SANITIZER "none")
  endif()
endif()