1
1
cmake_minimum_required (VERSION 3.16...3.27 )
2
2
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 )
4
7
5
8
set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
6
9
@@ -22,6 +25,98 @@ FetchContent_MakeAvailable(vrslib)
22
25
23
26
find_package (fmt REQUIRED )
24
27
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 ()
0 commit comments