options_win.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # This file is part of Desktop App Toolkit,
  2. # a set of libraries for developing nice desktop applications.
  3. #
  4. # For license and copyright information please follow this link:
  5. # https://github.com/desktop-app/legal/blob/master/LEGAL
  6. target_compile_definitions(common_options
  7. INTERFACE
  8. WIN32
  9. WIN32_LEAN_AND_MEAN
  10. _WINDOWS
  11. _SCL_SECURE_NO_WARNINGS
  12. NOMINMAX
  13. NOSERVICE
  14. NOMCX
  15. NOIME
  16. NOSOUND
  17. NOCOMM
  18. NOKANJI
  19. NORPC
  20. NOPROXYSTUB
  21. NOIMAGE
  22. NOTAPE
  23. UNICODE
  24. _UNICODE
  25. )
  26. if (MSVC)
  27. target_compile_options(common_options
  28. INTERFACE
  29. /permissive-
  30. # /Qspectre
  31. /utf-8
  32. /W4
  33. /MP # Enable multi process build.
  34. /EHsc # Catch C++ exceptions only, extern C functions never throw a C++ exception.
  35. /w15038 # wrong initialization order
  36. /w14265 # class has virtual functions, but destructor is not virtual
  37. /wd4018 # 'token' : signed/unsigned mismatch
  38. /wd4100 # 'identifier' : unreferenced formal parameter
  39. /wd4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
  40. /wd4244 # 'argument' : conversion from 'type1' to 'type2', possible loss of data
  41. /wd4245 # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
  42. /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data
  43. /wd4305 # 'conversion': truncation from 'type1' to 'type2'
  44. /wd4324 # 'structname': structure was padded due to alignment specifier
  45. /wd4389 # 'equality-operator' : signed/unsigned mismatch
  46. /wd4456 # declaration of 'identifier' hides previous local declaration
  47. /wd4457 # declaration of 'identifier' hides function parameter
  48. /wd4458 # declaration of 'identifier' hides class member
  49. /wd4459 # declaration of 'identifier' hides global declaration
  50. /wd4611 # interaction between 'function' and C++ object destruction is non-portable
  51. /wd4702 # unreachable code
  52. /Zi
  53. # Taken from Qt 6.
  54. # https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
  55. # No support for the flag in upstream CMake as of 3.17.
  56. # https://gitlab.kitware.com/cmake/cmake/issues/18837
  57. /Zc:__cplusplus
  58. )
  59. target_link_options(common_options
  60. INTERFACE
  61. $<IF:$<CONFIG:Debug>,/NODEFAULTLIB:LIBCMT,/DEBUG;/OPT:REF>
  62. $<$<BOOL:${DESKTOP_APP_NO_PDB}>:/DEBUG:NONE>
  63. /INCREMENTAL:NO
  64. )
  65. if (DESKTOP_APP_ASAN)
  66. target_compile_options(common_options INTERFACE /fsanitize=address)
  67. # https://developercommunity.visualstudio.com/t/Linker-error-LNK2038-when-using-Parallel/10512721
  68. target_compile_definitions(common_options
  69. INTERFACE
  70. _DISABLE_VECTOR_ANNOTATION
  71. _DISABLE_STRING_ANNOTATION
  72. )
  73. endif()
  74. target_compile_options(common_options
  75. INTERFACE
  76. /bigobj # scheme.cpp has too many sections.
  77. )
  78. if (NOT build_win64 AND NOT build_winarm)
  79. # target_compile_options(common_options
  80. # INTERFACE
  81. # /fp:except # Crash-report fp exceptions in 32 bit build.
  82. # )
  83. target_link_options(common_options
  84. INTERFACE
  85. /LARGEADDRESSAWARE # Allow more than 2 GB in 32 bit application.
  86. )
  87. endif()
  88. if (DESKTOP_APP_SPECIAL_TARGET)
  89. target_compile_options(common_options
  90. INTERFACE
  91. /WX
  92. $<IF:$<CONFIG:Debug>,,/GL>
  93. )
  94. target_link_options(common_options
  95. INTERFACE
  96. $<IF:$<CONFIG:Debug>,,/LTCG>
  97. $<IF:$<CONFIG:Debug>,,/LTCGOUT:>
  98. )
  99. endif()
  100. else()
  101. target_compile_definitions(common_options
  102. INTERFACE
  103. WINVER=0x0601
  104. _WIN32_WINNT=0x0601
  105. )
  106. target_compile_options(common_options
  107. INTERFACE
  108. -fpermissive
  109. )
  110. if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  111. target_compile_options(common_options
  112. INTERFACE
  113. -fms-extensions
  114. -femulated-tls
  115. )
  116. target_link_options(common_options
  117. INTERFACE
  118. -fuse-ld=lld
  119. )
  120. endif()
  121. endif()
  122. target_link_libraries(common_options
  123. INTERFACE
  124. winmm
  125. imm32
  126. ws2_32
  127. kernel32
  128. user32
  129. gdi32
  130. winspool
  131. comdlg32
  132. advapi32
  133. shell32
  134. ole32
  135. oleaut32
  136. uuid
  137. odbc32
  138. odbccp32
  139. Shlwapi
  140. Iphlpapi
  141. Gdiplus
  142. Strmiids
  143. Netapi32
  144. Userenv
  145. Version
  146. Dwmapi
  147. UxTheme
  148. Wtsapi32
  149. Crypt32
  150. Propsys
  151. Bcrypt
  152. )
  153. if (build_winstore)
  154. target_compile_definitions(common_options INTERFACE OS_WIN_STORE)
  155. endif()