Skip to content

Commit

Permalink
CMake: Add extra targets to run single benchmark using CMake generator
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
semlanik committed Dec 7, 2020
1 parent 886db3a commit 61d5b01
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
6 changes: 6 additions & 0 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 26 additions & 27 deletions cmake/QtProcessConfigureArgs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions cmake/QtSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.")

Expand Down
11 changes: 11 additions & 0 deletions cmake/QtTestHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE:${target}>"
)
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
Expand Down
7 changes: 5 additions & 2 deletions qt_cmdline.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 61d5b01

Please sign in to comment.