From 61d5b019727dd1c06366205cb307a2a928a2a29c Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 3 Dec 2020 19:13:08 +0100 Subject: 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 --- .../QtBuildInternals/QtBuildInternalsConfig.cmake | 6 +++ cmake/QtProcessConfigureArgs.cmake | 53 +++++++++++----------- cmake/QtSetup.cmake | 9 ++-- cmake/QtTestHelpers.cmake | 11 +++++ 4 files changed, 49 insertions(+), 30 deletions(-) (limited to 'cmake') 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 -- cgit v1.2.3