Cleanup MSVC CMake code
authorCharles Giessen <charles@lunarg.com>
Wed, 16 Feb 2022 20:24:26 +0000 (13:24 -0700)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 9 Mar 2022 22:06:30 +0000 (15:06 -0700)
* Googletest has been updated to 1.11 which means the TR1 deprecation notice is
unecessary.

* The `/permissive-` flag has been moved to loader_common_options so it doesn't
have to be repeated over and over.

* Since we do not support VS 2013 and early, use /guard:cf everywhere

* Remove MSVC_LOADER_COMPILE_OPTIONS in favor of loader_common_options

* Remove reduntant compile options and include directories

CMakeLists.txt
loader/CMakeLists.txt
tests/framework/CMakeLists.txt
tests/framework/icd/CMakeLists.txt
tests/framework/layer/CMakeLists.txt

index 6d30924b11d7ad44e566e1d86e56ce739bea3b99..89a109aab7e2a2e324e308144b1703ba1b1bb2f7 100644 (file)
@@ -300,7 +300,13 @@ if(MSVC)
     # /w34701, /w34703: Warn about potentially uninitialized variables
     # /w34057: Warn about different indirection types.
     # /w34245: Warn about signed/unsigned mismatch.
-    target_compile_options(loader_common_options INTERFACE /WX /GR- /w34456 /w34701 /w34703 /w34057 /w34245)
+    # /guard:cf: Enable control flow guard
+    # /permissive-: Use standard conformance mode
+    target_compile_options(loader_common_options INTERFACE /WX /GR- /w34456 /w34701 /w34703 /w34057 /w34245 /guard:cf /permissive-)
+
+    # Enable control flow guard
+    list(APPEND CMAKE_SHARED_LINKER_FLAGS /guard:cf)
+    list(APPEND CMAKE_EXE_LINKER_FLAGS /guard:cf)
 
     # Prevent <windows.h> from polluting the code. guards against things like MIN and MAX
     target_compile_definitions(loader_common_options INTERFACE WIN32_LEAN_AND_MEAN)
index 505872781f9a0b2abc031bb47730a28878ab4c96..1f4bd6afeb23239e64a9bbfb3ce83d7b40e1542c 100644 (file)
@@ -41,37 +41,27 @@ if(NOT MSVC AND NOT (HAVE_SECURE_GETENV OR HAVE___SECURE_GETENV))
     message(WARNING "Using non-secure environmental lookups. This loader will not properly disable environent variables when run with elevated permissions.")
 endif()
 
-if(WIN32)
-    if(MSVC AND NOT MSVC_VERSION LESS 1900)
-        # Enable control flow guard
-        message(STATUS "Building loader with control flow guard")
-        set(MSVC_LOADER_COMPILE_OPTIONS ${MSVC_LOADER_COMPILE_OPTIONS} /guard:cf)
-        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
-        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /guard:cf")
-    endif()
-endif()
-
 if(WIN32)
     if(MSVC)
-    # Use static MSVCRT libraries
-    foreach(configuration
-            in
-            CMAKE_C_FLAGS_DEBUG
-            CMAKE_C_FLAGS_MINSIZEREL
-            CMAKE_C_FLAGS_RELEASE
-            CMAKE_C_FLAGS_RELWITHDEBINFO
-            CMAKE_CXX_FLAGS_DEBUG
-            CMAKE_CXX_FLAGS_MINSIZEREL
-            CMAKE_CXX_FLAGS_RELEASE
-            CMAKE_CXX_FLAGS_RELWITHDEBINFO)
-        if(${configuration} MATCHES "/MD")
-            string(REGEX
-                   REPLACE "/MD"
-                           "/MT"
-                           ${configuration}
-                           "${${configuration}}")
-        endif()
-    endforeach()
+        # Use static MSVCRT libraries
+        foreach(configuration
+                in
+                CMAKE_C_FLAGS_DEBUG
+                CMAKE_C_FLAGS_MINSIZEREL
+                CMAKE_C_FLAGS_RELEASE
+                CMAKE_C_FLAGS_RELWITHDEBINFO
+                CMAKE_CXX_FLAGS_DEBUG
+                CMAKE_CXX_FLAGS_MINSIZEREL
+                CMAKE_CXX_FLAGS_RELEASE
+                CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+            if(${configuration} MATCHES "/MD")
+                string(REGEX
+                    REPLACE "/MD"
+                            "/MT"
+                            ${configuration}
+                            "${${configuration}}")
+            endif()
+        endforeach()
     endif()
 
     if(ENABLE_WIN10_ONECORE)
@@ -81,7 +71,7 @@ if(WIN32)
         set(CMAKE_C_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES})
     endif()
 
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
+    target_compile_options(loader_specific_options INTERFACE -D_CRT_SECURE_NO_WARNINGS)
     # ~~~
     # Build dev_ext_trampoline.c and unknown_ext_chain.c with /O2 to allow tail-call optimization.
     # Setup two CMake targets (loader-norm and loader-opt) for the different compilation flags.
@@ -180,6 +170,7 @@ if(WIN32)
         set_target_properties(loader_asm_gen_files PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})
         add_library(loader-unknown-chain OBJECT unknown_ext_chain_masm.asm)
         target_link_libraries(loader-unknown-chain Vulkan::Headers)
