travis: try to fix ubsan for clang-old
[awesomized/libmemcached] / CMake / CheckDebug.cmake
index 2701bdfd0ab3107c5cdf4b11364acb5b4eb93bff..433682998b17d171a023f94e14c95fe9c1ea45ac 100644 (file)
@@ -47,8 +47,13 @@ function(check_debug)
                 check_cxx_compiler_flag(-fsanitize=address HAVE_ASAN)
                 cmake_pop_check_state()
                 if(HAVE_ASAN)
+                    add_compile_definitions(HAVE_ASAN)
                     add_compile_options(-fsanitize=address)
-                    add_link_options(-lasan)
+                    if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
+                        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
+                    endif()
+                    link_libraries(asan)
+                    check_flag(-fsanitize-recover=address IGNORE)
                 endif()
             endif()
 
@@ -58,8 +63,13 @@ function(check_debug)
                 check_cxx_compiler_flag(-fsanitize=undefined HAVE_UBSAN)
                 cmake_pop_check_state()
                 if(HAVE_UBSAN)
+                    add_compile_definitions(HAVE_UBSAN)
                     add_compile_options(-fsanitize=undefined)
-                    add_link_options(-lubsan)
+                    if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
+                        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
+                    endif()
+                    link_libraries(ubsan)
+                    check_flag(-fsanitize-recover=undefined IGNORE)
                 endif()
             endif()
         endif()