Fix compiler warnings when building with GCC 7
[WebKit.git] / Source / cmake / OptionsMSVC.cmake
1 add_compile_options(
2     /wd4018 /wd4068 /wd4099 /wd4100 /wd4127 /wd4138 /wd4146 /wd4180 /wd4189
3     /wd4201 /wd4206 /wd4244 /wd4251 /wd4267 /wd4275 /wd4288 /wd4291 /wd4305
4     /wd4309 /wd4344 /wd4355 /wd4389 /wd4396 /wd4456 /wd4457 /wd4458 /wd4459
5     /wd4481 /wd4503 /wd4505 /wd4510 /wd4512 /wd4530 /wd4610 /wd4611 /wd4646
6     /wd4702 /wd4706 /wd4722 /wd4800 /wd4819 /wd4951 /wd4952 /wd4996 /wd6011
7     /wd6031 /wd6211 /wd6246 /wd6255 /wd6387
8 )
9
10 # Create pdb files for debugging purposes, also for Release builds
11 add_compile_options(/Zi /GS)
12
13 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG /OPT:ICF /OPT:REF")
14 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /OPT:ICF /OPT:REF")
15
16 # We do not use exceptions
17 add_definitions(-D_HAS_EXCEPTIONS=0)
18 add_compile_options(/EHa- /EHc- /EHs- /fp:except-)
19
20 # We have some very large object files that have to be linked
21 add_compile_options(/analyze- /bigobj)
22
23 # Use CRT security features
24 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
25 if (NOT COMPILER_IS_CLANG_CL)
26     add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1)
27 endif ()
28
29 # Turn off certain link features
30 add_compile_options(/Gy- /openmp- /GF-)
31
32 # Specify the source code encoding
33 add_compile_options(/utf-8 /validate-charset)
34
35 if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
36     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:NOREF /OPT:NOICF")
37     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:NOREF /OPT:NOICF")
38
39     # To debug linking time issues, uncomment the following three lines:
40     #add_compile_options(/Bv)
41     #set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /VERBOSE /VERBOSE:INCR /TIME")
42     #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /VERBOSE /VERBOSE:INCR /TIME")
43 elseif (${CMAKE_BUILD_TYPE} MATCHES "Release")
44     add_compile_options(/Oy-)
45 endif ()
46
47 if (NOT ${CMAKE_GENERATOR} MATCHES "Ninja")
48     link_directories("${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}")
49     add_definitions(/MP)
50 endif ()
51 if (NOT ${CMAKE_CXX_FLAGS} STREQUAL "")
52     string(REGEX REPLACE "(/EH[a-z]+) " "\\1- " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable C++ exceptions
53     string(REGEX REPLACE "/EHsc$" "/EHs- /EHc- " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable C++ exceptions
54     string(REGEX REPLACE "/GR " "/GR- " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Disable RTTI
55     string(REGEX REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # Warnings are important
56 endif ()
57
58 foreach (flag_var
59     CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
60     CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
61     CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
62     CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
63     # Use the multithreaded static runtime library instead of the default DLL runtime.
64     string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
65
66     # No debug runtime, even in debug builds.
67     if (NOT DEBUG_SUFFIX)
68         string(REGEX REPLACE "/MTd" "/MT" ${flag_var} "${${flag_var}}")
69         string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
70     endif ()
71 endforeach ()
72
73 # Make sure incremental linking is turned off, as it creates unacceptably long link times.
74 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
75 set(CMAKE_SHARED_LINKER_FLAGS "${replace_CMAKE_SHARED_LINKER_FLAGS} /INCREMENTAL:NO")
76 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS})
77 set(CMAKE_EXE_LINKER_FLAGS "${replace_CMAKE_EXE_LINKER_FLAGS} /INCREMENTAL:NO")
78
79 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_SHARED_LINKER_FLAGS_DEBUG ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
80 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${replace_CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
81 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_EXE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
82 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${replace_CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
83
84 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO})
85 set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${replace_CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
86 string(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replace_CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
87 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${replace_CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /INCREMENTAL:NO")
88
89 if (COMPILER_IS_CLANG_CL)
90     # FIXME: We need to set the msc-version above the one it defaults to
91     # when using clang-cl with VS2015. This might be unnecessary when moving to
92     # VS2017 as part of https://bugs.webkit.org/show_bug.cgi?id=172412
93     add_compile_options(-fmsc-version=190023918)
94
95     # FIXME: Building with clang-cl seemed to fail with 128 bit int support
96     set(HAVE_INT128_T OFF)
97     list(REMOVE_ITEM _WEBKIT_CONFIG_FILE_VARIABLES HAVE_INT128_T)
98 endif ()