+        target_include_directories(loader-unknown-chain PUBLIC $<TARGET_PROPERTY:loader_asm_gen_files,BINARY_DIR>)
         add_dependencies(loader-unknown-chain loader_asm_gen_files)
     else()
         message(WARNING "Could not find working MASM assebler\n${ASM_FAILURE_MSG}")
@@ -187,7 +178,6 @@ if(WIN32)
         add_library(loader-unknown-chain OBJECT unknown_ext_chain.c)
         target_link_libraries(loader-unknown-chain loader_specific_options)
         set_target_properties(loader-unknown-chain PROPERTIES CMAKE_C_FLAGS_DEBUG "${MODIFIED_C_FLAGS_DEBUG}")
-        target_compile_options(loader-unknown-chain PUBLIC ${MSVC_LOADER_COMPILE_OPTIONS})
     endif()
 elseif(APPLE)
     # For MacOS, use the C code and force the compiler's tail-call optimization instead of using assembly code.
@@ -241,8 +231,6 @@ if(WIN32)
     target_link_libraries(loader-opt PUBLIC loader_specific_options)
     add_dependencies(loader-opt loader_asm_gen_files)
     set_target_properties(loader-opt PROPERTIES CMAKE_C_FLAGS_DEBUG "${MODIFIED_C_FLAGS_DEBUG}")
-    target_compile_options(loader-opt PUBLIC ${MSVC_LOADER_COMPILE_OPTIONS})
-    target_include_directories(loader-opt PRIVATE "$<TARGET_PROPERTY:Vulkan::Headers,INTERFACE_INCLUDE_DIRECTORIES>")
 
     add_library(vulkan
                 SHARED
@@ -252,8 +240,6 @@ if(WIN32)
                 ${CMAKE_CURRENT_LIST_DIR}/loader.rc)
 
     target_link_libraries(vulkan loader_specific_options loader-opt)
-    target_compile_options(vulkan PUBLIC ${MSVC_LOADER_COMPILE_OPTIONS})
-    target_include_directories(vulkan PRIVATE "$<TARGET_PROPERTY:Vulkan::Headers,INTERFACE_INCLUDE_DIRECTORIES>")
 
     if (UPDATE_DEPS)
         add_dependencies(vulkan vl_update_deps)
index d2472b634b72953abdce96db09dafc6e81f4b022..6328da03bb56bff4e91daf80e1c395109939249f 100644 (file)
@@ -76,9 +76,4 @@ target_compile_definitions(test-environment PUBLIC "GTEST_LINKED_AS_SHARED_LIBRA
 
 add_library(testing_dependencies INTERFACE)
 
-target_compile_options(testing_dependencies INTERFACE $<$<PLATFORM_ID:WIN32>:${MSVC_LOADER_COMPILE_OPTIONS},/permissive->)
-target_compile_definitions(testing_dependencies INTERFACE
-# Workaround for TR1 deprecation in Visual Studio 15.5 until Google Test is updated
-    $<$<PLATFORM_ID:WIN32>:-DWIN32_LEAN_AND_MEAN,-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING>)
-
 target_link_libraries(testing_dependencies INTERFACE Vulkan::Headers testing_framework_util test-environment)
index 44378d16c84cd082cd1d125d48639fcb1492fe37..bf6d6967fc2284ee7c5ef483704d867c008f5190 100644 (file)
@@ -19,13 +19,7 @@ set(CMAKE_CXX_STANDARD 11)
 
 add_library(test_icd_deps INTERFACE)
 
-target_compile_options(test_icd_deps INTERFACE
-    $<$<PLATFORM_ID:WIN32>:${MSVC_LOADER_COMPILE_OPTIONS},/permissive->)
-
-target_compile_definitions(test_icd_deps INTERFACE
-# Workaround for TR1 deprecation in Visual Studio 15.5 until Google Test is updated
-    $<$<PLATFORM_ID:WIN32>:-DWIN32_LEAN_AND_MEAN,-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING>
-    VK_NO_PROTOTYPES)
+target_compile_definitions(test_icd_deps INTERFACE VK_NO_PROTOTYPES)
 
 target_link_libraries(test_icd_deps INTERFACE testing_framework_util)
 
index 0ab39550d4ab85246fb43952cd10047e8c9d67ee..15cd889638e23b98aa1ea0d507bea241b2497344 100644 (file)
 
 add_library(test_layer_deps INTERFACE)
 
-target_compile_options(test_layer_deps  INTERFACE
-    $<$<PLATFORM_ID:WIN32>:${MSVC_LOADER_COMPILE_OPTIONS},/permissive->)
-
-target_compile_definitions(test_layer_deps  INTERFACE
-    # Workaround for TR1 deprecation in Visual Studio 15.5 until Google Test is updated
-    $<$<PLATFORM_ID:WIN32>:-DWIN32_LEAN_AND_MEAN,-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING>
-    VK_NO_PROTOTYPES)
+target_compile_definitions(test_layer_deps INTERFACE VK_NO_PROTOTYPES)
 
 target_link_libraries(test_layer_deps INTERFACE testing_framework_util)