global_flags.compiler.msvc.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. set(_WARNS_ENABLED
  2. 4018 # 'expression' : signed/unsigned mismatch
  3. 4265 # 'class' : class has virtual functions, but destructor is not virtual
  4. 4296 # 'operator' : expression is always false
  5. 4431 # missing type specifier - int assumed
  6. )
  7. set(_WARNS_AS_ERROR
  8. 4013 # 'function' undefined; assuming extern returning int
  9. )
  10. set(_WARNS_DISABLED
  11. # While this warning corresponds to enabled-by-default -Wmacro-redefinition,
  12. # it floods clog with abundant amount of log lines,
  13. # as yvals_core.h from Windows SDK redefines certain
  14. # which macros logically belong to libcxx
  15. 4005 # '__cpp_lib_*': macro redefinition.
  16. # Ne need to recheck this, but it looks like _CRT_USE_BUILTIN_OFFSETOF still makes sense
  17. 4117 # macro name '_CRT_USE_BUILTIN_OFFSETOF' is reserved, '#define' ignored
  18. 4127 # conditional expression is constant
  19. 4200 # nonstandard extension used : zero-sized array in struct/union
  20. 4201 # nonstandard extension used : nameless struct/union
  21. 4351 # elements of array will be default initialized
  22. 4355 # 'this' : used in base member initializer list
  23. 4503 # decorated name length exceeded, name was truncated
  24. 4510 # default constructor could not be generated
  25. 4511 # copy constructor could not be generated
  26. 4512 # assignment operator could not be generated
  27. 4554 # check operator precedence for possible error; use parentheses to clarify precedence
  28. 4610 # 'object' can never be instantiated - user defined constructor required
  29. 4706 # assignment within conditional expression
  30. 4800 # forcing value to bool 'true' or 'false' (performance warning)
  31. 4996 # The POSIX name for this item is deprecated
  32. 4714 # function marked as __forceinline not inlined
  33. 4197 # 'TAtomic' : top-level volatile in cast is ignored
  34. 4245 # 'initializing' : conversion from 'int' to 'ui32', signed/unsigned mismatch
  35. 4324 # 'ystd::function<void (uint8_t *)>': structure was padded due to alignment specifier
  36. 5033 # 'register' is no longer a supported storage class
  37. )
  38. set (_MSVC_COMMON_C_CXX_FLAGS " \
  39. /DWIN32 \
  40. /D_WIN32 \
  41. /D_WINDOWS \
  42. /D_CRT_SECURE_NO_WARNINGS \
  43. /D_CRT_NONSTDC_NO_WARNINGS \
  44. /D_USE_MATH_DEFINES \
  45. /D__STDC_CONSTANT_MACROS \
  46. /D__STDC_FORMAT_MACROS \
  47. /D_USING_V110_SDK71_ \
  48. /DWIN32_LEAN_AND_MEAN \
  49. /DNOMINMAX \
  50. /nologo \
  51. /Zm500 \
  52. /GR \
  53. /bigobj \
  54. /FC \
  55. /EHs \
  56. /errorReport:prompt \
  57. /Zc:inline \
  58. /utf-8 \
  59. /permissive- \
  60. /D_WIN32_WINNT=0x0601 \
  61. /D_MBCS \
  62. /MP \
  63. ")
  64. if (CMAKE_GENERATOR MATCHES "Visual.Studio.*")
  65. string(APPEND _MSVC_COMMON_C_CXX_FLAGS "\
  66. /DY_UCRT_INCLUDE=\"$(UniversalCRT_IncludePath.Split(';')[0].Replace('\\','/'))\" \
  67. /DY_MSVC_INCLUDE=\"$(VC_VC_IncludePath.Split(';')[0].Replace('\\','/'))\" \
  68. ")
  69. else()
  70. set(UCRT_INCLUDE_FOUND false)
  71. foreach(INCLUDE_PATH $ENV{INCLUDE})
  72. if (INCLUDE_PATH MATCHES ".*\\\\Windows Kits\\\\[0-9]+\\\\include\\\\[0-9\\.]+\\\\ucrt$")
  73. message(VERBOSE "Found Y_UCRT_INCLUDE path \"${INCLUDE_PATH}\"")
  74. string(REPLACE "\\" "/" SAFE_INCLUDE_PATH "${INCLUDE_PATH}")
  75. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_UCRT_INCLUDE=\"${SAFE_INCLUDE_PATH}\"")
  76. set(UCRT_INCLUDE_FOUND true)
  77. break()
  78. endif()
  79. endforeach()
  80. if (NOT UCRT_INCLUDE_FOUND)
  81. message(FATAL_ERROR "UniversalCRT include path not found, please add it to the standard INCLUDE environment variable (most likely by calling vcvars64.bat)")
  82. endif()
  83. set(MSVC_INCLUDE_FOUND false)
  84. foreach(INCLUDE_PATH $ENV{INCLUDE})
  85. if (INCLUDE_PATH MATCHES ".*VC\\\\Tools\\\\MSVC\\\\[0-9\\.]+\\\\include$")
  86. message(VERBOSE "Found Y_MSVC_INCLUDE path \"${INCLUDE_PATH}\"")
  87. string(REPLACE "\\" "/" SAFE_INCLUDE_PATH "${INCLUDE_PATH}")
  88. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_MSVC_INCLUDE=\"${SAFE_INCLUDE_PATH}\"")
  89. set(MSVC_INCLUDE_FOUND true)
  90. break()
  91. endif()
  92. endforeach()
  93. if (NOT MSVC_INCLUDE_FOUND)
  94. message(FATAL_ERROR "MSVC include path not found, please add it to the standard INCLUDE environment variable (most likely by calling vcvars64.bat)")
  95. endif()
  96. endif()
  97. foreach(WARN ${_WARNS_AS_ERROR})
  98. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /we${WARN}")
  99. endforeach()
  100. foreach(WARN ${_WARNS_ENABLED})
  101. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /w1${WARN}")
  102. endforeach()
  103. foreach(WARN ${_WARNS_DISABLED})
  104. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /wd${WARN}")
  105. endforeach()
  106. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
  107. string(APPEND _MSVC_COMMON_C_CXX_FLAGS " \
  108. /D_WIN64 \
  109. /DWIN64 \
  110. /D__SSE2__ \
  111. /D__SSE3__ \
  112. /D__SSSE3__ \
  113. /D__SSE4_1__ \
  114. /D__SSE4_2__ \
  115. /D__POPCNT__ \
  116. ")
  117. endif()
  118. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_MSVC_COMMON_C_CXX_FLAGS} \
  119. ")
  120. # TODO - '/D_CRT_USE_BUILTIN_OFFSETOF'
  121. # TODO - -DUSE_STL_SYSTEM
  122. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_MSVC_COMMON_C_CXX_FLAGS} \
  123. /std:c++latest \
  124. /Zc:__cplusplus \
  125. ")
  126. set(CMAKE_CXX_FLAGS_DEBUG "/Z7 /Ob0 /Od /D_DEBUG")
  127. set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG")
  128. set(CMAKE_CXX_FLAGS_RELEASE "/Ox /Ob2 /Oi /DNDEBUG")
  129. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Z7 /Ox /Ob1 /DNDEBUG")