Skip to content

Commit

Permalink
cmake: Use common LunarG function for build config
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 13, 2023
1 parent 09eec88 commit 13e3d99
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 37 deletions.
25 changes: 1 addition & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,7 @@ if (BUILD_WERROR)
add_compile_options("$<IF:$<CXX_COMPILER_ID:MSVC>,/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("$<$<CONFIG:Release>:/Zi>")
add_link_options("$<$<CONFIG:Release>:/DEBUG:FULL>")
Expand All @@ -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($<$<BOOL:${MSVC_IDE}>:/MP>) # Speed up Visual Studio builds
endif()

option(VEL_CODEGEN "Enable code generation")
Expand Down
2 changes: 1 addition & 1 deletion layers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 10 additions & 12 deletions layers/timeline_semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
41 changes: 41 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<BOOL:${MSVC_IDE}>:/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()
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<IF:$<CXX_COMPILER_ID:MSVC>,/wd4100,-Wno-unused-parameter>")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)")
Expand Down

0 comments on commit 13e3d99

Please sign in to comment.