diff --git a/CMakeLists.txt b/CMakeLists.txt
index 114a01d9a2..a102020c75 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,7 @@ option(WITH_TESTS "Build Tests" OFF)
 add_feature_info("Build tests" ${WITH_TESTS} "")
 option(WITH_DEBUG_CMAKE "Enabled CMake project debugging functionality (e.g. source file disk checking)" OFF)
 option(SHOW_BUILD_DATE "Show build date in about dialog" OFF)
+option(WITH_SANITIZE "Build with sanitizer enabled" OFF)
 
 # merge binary directories of sub projects into top level
 set(QTC_MERGE_BINARY_DIR ON)
@@ -94,6 +95,8 @@ endfunction()
 set_if_target(_has_svg_target Qt5::Svg)
 option(ENABLE_SVG_SUPPORT "Enable SVG support" "${_has_svg_target}")
 
+add_feature_info("Build with sanitize" ${WITH_SANITIZE} "flags=${SANITIZE_FLAGS}")
+
 add_library(OptionalSvg INTERFACE)
 if (TARGET Qt5::Svg AND ENABLE_SVG_SUPPORT)
   target_link_libraries(OptionalSvg INTERFACE Qt5::Svg)
diff --git a/cmake/QtCreatorAPI.cmake b/cmake/QtCreatorAPI.cmake
index ac97e74fc4..32323a0a68 100644
--- a/cmake/QtCreatorAPI.cmake
+++ b/cmake/QtCreatorAPI.cmake
@@ -305,6 +305,10 @@ function(add_qtc_library name)
 
   qtc_enable_separate_debug_info(${name} "${IDE_LIBRARY_PATH}")
 
+  if( WITH_SANITIZE )
+    qtc_enable_sanitize(${SANITIZE_FLAGS})
+  endif()
+
   if (NAMELINK_OPTION)
     install(TARGETS ${name}
       LIBRARY
@@ -463,6 +467,10 @@ function(add_qtc_plugin target_name)
     set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
   endif()
 
+  if( WITH_SANITIZE )
+    qtc_enable_sanitize(${SANITIZE_FLAGS})
+  endif()
+
   extend_qtc_target(${target_name}
     INCLUDES ${_arg_INCLUDES}
     PUBLIC_INCLUDES ${_arg_PUBLIC_INCLUDES}
@@ -670,6 +678,11 @@ function(add_qtc_executable name)
     set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
   endif()
 
+  if( WITH_SANITIZE )
+    qtc_enable_sanitize(${SANITIZE_FLAGS})
+  endif()
+
+
   add_executable("${name}" ${_arg_SOURCES})
 
   extend_qtc_target("${name}"
diff --git a/cmake/QtCreatorAPIInternal.cmake b/cmake/QtCreatorAPIInternal.cmake
index 7ebd2d31d7..fa58467d08 100644
--- a/cmake/QtCreatorAPIInternal.cmake
+++ b/cmake/QtCreatorAPIInternal.cmake
@@ -136,6 +136,13 @@ function(qtc_enable_release_for_debug_configuration)
   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE)
 endfunction()
 
+function(qtc_enable_sanitize _sanitize_flags)
+  if (NOT MSVC)
+    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=${_sanitize_flags}")
+  endif()
+  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE)
+endfunction()
+
 function(append_extra_translations target_name)
   if(NOT ARGN)
     return()
diff --git a/scripts/build.py b/scripts/build.py
index cc8b12ff34..8d6f729f4e 100755
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -108,6 +108,9 @@ def get_arguments():
     parser.add_argument('--zip-threads', help='Sets number of threads to use for 7z. Use "+" for turning threads on '
                         'without a specific number of threads. This is directly passed to the "-mmt" option of 7z.',
                         default='2')
+    parser.add_argument('--add-sanitize-flags', help="Sets flags for sanitizer compilation flags used in Debug builds",
+                        action='append', dest='sanitize_flags', default=[] )
+
     args = parser.parse_args()
     args.with_debug_info = args.build_type == 'RelWithDebInfo'
 
@@ -182,6 +185,10 @@ def build_qtcreator(args, paths):
                        '-DIDE_REVISION_STR=' + ide_revision,
                        '-DIDE_REVISION_URL=https://code.qt.io/cgit/qt-creator/qt-creator.git/log/?id=' + ide_revision]
 
+    if not args.build_type.lower() == 'release' and args.sanitize_flags:
+        cmake_args += ['-DWITH_SANITIZE=ON',
+                       '-DSANITIZE_FLAGS=' + ",".join(args.sanitize_flags)]
+
     cmake_args += args.config_args
 
     common.check_print_call(cmake_args + [paths.src], paths.build)
diff --git a/scripts/build_plugin.py b/scripts/build_plugin.py
index 7ba55ef38d..16a51efed5 100755
--- a/scripts/build_plugin.py
+++ b/scripts/build_plugin.py
@@ -56,6 +56,8 @@ def get_arguments():
                         action='append', dest='config_args', default=[])
     parser.add_argument('--with-docs', help='Build and install documentation.',
                         action='store_true', default=False)
+    parser.add_argument('--add-sanitize-flags', help="Sets flags for sanitizer compilation flags used in Debug builds",
+                        action='append', dest='sanitize_flags', default=[] )
     parser.add_argument('--deploy', help='Installs the "Dependencies" component of the plugin.',
                         action='store_true', default=False)
     parser.add_argument('--build-type', help='Build type to pass to CMake (defaults to RelWithDebInfo)',
@@ -110,6 +112,10 @@ def build(args, paths):
         with open(os.path.join(paths.result, args.name + '.7z.git_sha'), 'w') as f:
             f.write(ide_revision)
 
+    if not args.build_type.lower() == 'release' and args.sanitize_flags:
+        cmake_args += ['-DWITH_SANITIZE=ON',
+                       '-DSANITIZE_FLAGS=' + ",".join(args.sanitize_flags)]
+
     cmake_args += args.config_args
     common.check_print_call(cmake_args + [paths.src], paths.build)
     build_args = ['cmake', '--build', '.']
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 799d8ef68c..c2aafb4d4e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,5 @@
+
+
 add_library(app_version INTERFACE)
 target_include_directories(app_version
   INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
