Skip to content

Commit faa2f32

Browse files
authored
Enable warnings (#21)
* Enable warnings * Fix some warnings * Try to enable deprecation warnings * Ignore warnings in VRS source code * Try that again * Try another fix * I hate CMAKE
1 parent d0345ca commit faa2f32

File tree

4 files changed

+102
-7
lines changed

4 files changed

+102
-7
lines changed

CMakeLists.txt

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.16...3.27)
22

3-
project(rerun_vrs_example LANGUAGES CXX)
3+
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) # TODO(emilk): If we turn this ON, VRS fails to compile
4+
5+
set(TARGET_NAME rerun_vrs_example)
6+
project(${TARGET_NAME} LANGUAGES CXX)
47

58
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
69

@@ -22,6 +25,98 @@ FetchContent_MakeAvailable(vrslib)
2225

2326
find_package(fmt REQUIRED)
2427

25-
add_executable(rerun_vrs_example src/main.cpp src/frame_player.cpp src/imu_player.cpp)
26-
target_link_libraries(rerun_vrs_example rerun_sdk vrslib vrs_utils fmt)
27-
target_include_directories(rerun_vrs_example PRIVATE src)
28+
add_executable(${TARGET_NAME} src/main.cpp src/frame_player.cpp src/imu_player.cpp)
29+
target_link_libraries(${TARGET_NAME} rerun_sdk vrslib vrs_utils fmt)
30+
target_include_directories(${TARGET_NAME} PRIVATE src)
31+
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${rerun_sdk_SOURCE_DIR}) # Ignore warnings in Rerun SDK headers
32+
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${vrslib_SOURCE_DIR}) # Ignore warnings in VRS headers
33+
34+
35+
if(MSVC)
36+
# TODO(andreas): Try to enable /Wall
37+
target_compile_options(${TARGET_NAME} PRIVATE /W4)
38+
39+
target_compile_options(${TARGET_NAME} PRIVATE /we4996) # Using deprecated functions is an error
40+
41+
if(BUILD_SHARED_LIBS)
42+
# If we are building as shared libs, we are going to have to disable the C4251
43+
# warning, as it would trigger for any datatype derived from a STL class
44+
# See also https://github.com/protocolbuffers/protobuf/blob/v26.1/cmake/README.md#notes-on-compiler-warnings
45+
# We need also to make it public, otherwise downstream code will be flooded by c4251 warnings
46+
target_compile_options(${TARGET_NAME} PUBLIC /wd4251)
47+
endif()
48+
49+
# CMAKE_COMPILE_WARNING_AS_ERROR is only directly supported starting in CMake `3.24`
50+
# https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_WARNING_AS_ERROR.html
51+
if(CMAKE_COMPILE_WARNING_AS_ERROR)
52+
target_compile_options(${TARGET_NAME} PRIVATE /WX
53+
/w15038 # Initialization order. https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038
54+
)
55+
endif()
56+
else()
57+
# Enabled warnings.
58+
target_compile_options(${TARGET_NAME} PRIVATE
59+
-Wall
60+
-Wcast-align
61+
-Wcast-qual
62+
-Wdeprecated
63+
-Wdeprecated-declarations
64+
-Werror=deprecated-declarations
65+
-Wextra
66+
-Wformat=2
67+
-Wmissing-include-dirs
68+
-Wnull-dereference
69+
-Wold-style-cast
70+
-Wpedantic
71+
-Wpointer-arith
72+
-Wshadow
73+
-Wswitch-enum
74+
-Wunreachable-code
75+
-Wvla
76+
)
77+
78+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # match both "Clang" and "AppleClang"
79+
# TODO(emilk): enable some hardening flags from https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
80+
target_compile_options(${TARGET_NAME} PRIVATE
81+
-Wc++17-compat-pedantic
82+
-Wc++20-compat-pedantic
83+
-Wc99-extensions
84+
-Weverything
85+
-Wgnu
86+
-Wnon-gcc
87+
-Wpre-c2x-compat-pedantic
88+
-Wshadow-all
89+
90+
# Turn off some warning that -Weverything turns on:
91+
-Wno-c++98-compat
92+
-Wno-c++98-compat-pedantic
93+
-Wno-covered-switch-default # We often add a `default:` case out of paranoia
94+
-Wno-ctad-maybe-unsupported
95+
-Wno-disabled-macro-expansion
96+
-Wno-documentation
97+
-Wno-documentation-unknown-command
98+
-Wno-double-promotion # float->double is nothing to whine about
99+
-Wno-exit-time-destructors
100+
-Wno-float-equal # comparing floats is fine
101+
-Wno-global-constructors
102+
-Wno-missing-prototypes
103+
-Wno-padded
104+
-Wno-reserved-id-macro
105+
-Wno-reserved-identifier
106+
-Wno-unused-macros
107+
-Wno-unsafe-buffer-usage # Not sure why we need this, but we do.
108+
-Wno-unknown-warning-option # Otherwise older clang will complain about `-Wno-unsafe-buffer-usage`
109+
)
110+
endif()
111+
112+
# CMAKE_COMPILE_WARNING_AS_ERROR is only directly supported starting in CMake `3.24`
113+
# https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_WARNING_AS_ERROR.html
114+
if(CMAKE_COMPILE_WARNING_AS_ERROR)
115+
target_compile_options(${TARGET_NAME} PRIVATE -Werror)
116+
endif()
117+
118+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
119+
# Improve stack traces:
120+
target_compile_options(${TARGET_NAME} PRIVATE -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-optimize-sibling-calls)
121+
endif()
122+
endif()

src/frame_player.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace rerun_vrs {
5757
auto& config = getExpectedLayout<FrameNumberDataLayout>(layout, block_index);
5858
uint64_t frame_number;
5959
if (config.frameNumber.get(frame_number)) {
60-
_rec->set_time_sequence("frame_number", frame_number);
60+
_rec->set_time_sequence("frame_number", static_cast<int64_t>(frame_number));
6161
}
6262

6363
// this is meta data per record and changes over time

src/frame_player.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace rerun_vrs {
3636
override;
3737

3838
private:
39-
std::shared_ptr<const rerun::RecordingStream> _rec;
4039
vrs::StreamId _id;
40+
std::shared_ptr<const rerun::RecordingStream> _rec;
4141
std::string _entity_path;
4242
bool _enabled{true};
4343
};

src/imu_player.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace rerun_vrs {
3838
void log_gyroscope(const std::array<float, 3>& gyroRadSec);
3939
void log_magnetometer(const std::array<float, 3>& magTesla);
4040

41-
std::shared_ptr<const rerun::RecordingStream> _rec;
4241
vrs::StreamId _id;
42+
std::shared_ptr<const rerun::RecordingStream> _rec;
4343
std::string _entity_path;
4444
bool _enabled{true};
4545
bool _has_accelerometer;

0 commit comments

Comments
 (0)