diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | cmake/QtCreatorAPI.cmake | 8 | ||||
-rw-r--r-- | cmake/QtCreatorAPIInternal.cmake | 7 | ||||
-rwxr-xr-x | scripts/build.py | 7 | ||||
-rwxr-xr-x | scripts/build_plugin.py | 6 |
5 files changed, 32 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8911572ca0..55d8d7c6aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,10 @@ 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) +set(SANITIZE_FLAGS "" CACHE STRING "Sets flags for sanitizer compilation flags used in Debug builds") +add_feature_info("Build with sanitize" ${WITH_SANITIZE} "SANITIZE_FLAGS='${SANITIZE_FLAGS}'") + # merge binary directories of sub projects into top level set(QTC_MERGE_BINARY_DIR ON) diff --git a/cmake/QtCreatorAPI.cmake b/cmake/QtCreatorAPI.cmake index 7484f78450..0069ae8010 100644 --- a/cmake/QtCreatorAPI.cmake +++ b/cmake/QtCreatorAPI.cmake @@ -299,6 +299,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 @@ -457,6 +461,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} diff --git a/cmake/QtCreatorAPIInternal.cmake b/cmake/QtCreatorAPIInternal.cmake index 026647f56d..e0bffda176 100644 --- a/cmake/QtCreatorAPIInternal.cmake +++ b/cmake/QtCreatorAPIInternal.cmake @@ -154,6 +154,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 (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + 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 776914175c..91ccd5bae1 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -109,6 +109,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' @@ -185,6 +188,10 @@ def build_qtcreator(args, paths): '-DIDE_REVISION_STR=' + ide_revision[:10], '-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', '.'] |