1##============================================================================ 2## Copyright (c) Kitware, Inc. 3## All rights reserved. 4## See LICENSE.txt for details. 5## 6## This software is distributed WITHOUT ANY WARRANTY; without even 7## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 8## PURPOSE. See the above copyright notice for more information. 9##============================================================================ 10 11#----------------------------------------------------------------------------- 12# check if this is a sanitizer build. If so, set up the environment. 13 14function(vtkm_check_sanitizer_build) 15 16 # each line is a separate entry 17 set(blacklist_file_content " 18src:${VTKm_SOURCE_DIR}/vtkm/thirdparty/ 19") 20 set (sanitizer_blacklist "${VTKm_BINARY_DIR}/sanitizer_blacklist.txt") 21 file(WRITE "${sanitizer_blacklist}" "${blacklist_file_content}") 22 23 set(sanitizer_flags ) 24 foreach(sanitizer IN LISTS VTKm_USE_SANITIZER) 25 string(APPEND sanitizer_flags "-fsanitize=${sanitizer} ") 26 endforeach() 27 # Add the compiler flags for blacklist 28 if(VTKM_COMPILER_IS_CLANG) 29 string(APPEND sanitizer_flags "\"-fsanitize-blacklist=${sanitizer_blacklist}\"") 30 endif() 31 foreach (entity C CXX SHARED_LINKER EXE_LINKER) 32 set (CMAKE_${entity}_FLAGS "${CMAKE_${entity}_FLAGS} ${sanitizer_flags}" PARENT_SCOPE) 33 endforeach () 34 35endfunction() 36 37if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR 38 CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") 39 set(CMAKE_COMPILER_IS_CLANGXX 1) 40endif() 41 42if(VTKM_COMPILER_IS_CLANG OR VTKM_COMPILER_IS_GNU) 43 vtkm_option(VTKm_ENABLE_SANITIZER "Build with sanitizer support." OFF) 44 mark_as_advanced(VTKm_ENABLE_SANITIZER) 45 46 set(VTKm_USE_SANITIZER "address" CACHE STRING "The sanitizer to use") 47 mark_as_advanced(VTKm_USE_SANITIZER) 48 49 if(VTKm_ENABLE_SANITIZER) 50 vtkm_check_sanitizer_build() 51 endif() 52 53endif() 54