From 0b7c4279717cbfee40b79efc7b93d325d43574bc Mon Sep 17 00:00:00 2001 From: Juan Ramos Date: Tue, 29 Nov 2022 10:25:24 -0700 Subject: [PATCH] MSVC cleanup MSVC compiler can be used with Ninja as well. However, the current CMake code doesn't account for it. --- src/CMakeLists.txt | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 879eaee..659382f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,19 +1,17 @@ -set(VMA_LIBRARY_SOURCE_FILES - VmaUsage.cpp - VmaUsage.h - "${PROJECT_SOURCE_DIR}/include/vk_mem_alloc.h" -) - -# Visual Studio only debugger symbols -if(WIN32 AND ${CMAKE_GENERATOR} MATCHES "Visual Studio.*") - set(VMA_LIBRARY_SOURCE_FILES ${VMA_LIBRARY_SOURCE_FILES} vk_mem_alloc.natvis) -endif() - set(CMAKE_DEBUG_POSTFIX d) set(CMAKE_RELWITHDEBINFO_POSTFIX rd) set(CMAKE_MINSIZEREL_POSTFIX s) -add_library(VulkanMemoryAllocator ${VMA_LIBRARY_SOURCE_FILES}) +add_library(VulkanMemoryAllocator + VmaUsage.cpp + VmaUsage.h + ${PROJECT_SOURCE_DIR}/include/vk_mem_alloc.h +) + +if (MSVC) + # Provides MSVC users nicer debugging support + target_sources(VulkanMemoryAllocator PRIVATE ${CMAKE_CURRENT_LIST_DIR}/vk_mem_alloc.natvis) +endif() set_target_properties( VulkanMemoryAllocator PROPERTIES @@ -63,20 +61,19 @@ if(VMA_BUILD_SAMPLE) add_executable(VmaSample ${VMA_SAMPLE_SOURCE_FILES}) add_dependencies(VmaSample VulkanMemoryAllocator VmaSampleShaders) - # Visual Studio specific settings - if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") + if(MSVC) # Use Unicode instead of multibyte set add_compile_definitions(UNICODE _UNICODE) - # Set VmaSample as startup project - set_property(DIRECTORY "${PROJECT_SOURCE_DIR}" PROPERTY VS_STARTUP_PROJECT "VmaSample") - # Add C++ warnings and security checks - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive- /sdl /W3") + add_compile_options(/permissive- /sdl /W3) # Enable multithreaded compiling target_compile_options(VmaSample PRIVATE "/MP") + # Set VmaSample as startup project + set_property(DIRECTORY "${PROJECT_SOURCE_DIR}" PROPERTY VS_STARTUP_PROJECT "VmaSample") + # Set working directory for Visual Studio debugger set_target_properties( VmaSample