-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark-generator.cmake
49 lines (39 loc) · 1.95 KB
/
benchmark-generator.cmake
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
set(BENCHMARK_GENERATOR ${CMAKE_CURRENT_LIST_DIR}/benchmark-generator.py)
function(generate_benchmarks_from_folder folder BENCHMARKS)
if (${CMAKE_VERSION} VERSION_LESS "3.19")
message(WARNING "Cannot generate benchmarks CMake 3.19 or higher is required. You are running version ${CMAKE_VERSION}")
message(WARNING "Using second last filename extension instead (deprecated)")
endif ()
file(GLOB_RECURSE jsons RELATIVE ${folder} *.json)
foreach (json ${jsons})
get_filename_component(dir ${json} DIRECTORY)
get_filename_component(name ${json} NAME_WE)
if (${CMAKE_VERSION} VERSION_LESS "3.19")
string(REPLACE "." ";" ext_list ${json})
list(GET ext_list -2 type)
else ()
file(READ ${folder}/${json} json_data)
string(JSON type GET ${json_data} type)
endif ()
if (${type} STREQUAL "definition")
SET(json_schema ${folder}/${dir}/${name}.schema.json)
add_custom_command(
OUTPUT ${json_schema}
COMMAND ${BENCHMARK_GENERATOR} --schema --input ${folder}/${json} --output ${json_schema}
DEPENDS ${folder}/${json}
VERBATIM)
# target to generate benchmark schema
add_custom_target(schema_${name} ALL DEPENDS ${json_schema})
elseif (${type} STREQUAL "benchmark")
set(cpp generated/${name}.cpp)
# ${cpp}.output is never created, therefore, the command is run on every build
add_custom_command(
OUTPUT ${cpp} ${cpp}.output
COMMAND ${BENCHMARK_GENERATOR} --benchmark --input ${folder}/${json} --output ${cpp}
VERBATIM)
add_executable(benchmark_${name} ${cpp})
list(APPEND benchmark_drivers benchmark_${name})
endif ()
endforeach ()
set(${BENCHMARKS} ${benchmark_drivers} PARENT_SCOPE)
endfunction()