Add option to build QtCreator with sanitizer

Fixes: QTCREATORBUG-26318
Change-Id: I44589b5bb39958eda2329b444e4857e8f61823bf
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Joerg Kreuzberger
2021-10-05 07:40:58 +02:00
committed by Cristian Adam
parent 9e8b838080
commit efdaeaba43
5 changed files with 32 additions and 0 deletions

View File

@@ -33,6 +33,10 @@ option(WITH_TESTS "Build Tests" OFF)
add_feature_info("Build tests" ${WITH_TESTS} "") add_feature_info("Build tests" ${WITH_TESTS} "")
option(WITH_DEBUG_CMAKE "Enabled CMake project debugging functionality (e.g. source file disk checking)" OFF) 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(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 # merge binary directories of sub projects into top level
set(QTC_MERGE_BINARY_DIR ON) set(QTC_MERGE_BINARY_DIR ON)

View File

@@ -299,6 +299,10 @@ function(add_qtc_library name)
qtc_enable_separate_debug_info(${name} "${IDE_LIBRARY_PATH}") qtc_enable_separate_debug_info(${name} "${IDE_LIBRARY_PATH}")
if (WITH_SANITIZE)
qtc_enable_sanitize(${SANITIZE_FLAGS})
endif()
if (NAMELINK_OPTION) if (NAMELINK_OPTION)
install(TARGETS ${name} install(TARGETS ${name}
LIBRARY LIBRARY
@@ -457,6 +461,10 @@ function(add_qtc_plugin target_name)
set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}") set(TEST_DEFINES WITH_TESTS SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
endif() endif()
if (WITH_SANITIZE)
qtc_enable_sanitize(${SANITIZE_FLAGS})
endif()
extend_qtc_target(${target_name} extend_qtc_target(${target_name}
INCLUDES ${_arg_INCLUDES} INCLUDES ${_arg_INCLUDES}
PUBLIC_INCLUDES ${_arg_PUBLIC_INCLUDES} PUBLIC_INCLUDES ${_arg_PUBLIC_INCLUDES}

View File

@@ -154,6 +154,13 @@ function(qtc_enable_release_for_debug_configuration)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE)
endfunction() 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) function(append_extra_translations target_name)
if(NOT ARGN) if(NOT ARGN)
return() return()

View File

@@ -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 ' 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.', 'without a specific number of threads. This is directly passed to the "-mmt" option of 7z.',
default='2') 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 = parser.parse_args()
args.with_debug_info = args.build_type == 'RelWithDebInfo' 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_STR=' + ide_revision[:10],
'-DIDE_REVISION_URL=https://code.qt.io/cgit/qt-creator/qt-creator.git/log/?id=' + 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 cmake_args += args.config_args
common.check_print_call(cmake_args + [paths.src], paths.build) common.check_print_call(cmake_args + [paths.src], paths.build)

View File

@@ -56,6 +56,8 @@ def get_arguments():
action='append', dest='config_args', default=[]) action='append', dest='config_args', default=[])
parser.add_argument('--with-docs', help='Build and install documentation.', parser.add_argument('--with-docs', help='Build and install documentation.',
action='store_true', default=False) 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.', parser.add_argument('--deploy', help='Installs the "Dependencies" component of the plugin.',
action='store_true', default=False) action='store_true', default=False)
parser.add_argument('--build-type', help='Build type to pass to CMake (defaults to RelWithDebInfo)', 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: with open(os.path.join(paths.result, args.name + '.7z.git_sha'), 'w') as f:
f.write(ide_revision) 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 cmake_args += args.config_args
common.check_print_call(cmake_args + [paths.src], paths.build) common.check_print_call(cmake_args + [paths.src], paths.build)
build_args = ['cmake', '--build', '.'] build_args = ['cmake', '--build', '.']