[MSVC]
[reactos.git] / reactos / cmake / msvc.cmake
index 53e4f07..75cfe9a 100644 (file)
@@ -2,6 +2,11 @@
 #if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
     # no optimization
+    add_compile_flags("/Ob0 /Od")
+elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
+    add_compile_flags("/Ox /Ob2 /Ot /Oy /GT /GF")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF")
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF")
 elseif(OPTIMIZE STREQUAL "1")
     add_definitions(/O1)
 elseif(OPTIMIZE STREQUAL "2")
@@ -33,13 +38,22 @@ if(MSVC_VERSION GREATER 1799 AND NOT MSVC_IDE)
     add_compile_flags("/FS")
 endif ()
 
+# VS14+ tries to use thread-safe initialization
+if(MSVC_VERSION GREATER 1899)
+    add_compile_flags("/Zc:threadSafeInit-")
+endif ()
+
 # Disable overly sensitive warnings as well as those that generally aren't
 # useful to us.
 # - C4244: implicit integer truncation
 # - C4290: C++ exception specification ignored
 # - C4800: forcing value to bool 'true' or 'false' (performance warning)
-#add_compile_flags("/wd4244 /wd4290 /wd4800 ")
-add_compile_flags("/wd4244 /wd4290 /wd4800")
+# - C4200: nonstandard extension used : zero-sized array in struct/union
+# - C4214: nonstandard extension used : bit field types other than int
+add_compile_flags("/wd4244 /wd4290 /wd4800 /wd4200 /wd4214")
+
+# FIXME: Temporarily disable C4018 until we fix more of the others. CORE-10113
+add_compile_flags("/wd4018")
 
 # The following warnings are treated as errors:
 # - C4013: implicit function declaration
@@ -60,6 +74,12 @@ add_compile_flags("/wd4244 /wd4290 /wd4800")
 # - C4716: function must return a value
 add_compile_flags("/we4013 /we4020 /we4022 /we4047 /we4098 /we4113 /we4129 /we4163 /we4229 /we4700 /we4603 /we4716")
 
+# - C4189: local variable initialized but not referenced
+# Not in Release mode and not with MSVC 2010
+if((NOT CMAKE_BUILD_TYPE STREQUAL "Release") AND (NOT MSVC_VERSION LESS 1700))
+    add_compile_flags("/we4189")
+endif()
+
 # Enable warnings above the default level, but don't treat them as errors:
 # - C4115: named type definition in parentheses
 add_compile_flags("/w14115")
@@ -70,17 +90,13 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
     if(NOT (_PREFAST_ OR _VS_ANALYZE_))
         add_compile_flags("/Zi")
     endif()
-    add_compile_flags("/Ob0 /Od")
 #elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
 elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
-    add_compile_flags("/Ob2 /D NDEBUG")
+    add_definitions("/D NDEBUG")
 endif()
 
-if(MSVC_IDE)
-    add_compile_flags("/MP")
-    if(NOT DEFINED USE_FOLDER_STRUCTURE)
-        set(USE_FOLDER_STRUCTURE FALSE)
-    endif()
+if(MSVC_IDE AND (NOT DEFINED USE_FOLDER_STRUCTURE))
+    set(USE_FOLDER_STRUCTURE FALSE)
 endif()
 
 if(NOT DEFINED RUNTIME_CHECKS)
@@ -93,7 +109,7 @@ if(RUNTIME_CHECKS)
 endif()
 
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
-set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE /IGNORE:4104")
 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
 
 if(CMAKE_DISABLE_NINJA_DEPSLOG)
@@ -207,10 +223,13 @@ function(set_entrypoint _module _entrypoint)
 endfunction()
 
 function(set_subsystem MODULE SUBSYSTEM)
+    string(TOUPPER ${SUBSYSTEM} _subsystem)
     if(ARCH STREQUAL "amd64")
-        add_target_link_flags(${MODULE} "/SUBSYSTEM:${SUBSYSTEM},5.02")
+        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.02")
+    elseif(ARCH STREQUAL "arm")
+        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},6.02")
     else()
-        add_target_link_flags(${MODULE} "/SUBSYSTEM:${SUBSYSTEM},5.01")
+        add_target_link_flags(${MODULE} "/SUBSYSTEM:${_subsystem},5.01")
     endif()
 endfunction()
 
@@ -335,10 +354,10 @@ function(spec2def _dllname _spec_file)
         DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
 
     if(__spec2def_ADD_IMPORTLIB)
-        # TODO: NO_PRIVATE_WARNINGS should add /IGNORE:4104 to the link command
-        #       line. However that should be on all command lines outside of
-        #       generate_import_lib in the first place.
         generate_import_lib(lib${_file} ${_dllname} ${_spec_file})
+        if(__spec2def_NO_PRIVATE_WARNINGS)
+            add_target_property(lib${_file} STATIC_LIBRARY_FLAGS "/ignore:4104")
+        endif()
     endif()
 endfunction()