Skip to content

Commit

Permalink
Extract version string into GetBenchmarkVersiom()
Browse files Browse the repository at this point in the history
  • Loading branch information
LebedevRI committed Jan 24, 2024
1 parent 341783b commit a7a5822
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ class BenchmarkReporter;
// Default number of minimum benchmark running time in seconds.
const char kDefaultMinTimeStr[] = "0.5s";

// Returns the version of the library.
BENCHMARK_EXPORT std::string GetBenchmarkVersiom();

BENCHMARK_EXPORT void PrintDefaultHelp();

BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target_include_directories(benchmark PUBLIC
)

set_property(
SOURCE json_reporter.cc
SOURCE benchmark.cc
APPEND
PROPERTY COMPILE_DEFINITIONS
BENCHMARK_VERSION="${VERSION}"
Expand Down
8 changes: 8 additions & 0 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,14 @@ int InitializeStreams() {

} // end namespace internal

std::string GetBenchmarkVersiom() {
#if defined(BENCHMARK_VERSION)
return {BENCHMARK_VERSION};
#else
return "hello, bazel!";
#endif
}

void PrintDefaultHelp() {
fprintf(stdout,
"benchmark"
Expand Down
7 changes: 1 addition & 6 deletions src/json_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,7 @@ bool JSONReporter::ReportContext(const Context& context) {
}
out << "],\n";

#if defined(BENCHMARK_VERSION)
const char library_version[] = BENCHMARK_VERSION;
#else
const char library_version[] = "hello, bazel!";
#endif
out << indent << FormatKV("library_version", library_version);
out << indent << FormatKV("library_version", GetBenchmarkVersiom());
out << ",\n";

#if defined(NDEBUG)
Expand Down

0 comments on commit a7a5822

Please sign in to comment.