Skip to content
Snippets Groups Projects
Commit 2503e8bd authored by Simon McVittie's avatar Simon McVittie
Browse files

Merge branch 'wip/smcv/warn-more' into 'master'

Enable and squash compiler warnings

See merge request steam/steam-runtime-tools!82
parents 8bb16389 270fa6d8
No related branches found
No related tags found
1 merge request!82Enable and squash compiler warnings
Pipeline #1945 passed
...@@ -49,12 +49,23 @@ ubsan: ...@@ -49,12 +49,23 @@ ubsan:
clang-tools \ clang-tools \
${NULL+} ${NULL+}
rm -fr builddir
meson \
-Db_lundef=false \
-Db_sanitize=address,undefined \
--werror \
builddir
ninja -C builddir
meson test -C builddir -v
export CC=clang export CC=clang
export CXX=clang++
rm -fr builddir rm -fr builddir
meson \ meson \
-Db_lundef=false \ -Db_lundef=false \
-Db_sanitize=address,undefined \ -Db_sanitize=address,undefined \
--werror \
builddir builddir
ninja -C builddir scan-build ninja -C builddir scan-build
meson test -C builddir -v meson test -C builddir -v
...@@ -11,6 +11,12 @@ ifeq ($(shell dpkg --compare-versions `c++ -dumpversion || echo 0` ge 4.8 || ech ...@@ -11,6 +11,12 @@ ifeq ($(shell dpkg --compare-versions `c++ -dumpversion || echo 0` ge 4.8 || ech
export CXX = g++-4.8 export CXX = g++-4.8
endif endif
meson_options =
ifeq ($(DEB_DISTRIBUTION),UNRELEASED)
meson_options += --werror
endif
gtk_doc_has_cflags := $(shell \ gtk_doc_has_cflags := $(shell \
if gtkdoc-scangobj --help 2>&1 | grep '[-]-cflags' >/dev/null; then \ if gtkdoc-scangobj --help 2>&1 | grep '[-]-cflags' >/dev/null; then \
echo true; \ echo true; \
...@@ -42,7 +48,7 @@ override_dh_auto_configure: ...@@ -42,7 +48,7 @@ override_dh_auto_configure:
-Dgtk_doc=$(gtk_doc_has_cflags) \ -Dgtk_doc=$(gtk_doc_has_cflags) \
-Dintrospection=false \ -Dintrospection=false \
-Dmultiarch_tuple=$(DEB_HOST_MULTIARCH) \ -Dmultiarch_tuple=$(DEB_HOST_MULTIARCH) \
$(NULL) $(meson_options)
override_dh_auto_build: override_dh_auto_build:
ninja -C builddir ninja -C builddir
......
...@@ -783,50 +783,50 @@ private: ...@@ -783,50 +783,50 @@ private:
} }
} }
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device) { SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice dev) {
SwapChainSupportDetails details; SwapChainSupportDetails details;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities); vkGetPhysicalDeviceSurfaceCapabilitiesKHR(dev, surface, &details.capabilities);
uint32_t formatCount; uint32_t formatCount;
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr); vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, nullptr);
if (formatCount != 0) { if (formatCount != 0) {
details.formats.resize(formatCount); details.formats.resize(formatCount);
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data()); vkGetPhysicalDeviceSurfaceFormatsKHR(dev, surface, &formatCount, details.formats.data());
} }
uint32_t presentModeCount; uint32_t presentModeCount;
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr); vkGetPhysicalDeviceSurfacePresentModesKHR(dev, surface, &presentModeCount, nullptr);
if (presentModeCount != 0) { if (presentModeCount != 0) {
details.presentModes.resize(presentModeCount); details.presentModes.resize(presentModeCount);
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data()); vkGetPhysicalDeviceSurfacePresentModesKHR(dev, surface, &presentModeCount, details.presentModes.data());
} }
return details; return details;
} }
bool isDeviceSuitable(VkPhysicalDevice device) { bool isDeviceSuitable(VkPhysicalDevice dev) {
QueueFamilyIndices indices = findQueueFamilies(device); QueueFamilyIndices indices = findQueueFamilies(dev);
bool extensionsSupported = checkDeviceExtensionSupport(device); bool extensionsSupported = checkDeviceExtensionSupport(dev);
bool swapChainAdequate = false; bool swapChainAdequate = false;
if (extensionsSupported) { if (extensionsSupported) {
SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device); SwapChainSupportDetails swapChainSupport = querySwapChainSupport(dev);
swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty(); swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();
} }
return indices.isComplete() && extensionsSupported && swapChainAdequate; return indices.isComplete() && extensionsSupported && swapChainAdequate;
} }
bool checkDeviceExtensionSupport(VkPhysicalDevice device) { bool checkDeviceExtensionSupport(VkPhysicalDevice dev) {
uint32_t extensionCount; uint32_t extensionCount;
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, nullptr);
std::vector<VkExtensionProperties> availableExtensions(extensionCount); std::vector<VkExtensionProperties> availableExtensions(extensionCount);
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data()); vkEnumerateDeviceExtensionProperties(dev, nullptr, &extensionCount, availableExtensions.data());
std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end()); std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());
...@@ -837,16 +837,16 @@ private: ...@@ -837,16 +837,16 @@ private:
return requiredExtensions.empty(); return requiredExtensions.empty();
} }
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) { QueueFamilyIndices findQueueFamilies(VkPhysicalDevice dev) {
QueueFamilyIndices indices; QueueFamilyIndices indices;
indices.hasGraphicsFamily = false; indices.hasGraphicsFamily = false;
indices.hasPresentFamily = false; indices.hasPresentFamily = false;
uint32_t queueFamilyCount = 0; uint32_t queueFamilyCount = 0;
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr); vkGetPhysicalDeviceQueueFamilyProperties(dev, &queueFamilyCount, nullptr);
std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount); std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);
vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data()); vkGetPhysicalDeviceQueueFamilyProperties(dev, &queueFamilyCount, queueFamilies.data());
int i = 0; int i = 0;
for (const auto& queueFamily : queueFamilies) { for (const auto& queueFamily : queueFamilies) {
...@@ -856,7 +856,7 @@ private: ...@@ -856,7 +856,7 @@ private:
} }
VkBool32 presentSupport = false; VkBool32 presentSupport = false;
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport); vkGetPhysicalDeviceSurfaceSupportKHR(dev, i, surface, &presentSupport);
if (queueFamily.queueCount > 0 && presentSupport) { if (queueFamily.queueCount > 0 && presentSupport) {
indices.presentFamily = i; indices.presentFamily = i;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
executable( executable(
multiarch + '-true', multiarch + '-true',
'true.c', 'true.c',
include_directories : project_include_dirs,
install : true, install : true,
install_dir : pkglibexecdir, install_dir : pkglibexecdir,
# Deliberately no RPATH/RUNPATH here: it's unnecessary because this # Deliberately no RPATH/RUNPATH here: it's unnecessary because this
...@@ -46,6 +47,7 @@ executable( ...@@ -46,6 +47,7 @@ executable(
multiarch + '-inspect-library', multiarch + '-inspect-library',
'inspect-library.c', 'inspect-library.c',
dependencies : [libdl], dependencies : [libdl],
include_directories : project_include_dirs,
install : true, install : true,
install_dir : pkglibexecdir, install_dir : pkglibexecdir,
# Deliberately no RPATH/RUNPATH here: we want to determine whether # Deliberately no RPATH/RUNPATH here: we want to determine whether
...@@ -56,6 +58,7 @@ executable( ...@@ -56,6 +58,7 @@ executable(
multiarch + '-check-vulkan', multiarch + '-check-vulkan',
'check-vulkan.cpp', 'check-vulkan.cpp',
dependencies : [vulkan, xcb], dependencies : [vulkan, xcb],
include_directories : project_include_dirs,
install : true, install : true,
install_dir : join_paths( install_dir : join_paths(
get_option('libexecdir'), get_option('libexecdir'),
......
...@@ -21,9 +21,15 @@ ...@@ -21,9 +21,15 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
project('steam-runtime-tools', 'c', project(
version : '0.20191024.0', 'steam-runtime-tools', 'c',
default_options: ['cpp_std=c++11']) version : '0.20191024.0',
default_options: [
'c_std=c99',
'cpp_std=c++11',
'warning_level=2',
],
)
add_languages('cpp') add_languages('cpp')
api_major = '0' api_major = '0'
...@@ -49,31 +55,24 @@ endif ...@@ -49,31 +55,24 @@ endif
glslang_validator = find_program('glslangValidator', required : true) glslang_validator = find_program('glslangValidator', required : true)
warning_cflags = [ warning_flags = [
'-Wall', '-Wall',
'-Wextra', '-Wextra',
'-Warray-bounds', '-Warray-bounds',
'-Wcast-align', '-Wcast-align',
'-Wdeclaration-after-statement',
'-Wdouble-promotion', '-Wdouble-promotion',
'-Wduplicated-branches', '-Wduplicated-branches',
'-Wduplicated-cond', '-Wduplicated-cond',
'-Wformat-nonliteral', '-Wformat-nonliteral',
'-Wformat-security', '-Wformat-security',
'-Wformat=2', '-Wformat=2',
'-Wimplicit-function-declaration',
'-Winit-self', '-Winit-self',
'-Winline',
'-Wjump-misses-init',
'-Wlogical-op', '-Wlogical-op',
'-Wmissing-declarations', '-Wmissing-declarations',
'-Wmissing-format-attribute', '-Wmissing-format-attribute',
'-Wmissing-include-dirs', '-Wmissing-include-dirs',
'-Wmissing-noreturn', '-Wmissing-noreturn',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wnull-dereference', '-Wnull-dereference',
'-Wold-style-definition',
'-Wpacked', '-Wpacked',
'-Wpointer-arith', '-Wpointer-arith',
'-Wredundant-decls', '-Wredundant-decls',
...@@ -81,27 +80,46 @@ warning_cflags = [ ...@@ -81,27 +80,46 @@ warning_cflags = [
'-Wreturn-type', '-Wreturn-type',
'-Wshadow', '-Wshadow',
'-Wstrict-aliasing', '-Wstrict-aliasing',
'-Wstrict-prototypes',
'-Wswitch-default', '-Wswitch-default',
'-Wswitch-enum', '-Wswitch-enum',
'-Wundef', '-Wundef',
'-Wunused-but-set-variable', '-Wunused-but-set-variable',
'-Wwrite-strings', '-Wwrite-strings',
] ]
no_warning_cflags = [ warning_cflags = warning_flags + [
'declaration-after-statement', '-Wimplicit-function-declaration',
'-Wjump-misses-init',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wold-style-definition',
'-Wstrict-prototypes',
]
warning_cxxflags = warning_flags + [
]
no_warning_flags = [
'inline',
'missing-field-initializers', 'missing-field-initializers',
'pedantic',
'sign-compare', 'sign-compare',
'unused-local-typedefs', 'unused-local-typedefs',
'unused-parameter', 'unused-parameter',
] ]
no_warning_cflags = no_warning_flags + [
'declaration-after-statement',
]
no_warning_cxxflags = no_warning_flags + [
]
c_compiler = meson.get_compiler('c') c_compiler = meson.get_compiler('c')
cpp_compiler = meson.get_compiler('cpp')
supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags) supported_warning_cflags = c_compiler.get_supported_arguments(warning_cflags)
add_project_arguments(supported_warning_cflags, language : 'c') add_project_arguments(supported_warning_cflags, language : 'c')
supported_warning_cxxflags = cpp_compiler.get_supported_arguments(warning_cxxflags)
add_project_arguments(supported_warning_cxxflags, language : 'cpp')
add_project_arguments( add_project_link_arguments(
c_compiler.get_supported_arguments( c_compiler.get_supported_link_arguments(
'-Wl,-z,origin', '-Wl,-z,origin',
# Generate RPATH in preference to RUNPATH, even if RUNPATH is the # Generate RPATH in preference to RUNPATH, even if RUNPATH is the
# linker's default. We want RPATH here, because it's used recursively # linker's default. We want RPATH here, because it's used recursively
...@@ -121,18 +139,31 @@ foreach flag : no_warning_cflags ...@@ -121,18 +139,31 @@ foreach flag : no_warning_cflags
add_project_arguments(supported_no_warning_cflags, language : 'c') add_project_arguments(supported_no_warning_cflags, language : 'c')
endforeach endforeach
foreach flag : no_warning_cxxflags
supported_no_warning_cxxflags = cpp_compiler.get_supported_arguments([
'-Wno-error=' + flag,
'-Wno-' + flag,
])
add_project_arguments(supported_no_warning_cxxflags, language : 'cpp')
endforeach
conf_data = configuration_data() conf_data = configuration_data()
conf_data.set('_GNU_SOURCE', '1')
conf_data.set_quoted('VERSION', meson.project_version()) conf_data.set_quoted('VERSION', meson.project_version())
configure_file( configure_file(
output : 'config.h', output : '_steam-runtime-tools-config.h',
configuration : conf_data, configuration : conf_data,
) )
add_project_arguments(['-std=c99'], language : 'c') add_project_arguments(
add_project_arguments(['-D_GNU_SOURCE'], language : 'c') ['-include', '_steam-runtime-tools-config.h'],
add_project_arguments(['-include', 'config.h'], language : 'c') language : 'c',
add_project_arguments(['-include', 'config.h'], language : 'cpp') )
add_project_arguments(
['-include', '_steam-runtime-tools-config.h'],
language : 'cpp',
)
glib = dependency( glib = dependency(
'glib-2.0', 'glib-2.0',
......
...@@ -65,6 +65,7 @@ install_subdir('sysroots', install_dir : tests_dir) ...@@ -65,6 +65,7 @@ install_subdir('sysroots', install_dir : tests_dir)
executable( executable(
'mock-true', 'mock-true',
join_paths('..', 'helpers', 'true.c'), join_paths('..', 'helpers', 'true.c'),
include_directories : project_include_dirs,
install : get_option('installed_tests'), install : get_option('installed_tests'),
install_dir : tests_dir, install_dir : tests_dir,
) )
...@@ -77,6 +78,7 @@ foreach test_name : tests ...@@ -77,6 +78,7 @@ foreach test_name : tests
'-D_SRT_MULTIARCH="' + multiarch + '"', '-D_SRT_MULTIARCH="' + multiarch + '"',
], ],
dependencies : [glib, gobject, libsteamrt_dep, json_glib], dependencies : [glib, gobject, libsteamrt_dep, json_glib],
include_directories : project_include_dirs,
install : get_option('installed_tests'), install : get_option('installed_tests'),
install_dir : tests_dir, install_dir : tests_dir,
) )
...@@ -146,6 +148,7 @@ executable( ...@@ -146,6 +148,7 @@ executable(
executable( executable(
'mock-good-wflinfo', 'mock-good-wflinfo',
'mock-good-wflinfo.c', 'mock-good-wflinfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -153,6 +156,7 @@ executable( ...@@ -153,6 +156,7 @@ executable(
executable( executable(
'mock-hanging-wflinfo', 'mock-hanging-wflinfo',
'mock-hanging-wflinfo.c', 'mock-hanging-wflinfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -160,6 +164,7 @@ executable( ...@@ -160,6 +164,7 @@ executable(
executable( executable(
'mock-bad-wflinfo', 'mock-bad-wflinfo',
'mock-bad-wflinfo.c', 'mock-bad-wflinfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -167,6 +172,7 @@ executable( ...@@ -167,6 +172,7 @@ executable(
executable( executable(
'mock-software-wflinfo', 'mock-software-wflinfo',
'mock-software-wflinfo.c', 'mock-software-wflinfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -174,6 +180,7 @@ executable( ...@@ -174,6 +180,7 @@ executable(
executable( executable(
'mock-good-vulkaninfo', 'mock-good-vulkaninfo',
'mock-good-vulkaninfo.c', 'mock-good-vulkaninfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -181,6 +188,7 @@ executable( ...@@ -181,6 +188,7 @@ executable(
executable( executable(
'mock-bad-vulkaninfo', 'mock-bad-vulkaninfo',
'mock-bad-vulkaninfo.c', 'mock-bad-vulkaninfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -188,6 +196,7 @@ executable( ...@@ -188,6 +196,7 @@ executable(
executable( executable(
'mock-good-check-vulkan', 'mock-good-check-vulkan',
join_paths('..', 'helpers', 'true.c'), join_paths('..', 'helpers', 'true.c'),
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -195,6 +204,7 @@ executable( ...@@ -195,6 +204,7 @@ executable(
executable( executable(
'mock-bad-check-vulkan', 'mock-bad-check-vulkan',
'mock-bad-check-vulkan.c', 'mock-bad-check-vulkan.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -202,6 +212,7 @@ executable( ...@@ -202,6 +212,7 @@ executable(
executable( executable(
'mock-mixed-vulkaninfo', 'mock-mixed-vulkaninfo',
'mock-good-vulkaninfo.c', 'mock-good-vulkaninfo.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
...@@ -209,6 +220,7 @@ executable( ...@@ -209,6 +220,7 @@ executable(
executable( executable(
'mock-mixed-check-vulkan', 'mock-mixed-check-vulkan',
'mock-bad-check-vulkan.c', 'mock-bad-check-vulkan.c',
include_directories : project_include_dirs,
install: true, install: true,
install_dir: tests_dir install_dir: tests_dir
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment