cmake: Add build option for Address Sanitizer
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0bc37cb..16fb699 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,10 @@
 # Require the user to ask that it be installed if they really want it.
 option(INSTALL_ICD "Install icd" OFF)
 
+if (UNIX AND NOT APPLE) # i.e. Linux
+    option(ENABLE_ADDRESS_SANITIZER "Use addres sanitization" OFF)
+endif()
+
 if(WIN32)
     # Optional: Allow specify the exact version used in the vulkaninfo executable
     # Format is major.minor.patch.build
diff --git a/cube/CMakeLists.txt b/cube/CMakeLists.txt
index a2f026e..3c37189 100644
--- a/cube/CMakeLists.txt
+++ b/cube/CMakeLists.txt
@@ -239,6 +239,11 @@
     if (NEED_RT)
         target_link_libraries(vkcube rt)
     endif()
+
+    if (ENABLE_ADDRESS_SANITIZER)
+        target_compile_options(vkcube PUBLIC -fsanitize=address)
+        target_link_options(vkcube PUBLIC -fsanitize=address)
+    endif ()
 else()
     if(CMAKE_CL_64)
         set(LIB_DIR "Win64")
@@ -284,6 +289,11 @@
                    ${OPTIONAL_WAYLAND_DATA_FILES})
     target_link_libraries(vkcubepp Vulkan::Vulkan)
     target_compile_definitions(vkcubepp PUBLIC ${CUBE_PLATFORM})
+
+    if (ENABLE_ADDRESS_SANITIZER)
+        target_compile_options(vkcubepp PUBLIC -fsanitize=address)
+        target_link_options(vkcubepp PUBLIC -fsanitize=address)
+    endif ()
 else()
     if(CMAKE_CL_64)
         set(LIB_DIR "Win64")
@@ -342,5 +352,10 @@
             target_link_libraries(vkcube-wayland rt)
         endif()
         install(TARGETS vkcube-wayland RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+
+        if (ENABLE_ADDRESS_SANITIZER)
+            target_compile_options(vkcube-wayland PUBLIC -fsanitize=address)
+            target_link_options(vkcube-wayland PUBLIC -fsanitize=address)
+        endif ()
     endif()
 endif()
diff --git a/icd/CMakeLists.txt b/icd/CMakeLists.txt
index 41772f7..950300d 100644
--- a/icd/CMakeLists.txt
+++ b/icd/CMakeLists.txt
@@ -130,6 +130,10 @@
         if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
             install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
         endif()
+        if (ENABLE_ADDRESS_SANITIZER)
+            target_compile_options(VkICD_${target} PUBLIC -fsanitize=address)
+            target_link_options(VkICD_${target} PUBLIC -fsanitize=address)
+        endif ()
     endmacro()
 endif()
 
diff --git a/vulkaninfo/CMakeLists.txt b/vulkaninfo/CMakeLists.txt
index d23dcf8..d2d66df 100644
--- a/vulkaninfo/CMakeLists.txt
+++ b/vulkaninfo/CMakeLists.txt
@@ -93,6 +93,11 @@
         target_link_libraries(vulkaninfo PkgConfig::DirectFB)
         target_compile_definitions(vulkaninfo PRIVATE -DVK_USE_PLATFORM_DIRECTFB_EXT -DVK_NO_PROTOTYPES)
     endif()
+
+    if (ENABLE_ADDRESS_SANITIZER)
+        target_compile_options(vulkaninfo PUBLIC -fsanitize=address)
+        target_link_options(vulkaninfo PUBLIC -fsanitize=address)
+    endif ()
 endif()
 
 if(APPLE)