@@ -34,3 +34,105 @@ macro(add_metabench_profile)
34
34
get_metabench()
35
35
add_mb_profile(${ARGN} )
36
36
endmacro ()
37
+
38
+ function (add_mb_comparison)
39
+ set (singleValueArgs
40
+ TARGET
41
+ RANGE
42
+ TEMPLATE
43
+ LIBRARY
44
+ REMOTE
45
+ BRANCH
46
+ OPTIONS )
47
+ set (multiValueArgs INCLUDE_DIRECTORIES LIBRARIES DS_ARGS CHART_ARGS)
48
+ cmake_parse_arguments (MB "" "${singleValueArgs} " "${multiValueArgs} "
49
+ ${ARGN} )
50
+
51
+ if (NOT PROJECT_IS_TOP_LEVEL)
52
+ message (
53
+ FATAL_ERROR
54
+ "add_mb_comparison() must be used only against a top-level project."
55
+ )
56
+ endif ()
57
+
58
+ if (NOT DEFINED ${MB_LIBRARY} _SOURCE_DIR)
59
+ message (
60
+ FATAL_ERROR
61
+ "add_mb_comparison(${ARGN} ): no source directory for ${MB_LIBRARY} "
62
+ )
63
+ endif ()
64
+ set (my_path ${${MB_LIBRARY} _SOURCE_DIR})
65
+
66
+ string (TOUPPER ${MB_LIBRARY} ulib_name)
67
+ if (NOT DEFINED ${ulib_name} _ALT)
68
+ message (
69
+ FATAL_ERROR
70
+ "add_mb_comparison(${ARGN} ): ${MB_LIBRARY} does not define a ${ulib_name} _ALT option."
71
+ )
72
+ endif ()
73
+
74
+ if (NOT DEFINED MB_REMOTE)
75
+ set (MB_REMOTE "origin" )
76
+ endif ()
77
+ if (NOT DEFINED MB_BRANCH)
78
+ set (MB_BRANCH "main" )
79
+ endif ()
80
+
81
+ # get the hash the remote branch is at
82
+ execute_process (
83
+ COMMAND ${GIT_PROGRAM} ls-remote -h ${MB_REMOTE} ${MB_BRANCH}
84
+ WORKING_DIRECTORY ${my_path}
85
+ OUTPUT_VARIABLE remote_hash
86
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
87
+ string (REGEX REPLACE "\t .*" "" remote_hash ${remote_hash} )
88
+
89
+ # get the remote repository
90
+ execute_process (
91
+ COMMAND ${GIT_PROGRAM} remote -v
92
+ COMMAND awk "/^${MB_REMOTE} \\ s.*\\ (fetch\\ )$/ { print $2 }"
93
+ WORKING_DIRECTORY ${my_path}
94
+ OUTPUT_VARIABLE gh_repo
95
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
96
+ string (REGEX REPLACE "^.*:" "" gh_repo ${gh_repo} )
97
+ string (REGEX REPLACE "\. git$" "" gh_repo ${gh_repo} )
98
+
99
+ # get the library at that hash
100
+ set (orig_lib "${MB_LIBRARY} _alt" )
101
+ add_versioned_package(
102
+ NAME
103
+ ${orig_lib}
104
+ GITHUB_REPOSITORY
105
+ ${gh_repo}
106
+ GIT_TAG
107
+ ${remote_hash}
108
+ OPTIONS
109
+ ${MB_OPTIONS}
110
+ "${ulib_name} _ALT ON" )
111
+
112
+ if (NOT TARGET ${orig_lib} )
113
+ message (
114
+ FATAL_ERROR
115
+ "add_mb_comparison(${ARGN} ): ${MB_LIBRARY} with ${ulib_name} _ALT ON did not define a ${orig_lib} target."
116
+ )
117
+ endif ()
118
+
119
+ string (REPLACE "/" "_" dataset ${MB_TEMPLATE} )
120
+ foreach (alt in ITEMS old new)
121
+ metabench_add_dataset(
122
+ "${alt} _${dataset} " "${MB_TEMPLATE} " "${MB_RANGE} " NAME
123
+ "${alt} _${dataset} " ${MB_DS_ARGS} )
124
+ target_include_directories ("${alt} _${dataset} "
125
+ PRIVATE ${MB_INCLUDE_DIRECTORIES} )
126
+ target_link_libraries ("${alt} _${dataset} " PRIVATE ${MB_LIBRARIES} )
127
+ endforeach ()
128
+ target_link_libraries ("old_${dataset} " PRIVATE ${orig_lib} )
129
+ target_link_libraries ("new_${dataset} " PRIVATE ${MB_LIBRARY} )
130
+
131
+ metabench_add_chart(${MB_TARGET} DATASETS old_${dataset} new_${dataset}
132
+ ${MB_CHART_ARGS} )
133
+ endfunction ()
134
+
135
+ macro (add_metabench_comparison)
136
+ get_metabench()
137
+ add_mb_comparison(${ARGN} )
138
+ endmacro ()
0 commit comments