diff --git a/CMakeLists.txt b/CMakeLists.txt index 91af0d88..9f749058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,28 +73,7 @@ if (BUILD_WERROR) add_compile_options("$,/WX,-Werror>") endif() -if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)") - add_compile_options( - -Wall - -Wextra - -Wpointer-arith - ) - if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - add_compile_options( - -Wconversion - -Wimplicit-fallthrough - -Wstring-conversion - ) - endif() -elseif(MSVC) - add_compile_options( - /W4 - /we5038 # Enable warning about MIL ordering in constructors - ) - - # Enforce stricter ISO C++ - add_compile_options(/permissive-) - +if(MSVC) # PDBs aren't generated on Release builds by default. add_compile_options("$<$:/Zi>") add_link_options("$<$:/DEBUG:FULL>") @@ -105,8 +84,6 @@ elseif(MSVC) # Allow usage of unsafe CRT functions and minimize what Windows.h leaks add_compile_definitions(_CRT_SECURE_NO_WARNINGS NOMINMAX WIN32_LEAN_AND_MEAN) - - add_compile_options($<$:/MP>) # Speed up Visual Studio builds endif() option(VEL_CODEGEN "Enable code generation") diff --git a/layers/CMakeLists.txt b/layers/CMakeLists.txt index 4f2c202c..cbadd1a4 100644 --- a/layers/CMakeLists.txt +++ b/layers/CMakeLists.txt @@ -45,8 +45,8 @@ if (NOT WIN32) endif() foreach(extension_layer ${EXTENSION_LAYERS}) + lunarg_target_compiler_configurations(${extension_layer} ${BUILD_WERROR}) target_include_directories(${extension_layer} PRIVATE .) - target_link_libraries(${extension_layer} PRIVATE VkExtLayer_utils Vulkan::LayerSettings) if(MSVC) diff --git a/layers/timeline_semaphore.c b/layers/timeline_semaphore.c index 5b7b85c9..ca1e66fe 100644 --- a/layers/timeline_semaphore.c +++ b/layers/timeline_semaphore.c @@ -1059,8 +1059,10 @@ static void timeline_DestroySemaphore( struct device_data *device = object_find(&global_map, _device); struct timeline_semaphore *semaphore = object_find(&device->semaphores, (void*)(uintptr_t)_semaphore); - if (!semaphore) - return device->vtable.DestroySemaphore(_device, _semaphore, pAllocator); + if (!semaphore) { + device->vtable.DestroySemaphore(_device, _semaphore, pAllocator); + return; + } pthread_mutex_lock(&device->lock); @@ -2084,9 +2086,9 @@ static void timeline_GetPhysicalDeviceExternalSemaphoreProperties( vk_find_struct_const(pExternalSemaphoreInfo->pNext, SEMAPHORE_TYPE_CREATE_INFO_KHR); if (!type_info || type_info->semaphoreType != VK_SEMAPHORE_TYPE_TIMELINE_KHR) { - return instance->vtable.GetPhysicalDeviceExternalSemaphoreProperties(physicalDevice, - pExternalSemaphoreInfo, - pExternalSemaphoreProperties); + instance->vtable.GetPhysicalDeviceExternalSemaphoreProperties(physicalDevice, pExternalSemaphoreInfo, + pExternalSemaphoreProperties); + return; } pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0; @@ -2521,8 +2523,7 @@ static void *find_ptr(const char *name, bool isInstance) VEL_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice _device, const char *funcName) { void *ptr = find_ptr(funcName, false); - if (ptr) - return ptr; + if (ptr) return (PFN_vkVoidFunction)ptr; if (_device == NULL) return NULL; @@ -2534,12 +2535,9 @@ VEL_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice VEL_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance _instance, const char *funcName) { void *ptr = find_ptr(funcName, true); + if (!ptr) ptr = find_ptr(funcName, false); - if (!ptr) - ptr = find_ptr(funcName, false); - - if (ptr) - return ptr; + if (ptr) return (PFN_vkVoidFunction)ptr; if (_instance == NULL) return NULL; diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 519b4e89..cb597af5 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -104,6 +104,47 @@ if (UPDATE_DEPS) include("${UPDATE_DEPS_DIR}/helper.cmake") endif() endif() + +# Configure compiler build options common to all targets +function(lunarg_target_compiler_configurations TARGET_NAME WERROR_OPTION) + if (${WERROR_OPTION}) + if (MSVC) + target_compile_options(${TARGET_NAME} INTERFACE /WX) + target_link_options(${TARGET_NAME} INTERFACE /WX) + else() + target_compile_options(${TARGET_NAME} INTERFACE -Werror) + endif() + endif() + + if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)") + target_compile_options(${TARGET_NAME} INTERFACE + -Wall + -Wextra + -Wpointer-arith + ) + if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + target_compile_options(${TARGET_NAME} INTERFACE + -Wconversion + -Wimplicit-fallthrough + -Wstring-conversion + ) + endif() + elseif(MSVC) + target_compile_options(${TARGET_NAME} INTERFACE + /W4 + /we5038 # Enable warning about MIL ordering in constructors + ) + + # Enforce stricter ISO C++ + target_compile_options(${TARGET_NAME} INTERFACE /permissive-) + + target_compile_options(${TARGET_NAME} INTERFACE $<$:/MP>) # Speed up Visual Studio builds + + # Allow usage of unsafe CRT functions and minimize what Windows.h leaks + target_compile_definitions(${TARGET_NAME} INTERFACE _CRT_SECURE_NO_WARNINGS NOMINMAX WIN32_LEAN_AND_MEAN) + endif() +endfunction() + if (SPIRV_HEADERS_INSTALL_DIR) list(APPEND CMAKE_PREFIX_PATH ${SPIRV_HEADERS_INSTALL_DIR}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9323cb5c..0cd24ae1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,8 @@ else() ) endif() +lunarg_target_compiler_configurations(vk_extension_layer_tests ${BUILD_WERROR}) + target_sources(vk_extension_layer_tests PRIVATE extension_layer_tests.cpp synchronization2_tests.cpp diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 2d251243..6f8156a5 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -24,6 +24,8 @@ target_sources(VkExtLayer_utils PRIVATE generated/lvt_function_pointers.cpp ) +lunarg_target_compiler_configurations(VkExtLayer_utils ${BUILD_WERROR}) + # TODO: Fix warnings target_compile_options(VkExtLayer_utils PUBLIC "$,/wd4100,-Wno-unused-parameter>") if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)")