Skip to content

Commit 6482076

Browse files
committed
build: Fix enabling of build warnings, and handle most warnings discovered.
1 parent dc35446 commit 6482076

File tree

12 files changed

+47
-36
lines changed

12 files changed

+47
-36
lines changed

src/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,17 @@ set_target_properties(xr_global_generated_files PROPERTIES FOLDER ${CODEGEN_FOLD
320320
set(COMMON_GENERATED_OUTPUT ${GENERATED_OUTPUT})
321321
if(NOT MSVC)
322322
include(CheckCXXCompilerFlag)
323-
foreach(FLAG -Wall -Werror=unused-parameter -Werror=unused-argument)
323+
include(CheckCCompilerFlag)
324+
foreach(FLAG -Wall -Werror=unused-parameter -Werror=unused-argument -Wpointer-arith)
324325
string(REGEX REPLACE "[^A-Za-z0-9]" "" _flagvar "${FLAG}")
325326
check_cxx_compiler_flag(${FLAG} SUPPORTS_${_flagvar})
326-
if(SUPPORTS_WARNING_${_flagvar})
327+
if(SUPPORTS_${_flagvar})
327328
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}")
328329
endif()
330+
check_c_compiler_flag(${FLAG} SUPPORTS_C_${_flagvar})
331+
if(SUPPORTS_C_${_flagvar})
332+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
333+
endif()
329334
endforeach()
330335
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
331336
endif()

src/api_layers/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,16 @@ if(WIN32)
186186
set_target_properties(copy-core_validation-def-file PROPERTIES FOLDER ${HELPER_FOLDER})
187187
elseif(APPLE)
188188
# Apple api_dump-specific information
189-
target_compile_options(XrApiLayer_api_dump PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare)
190189
set_target_properties(XrApiLayer_api_dump PROPERTIES LINK_FLAGS "-Wl")
191190

192191
# Apple core_validation-specific information
193-
target_compile_options(XrApiLayer_core_validation PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare)
194192
set_target_properties(XrApiLayer_core_validation PROPERTIES LINK_FLAGS "-Wl")
195193

196194
else()
197195
# Linux api_dump-specific information
198-
target_compile_options(XrApiLayer_api_dump PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare)
199196
set_target_properties(XrApiLayer_api_dump PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL")
200197

201198
# Linux core_validation-specific information
202-
target_compile_options(XrApiLayer_core_validation PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare)
203199
set_target_properties(XrApiLayer_core_validation PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL")
204200
endif()
205201

src/common/gfxwrapper_opengl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,10 @@ ksGpuWindowEvent ksGpuWindow_ProcessEvents(ksGpuWindow *window) {
31903190

31913191
#elif defined(OS_LINUX_WAYLAND)
31923192

3193+
#ifdef __GNUC__
3194+
#pragma GCC diagnostic push
3195+
#pragma GCC diagnostic ignored "-Wunused-parameter"
3196+
#endif
31933197
static void _keyboard_keymap_cb(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) { close(fd); }
31943198
static void _keyboard_modifiers_cb(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed,
31953199
uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {}
@@ -3337,11 +3341,16 @@ static void _registry_cb(void *data, struct wl_registry *registry, uint32_t id,
33373341

33383342
static void _registry_remove_cb(void *data, struct wl_registry *registry, uint32_t id) {}
33393343

3344+
#ifdef __GNUC__
3345+
#pragma GCC diagnostic pop
3346+
#endif
3347+
33403348
const struct wl_registry_listener registry_listener = {_registry_cb, _registry_remove_cb};
33413349

33423350
bool ksGpuWindow_Create(ksGpuWindow *window, ksDriverInstance *instance, const ksGpuQueueInfo *queueInfo, const int queueIndex,
33433351
const ksGpuSurfaceColorFormat colorFormat, const ksGpuSurfaceDepthFormat depthFormat,
33443352
const ksGpuSampleCount sampleCount, const int width, const int height, const bool fullscreen) {
3353+
(void)queueIndex;
33453354
memset(window, 0, sizeof(ksGpuWindow));
33463355

33473356
window->display = NULL;

src/loader/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,7 @@ endif()
213213
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
214214
target_compile_options(
215215
openxr_loader
216-
PRIVATE -Wall
217-
-Wextra
218-
-Wno-unused-parameter
219-
-Wno-missing-field-initializers
220-
-Wpointer-arith
216+
PRIVATE -Wextra
221217
-fno-strict-aliasing
222218
-fno-builtin-memcmp
223219
"$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>"

src/scripts/validation_layer_generator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ def outputValidationHeaderInfo(self):
589589
validation_header_info += '\n// Current API version of the Core Validation API Layer\n#define XR_CORE_VALIDATION_API_VERSION '
590590
validation_header_info += self.api_version_define
591591
validation_header_info += '\n'
592+
validation_header_info += '#if defined(__GNUC__)\n'
593+
validation_header_info += '#pragma GCC diagnostic push\n'
594+
validation_header_info += '#pragma GCC diagnostic ignored "-Wunused-parameter"\n'
595+
validation_header_info += '#pragma GCC diagnostic ignored "-Wunused-variable"\n'
596+
validation_header_info += '#endif\n'
592597

593598
validation_header_info += '\n// Externs for Core Validation\n'
594599
validation_header_info += self.outputInfoMapDeclarations(extern=True)
@@ -1001,8 +1006,6 @@ def writeValidateStructNextCheck(self, struct_type, struct_name, member, indent)
10011006
validate_struct_next += self.writeIndent(indent)
10021007
validate_struct_next += '} else if (NEXT_CHAIN_RESULT_DUPLICATE_STRUCT == next_result) {\n'
10031008
validate_struct_next += self.writeIndent(indent + 1)
1004-
validate_struct_next += 'char struct_type_buffer[XR_MAX_STRUCTURE_NAME_SIZE];\n'
1005-
validate_struct_next += self.writeIndent(indent + 1)
10061009
validate_struct_next += 'std::string error_message = "Multiple structures of the same type(s) in \\"next\\" chain for ";\n'
10071010
validate_struct_next += self.writeIndent(indent + 1)
10081011
validate_struct_next += 'error_message += "%s : ";\n' % struct_type

src/tests/hello_xr/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
8181
if(NOT D3D_DIRECTXCOLORS_INCLUDE_DIR)
8282
target_compile_definitions(hello_xr PRIVATE -DMISSING_DIRECTX_COLORS)
8383
endif()
84-
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
85-
target_compile_options(hello_xr PRIVATE -Wall)
8684
endif()
8785

8886
if(Vulkan_LIBRARY)

src/tests/list/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ if(MSVC)
4040
target_compile_options(runtime_list PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
4141
endif()
4242

43-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
44-
target_compile_options(runtime_list PRIVATE -Wall)
45-
endif()
46-
4743
set_target_properties(runtime_list PROPERTIES FOLDER ${TESTS_FOLDER})
4844
set_target_properties(runtime_list PROPERTIES OUTPUT_NAME openxr_runtime_list)
4945

src/tests/loader_test/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
5353
endif()
5454

5555
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
56-
target_compile_options(
57-
loader_test PRIVATE -Wall -Wno-unused-function -Wno-format-truncation
58-
)
56+
# No special options needed.
5957
else()
6058
message(FATAL_ERROR "Unsupported Platform")
6159
endif()

src/tests/loader_test/test_layers/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
6969
)
7070
set_target_properties(copy-test-def-file PROPERTIES FOLDER ${HELPER_FOLDER})
7171
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
72-
target_compile_options(XrApiLayer_test PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare)
7372
set_target_properties(XrApiLayer_test PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL")
7473
gen_xr_layer_json(
7574
${PROJECT_BINARY_DIR}/src/tests/loader_test/resources/layers/XrApiLayer_test.json

src/tests/loader_test/test_layers/layer_test.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
extern "C" {
4040
std::map<XrInstance, PFN_xrGetInstanceProcAddr> g_next_gipa_map;
4141

42-
XRAPI_ATTR XrResult XRAPI_CALL LayerTestXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) {
42+
XRAPI_ATTR XrResult XRAPI_CALL LayerTestXrCreateInstance(const XrInstanceCreateInfo * /* info */, XrInstance * /* instance */) {
4343
// In a layer, LayerTestXrCreateApiLayerInstance is called instead of this function. This should not be called.
4444
return XR_ERROR_FUNCTION_UNSUPPORTED;
4545
}
@@ -118,6 +118,7 @@ LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoader
118118
return XR_ERROR_INITIALIZATION_FAILED;
119119
}
120120

121+
(void)layerName;
121122
layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION;
122123
layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0);
123124
layerRequest->getInstanceProcAddr = LayerTestXrGetInstanceProcAddr;
@@ -127,9 +128,9 @@ LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoader
127128
}
128129

129130
// Always fail
130-
LAYER_EXPORT XrResult TestlayerAlwaysFailNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo *loaderInfo,
131-
const char *layerName,
132-
XrNegotiateApiLayerRequest *layerRequest) {
131+
LAYER_EXPORT XrResult TestlayerAlwaysFailNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo * /* loaderInfo */,
132+
const char * /* layerName */,
133+
XrNegotiateApiLayerRequest * /* layerRequest */) {
133134
return XR_ERROR_INITIALIZATION_FAILED;
134135
}
135136

@@ -148,7 +149,7 @@ LAYER_EXPORT XrResult TestLayerNullGipaNegotiateLoaderApiLayerInterface(const Xr
148149
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
149150
return XR_ERROR_INITIALIZATION_FAILED;
150151
}
151-
152+
(void)layerName;
152153
layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION;
153154
layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0);
154155
layerRequest->getInstanceProcAddr = nullptr;
@@ -171,7 +172,7 @@ LAYER_EXPORT XrResult TestLayerInvalidInterfaceNegotiateLoaderApiLayerInterface(
171172
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
172173
return XR_ERROR_INITIALIZATION_FAILED;
173174
}
174-
175+
(void)layerName;
175176
layerRequest->layerInterfaceVersion = 0;
176177
layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0);
177178
layerRequest->getInstanceProcAddr = reinterpret_cast<PFN_xrGetInstanceProcAddr>(LayerTestXrGetInstanceProcAddr);
@@ -194,7 +195,7 @@ LAYER_EXPORT XrResult TestLayerInvalidApiNegotiateLoaderApiLayerInterface(const
194195
loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) {
195196
return XR_ERROR_INITIALIZATION_FAILED;
196197
}
197-
198+
(void)layerName;
198199
layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION;
199200
layerRequest->layerApiVersion = 0;
200201
layerRequest->getInstanceProcAddr = reinterpret_cast<PFN_xrGetInstanceProcAddr>(LayerTestXrGetInstanceProcAddr);

0 commit comments

Comments
 (0)