Skip to content

Commit

Permalink
cmake: Use W4 warnings on MSVC to match GCC/Clang warning level
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 6, 2023
1 parent 4d4015e commit 4b39429
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ if (VUL_WERROR)
endif()
endif()

if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)")
add_compile_options(
-Wall
-Wextra
)
endif()
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/W4,-Wall -Wextra>")

add_library(VulkanUtilityHeaders INTERFACE)
add_library(Vulkan::UtilityHeaders ALIAS VulkanUtilityHeaders)
Expand Down
2 changes: 1 addition & 1 deletion src/layer/vk_layer_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ VkResult vlGetLayerSettingValues(VlLayerSettingSet layerSettingSet, const char *
for (std::size_t i = 0, n = values.size(); i < n; ++i) {
const std::string &setting_value = vl::ToLower(settings[i]);
if (vl::IsFloat(setting_value)) {
values[i] = std::atof(setting_value.c_str());
values[i] = static_cast<float>(std::atof(setting_value.c_str()));
} else {
const std::string &message =
vl::FormatString("The data provided (%s) is not a floating-point value.", setting_value.c_str());
Expand Down
33 changes: 21 additions & 12 deletions tests/layer/test_setting_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
//
// Author(s):
// - Christophe Riccio <[email protected]>

#include <gtest/gtest.h>

#include "vulkan/layer/vk_layer_settings.h"
#include <vector>
#include <cstdlib>

static void SetEnv(const char* value) {
#ifdef _WIN32
_putenv(value);
#else
putenv(const_cast<char *>(value));
#endif
}

TEST(test_layer_setting_env, EnvVar_TrimNone) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING_A=true,false"));
SetEnv("VK_LUNARG_TEST_MY_SETTING_A=true,false");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand All @@ -38,7 +47,7 @@ TEST(test_layer_setting_env, EnvVar_TrimNone) {
}

TEST(test_layer_setting_env, EnvVar_TrimVendor) {
putenv(const_cast<char *>("VK_TEST_MY_SETTING_B=true,false"));
SetEnv("VK_TEST_MY_SETTING_B=true,false");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand All @@ -63,7 +72,7 @@ TEST(test_layer_setting_env, EnvVar_TrimVendor) {
}

TEST(test_layer_setting_env, EnvVar_TrimNamespace) {
putenv(const_cast<char *>("VK_MY_SETTING_C=true,false"));
SetEnv("VK_MY_SETTING_C=true,false");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand All @@ -88,7 +97,7 @@ TEST(test_layer_setting_env, EnvVar_TrimNamespace) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Bool) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=true,false"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=true,false");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -123,7 +132,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Bool) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Int32) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76,-82"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76,-82");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -158,7 +167,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Int32) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Int64) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76,-82"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76,-82");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -193,7 +202,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Int64) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Uint32) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76,82"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76,82");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -228,7 +237,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Uint32) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Uint64) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76,82"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76,82");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -263,7 +272,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Uint64) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Float) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76.1f,-82.5f"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76.1f,-82.5f");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -297,7 +306,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Float) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Double) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76.1,-82.5"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76.1,-82.5");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -331,7 +340,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Double) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_Frameset) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=76-100-10,1-100-1"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=76-100-10,1-100-1");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down Expand Up @@ -371,7 +380,7 @@ TEST(test_layer_setting_env, vlGetLayerSettingValues_Frameset) {
}

TEST(test_layer_setting_env, vlGetLayerSettingValues_String) {
putenv(const_cast<char *>("VK_LUNARG_TEST_MY_SETTING=VALUE_A,VALUE_B"));
SetEnv("VK_LUNARG_TEST_MY_SETTING=VALUE_A,VALUE_B");

VlLayerSettingSet layerSettingSet = VK_NULL_HANDLE;
vlCreateLayerSettingSet("VK_LAYER_LUNARG_test", nullptr, nullptr, nullptr, &layerSettingSet);
Expand Down
2 changes: 1 addition & 1 deletion tests/layer/test_setting_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ TEST(test_layer_settings_util, ToInt32) {
EXPECT_EQ(24, vl::ToInt32("24"));
EXPECT_EQ(-24, vl::ToInt32("-24"));
EXPECT_EQ(2147483647, vl::ToInt32("2147483647"));
EXPECT_EQ(-2147483648, vl::ToInt32("-2147483648"));
EXPECT_EQ(-2147483647, vl::ToInt32("-2147483647"));
EXPECT_EQ(65535, vl::ToInt32("0xFFFF"));
EXPECT_EQ(-65535, vl::ToInt32("-0xFFFF"));
EXPECT_EQ(15, vl::ToInt32("0xF"));
Expand Down

0 comments on commit 4b39429

Please sign in to comment.