Skip to content

Commit 8219fe6

Browse files
chore(core): prevent building tests if there are warnings
This way we can get early warnings in our CI without disrupting downstream users by adding -Wall -Werror etc if they do not wish to do so.
1 parent e2ba701 commit 8219fe6

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

core/test/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ target_link_libraries(unit_tests
1818
GTest::gtest_main
1919
)
2020

21+
# Treat warnings as errors for tests to catch issues early
22+
if(MSVC)
23+
target_compile_options(unit_tests PRIVATE /W4 /WX)
24+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
25+
target_compile_options(unit_tests PRIVATE -Wall -Wextra -Werror)
26+
endif()
27+
2128
include(GoogleTest)
2229
gtest_discover_tests(unit_tests)

examples/google_benchmark_bazel/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
config_setting(
2+
name = "windows",
3+
constraint_values = ["@platforms//os:windows"],
4+
)
5+
16
cc_binary(
27
name = "my_benchmark",
38
srcs = glob(["*.cpp", "*.hpp"]),
4-
copts = ["-Wall", "-Wextra", "-Werror"],
9+
copts = select({
10+
":windows": ["/std:c++17", "/W4", "/WX"],
11+
"//conditions:default": ["-Wall", "-Wextra", "-Werror"],
12+
}),
513
deps = [
614
"//google_benchmark:benchmark",
715
],

examples/google_benchmark_cmake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.12)
22
include(FetchContent)
33

4-
project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)
4+
project(codspeed_google_benchmark_example VERSION 0.0.0 LANGUAGES CXX)
55

66
# Treat warnings as errors
77
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")

google_benchmark/include/benchmark/benchmark.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
185185

186186
#ifdef CODSPEED_ENABLED
187187
#include <codspeed.h>
188-
#include <measurement.hpp>
189188

190189
#include <filesystem>
191-
#endif // CODSPEED_ENABLED
190+
#include <measurement.hpp>
191+
#endif // CODSPEED_ENABLED
192192

193193
#if defined(_MSC_VER)
194194
#include <intrin.h> // for _ReadWriteBarrier
@@ -947,7 +947,7 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
947947
public:
948948
const IterationCount max_iterations;
949949
#ifdef CODSPEED_INSTRUMENTATION
950-
codspeed::CodSpeed *codspeed_;
950+
codspeed::CodSpeed* codspeed_;
951951
#endif
952952

953953
private:
@@ -970,11 +970,11 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
970970
internal::ThreadTimer* timer, internal::ThreadManager* manager,
971971
internal::PerfCountersMeasurement* perf_counters_measurement,
972972
ProfilerManager* profiler_manager
973-
#ifdef CODSPEED_INSTRUMENTATION
973+
#ifdef CODSPEED_INSTRUMENTATION
974974
,
975-
codspeed::CodSpeed *codspeed = NULL
976-
#endif
977-
);
975+
codspeed::CodSpeed* codspeed = NULL
976+
#endif
977+
);
978978

979979
void StartKeepRunning();
980980
// Implementation of KeepRunning() and KeepRunningBatch().
@@ -1609,12 +1609,12 @@ class Fixture : public internal::Benchmark {
16091609
#ifdef CODSPEED_ENABLED
16101610

16111611
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
1612-
STATIC_NAMESPACE_STRING(ns_##BaseClass##_##Method); \
1612+
STATIC_NAMESPACE_STRING(ns_##BaseClass##_##Method); \
16131613
class BaseClass##_##Method##_Benchmark : public BaseClass { \
16141614
public: \
16151615
BaseClass##_##Method##_Benchmark() { \
16161616
this->SetName(CUR_FILE + ns_##BaseClass##_##Method + \
1617-
#Method "[" #BaseClass "]"); \
1617+
#Method "[" #BaseClass "]"); \
16181618
} \
16191619
\
16201620
protected: \
@@ -1660,7 +1660,7 @@ class Fixture : public internal::Benchmark {
16601660
void BenchmarkCase(::benchmark::State&) override; \
16611661
};
16621662

1663-
#else // CODSPEED_ENABLED undefined:
1663+
#else // CODSPEED_ENABLED undefined:
16641664

16651665
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
16661666
class BaseClass##_##Method##_Benchmark : public BaseClass { \

0 commit comments

Comments
 (0)