File: IgnBenchmark.cmake

package info (click to toggle)
ignition-cmake 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,132 kB
  • sloc: xml: 35,671; python: 3,768; javascript: 2,308; sh: 172; ansic: 109; cpp: 64; makefile: 7
file content (103 lines) | stat: -rw-r--r-- 3,535 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#.rst
# IgnBenchmark
# ------------
#
# ign_add_version_info_target()
#
# Adds a target to generate build and system configuration information.
#
# ign_add_benchmarks()
#
# Adds a target to execute all available benchmarks and aggregate the results.
#
# USAGE:
# 1. Add the following line to your CMakeLists.txt
#    include(IgnBenchmark)
#
# 2. Add the benchmark
#    ign_add_benchmarks(SOURCES ${benchmark_sources_list})
#
# 3. After building the project, use `make run_benchmarks` to execute and
#    aggregate benchmark results to ${CMAKE_BINARY_DIR}/benchmark_results
#
#===============================================================================
# Copyright (C) 2019 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function(ign_add_version_info_target)
  # generate a version_info.json file that can be used to embed project
  # version information
  # While this command may look a bit unweildy, it creates a target
  # that forces the file to be regenerated at build time.
  add_custom_target(version_info_target
    COMMAND ${CMAKE_COMMAND}
      -Dinput_file=${IGNITION_CMAKE_DIR}/version_info.json.in
      -Doutput_file=${CMAKE_CURRENT_BINARY_DIR}/version_info.json
      -Drepository_root=${CMAKE_CURRENT_SOURCE_DIR}
      # Yes, these variables need to be passed in, because they won't
      # get properly set when invoked as a CMake script.
      -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
      -DPROJECT_VERSION=${PROJECT_VERSION}
      -DPROJECT_VERSION_FULL=${PROJECT_VERSION_FULL}
      -DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
      -DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
      -DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
      -DPROJECT_NAME=${PROJECT_NAME}
      -P ${IGNITION_CMAKE_DIR}/IgnGenerateVersionInfo.cmake
  )
endfunction()

function(ign_add_benchmarks)
  cmake_parse_arguments(BENCHMARK "" "" "SOURCES" ${ARGN})

  if(NOT BUILD_TESTING)
    return()
  endif()

  find_package(benchmark)
  if(NOT benchmark_FOUND)
    message(WARNING "Unable to find google benchmark (libbenchmark-dev). Disabling benchmarks.")
    return()
  endif()

  ign_build_executables(
    PREFIX "BENCHMARK_"
    SOURCES ${BENCHMARK_SOURCES}
    LIB_DEPS benchmark::benchmark
    EXEC_LIST BENCHMARK_TARGETS
  )

  set(BENCHMARK_TARGETS_LIST "")
  foreach(benchmark ${BENCHMARK_TARGETS})
    list(APPEND BENCHMARK_TARGETS_LIST "$<TARGET_FILE:${benchmark}>")
  endforeach()

  ign_add_version_info_target()

  file(GENERATE
    OUTPUT
    "${CMAKE_CURRENT_BINARY_DIR}/benchmark_targets"
    CONTENT
    "${BENCHMARK_TARGETS_LIST}")

  add_custom_target(
    run_benchmarks
    COMMAND python3 ${IGNITION_CMAKE_BENCHMARK_DIR}/run_benchmarks.py
      --project-name ${PROJECT_NAME}
      --version-file ${CMAKE_CURRENT_BINARY_DIR}/version_info.json
      --benchmark-targets ${CMAKE_CURRENT_BINARY_DIR}/benchmark_targets
      --results-root ${CMAKE_BINARY_DIR}/benchmark_results
  )
  add_dependencies(run_benchmarks ${BENCHMARK_TARGETS} version_info_target)
endfunction()