From 61d5b019727dd1c06366205cb307a2a928a2a29c Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 3 Dec 2020 19:13:08 +0100 Subject: [PATCH] CMake: Add extra targets to run single benchmark using CMake generator Add custom targets with '_benchmark' suffixes to make run of benchmarks using generators possible, e.g.: $ ninja tst_bench_qudpsocket_benchmark Extend '-[no]make' option to pass benchmark. Rework '-[no]make' processing to unify these options processing. Also looks like it doesn't make sense to enable benchmarks without having test enabled. So '-DQT_BUILD_BENCHMARKS' enables test as own dependency automatically. Task-number: QTBUG-89076 Pick-to: 6.0 Change-Id: Ieee9eadaf6d75a1efec120242d6eb786ace1b071 Reviewed-by: Alexandru Croitor --- .../QtBuildInternalsConfig.cmake | 6 +++ cmake/QtProcessConfigureArgs.cmake | 53 +++++++++---------- cmake/QtSetup.cmake | 9 ++-- cmake/QtTestHelpers.cmake | 11 ++++ qt_cmdline.cmake | 7 ++- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 7aebfb04db..d9e4eb85ef 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -335,6 +335,12 @@ macro(qt_build_repo_begin) add_custom_target(host_tools) add_custom_target(bootstrap_tools) endif() + + # Add benchmark meta target. It's collection of all benchmarks added/registered by + # 'qt_internal_add_benchmark' helper. + if(NOT TARGET benchmark) + add_custom_target(benchmark) + endif() endmacro() macro(qt_build_repo_end) diff --git a/cmake/QtProcessConfigureArgs.cmake b/cmake/QtProcessConfigureArgs.cmake index 258a4a09e1..021b2abdef 100644 --- a/cmake/QtProcessConfigureArgs.cmake +++ b/cmake/QtProcessConfigureArgs.cmake @@ -603,6 +603,30 @@ function(guess_compiler_from_mkspec) set(cmake_args "${cmake_args}" PARENT_SCOPE) endfunction() +function(check_qt_build_parts type) + set(input "INPUT_${type}") + set(buildFlag "TRUE") + if("${type}" STREQUAL "nomake") + set(buildFlag "FALSE") + endif() + + list(APPEND knownParts "tests" "examples" "benchmarks") + + foreach(part ${${input}}) + if(part IN_LIST knownParts) + qt_feature_normalize_name("${part}" partUpperCase) + string(TOUPPER "${partUpperCase}" partUpperCase) + push("-DQT_BUILD_${partUpperCase}=${buildFlag}") + continue() + elseif("${part}" STREQUAL "tools" AND "${type}" STREQUAL "make") + # default true ignored + continue() + endif() + qtConfAddWarning("'-${type} ${part}' is not implemented yet.") + endforeach() + set(cmake_args "${cmake_args}" PARENT_SCOPE) +endfunction() + drop_input(commercial) drop_input(confirm-license) translate_boolean_input(precompile_header BUILD_WITH_PCH) @@ -662,33 +686,8 @@ endif() drop_input(make) drop_input(nomake) -foreach(part ${INPUT_nomake}) - if("${part}" STREQUAL "tests") - push("-DQT_BUILD_TESTS=OFF") - continue() - endif() - if("${part}" STREQUAL "examples") - push("-DQT_BUILD_EXAMPLES=OFF") - continue() - endif() - qtConfAddWarning("'-nomake ${part}' is not implemented yet.") -endforeach() - -foreach(part ${INPUT_make}) - if("${part}" STREQUAL "tests") - push("-DQT_BUILD_TESTS=ON") - continue() - endif() - if("${part}" STREQUAL "examples") - push("-DQT_BUILD_EXAMPLES=ON") - continue() - endif() - if("${part}" STREQUAL "tools") - # default - continue() - endif() - qtConfAddWarning("'-make ${part}' is not implemented yet.") -endforeach() +check_qt_build_parts(nomake) +check_qt_build_parts(make) drop_input(debug) drop_input(release) diff --git a/cmake/QtSetup.cmake b/cmake/QtSetup.cmake index 56684e7e02..a77a1795b9 100644 --- a/cmake/QtSetup.cmake +++ b/cmake/QtSetup.cmake @@ -125,6 +125,12 @@ else() set(__build_benchmarks OFF) endif() +# Build Benchmarks +option(QT_BUILD_BENCHMARKS "Build Qt Benchmarks" ${__build_benchmarks}) +if(QT_BUILD_BENCHMARKS) + set(_qt_build_tests_default ON) +endif() + ## Set up testing option(QT_BUILD_TESTS "Build the testing tree." ${_qt_build_tests_default}) unset(_qt_build_tests_default) @@ -157,9 +163,6 @@ enable_testing() option(QT_BUILD_EXAMPLES "Build Qt examples" OFF) option(QT_BUILD_EXAMPLES_BY_DEFAULT "Should examples be built as part of the default 'all' target." ON) -# Build Benchmarks -option(QT_BUILD_BENCHMARKS "Build Qt Benchmarks" ${__build_benchmarks}) - ## Find host tools (if non native): set(QT_HOST_PATH "" CACHE PATH "Installed Qt host directory path, used for cross compiling.") diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 3405eee83a..756be0ad4b 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -33,6 +33,17 @@ function(qt_internal_add_benchmark target) ${exec_args} ) + # Add a ${target}_benchmark generator target, to run single benchmark more easily. + # TODO: Need to use test wrapper script with propagated environment variables to run benchmarks. + add_custom_target("${target}_benchmark" + VERBATIM + COMMENT "Running benchmark ${target}" + COMMAND "$" + ) + add_dependencies("${target}_benchmark" "${target}") + + #Add benchmark to meta target. + add_dependencies("benchmark" "${target}_benchmark") endfunction() # Simple wrapper around qt_internal_add_executable for manual tests which insure that diff --git a/qt_cmdline.cmake b/qt_cmdline.cmake index ee580bd930..0145cd4a14 100644 --- a/qt_cmdline.cmake +++ b/qt_cmdline.cmake @@ -71,12 +71,15 @@ qt_commandline_option(incredibuild-xge TYPE boolean NAME incredibuild_xge) qt_commandline_option(libudev TYPE boolean) qt_commandline_option(linker TYPE optionalString VALUES bfd gold lld) qt_commandline_option(ltcg TYPE boolean) -qt_commandline_option(make TYPE addString VALUES examples libs tests tools) +# special case begin +qt_commandline_option(make TYPE addString VALUES examples libs tests tools + benchmarks) +# special case end qt_commandline_option(make-tool TYPE string) qt_commandline_option(mips_dsp TYPE boolean) qt_commandline_option(mips_dspr2 TYPE boolean) qt_commandline_option(mp TYPE boolean NAME msvc_mp) -qt_commandline_option(nomake TYPE addString VALUES examples tests tools) +qt_commandline_option(nomake TYPE addString VALUES examples tests tools benchmarks) # special case qt_commandline_option(opensource TYPE void NAME commercial VALUE no) qt_commandline_option(optimize-debug TYPE boolean NAME optimize_debug) qt_commandline_option(optimize-size TYPE boolean NAME optimize_size)