CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # Enable modules to include each other's files
  2. include_directories(.)
  3. # CMake seems to only define _DEBUG on Windows
  4. set_property(DIRECTORY APPEND PROPERTY
  5. COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG> $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
  6. # Set compilation flags
  7. if (MSVC)
  8. set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)
  9. # Silence "deprecation" warnings
  10. add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
  11. # Avoid windows.h junk
  12. add_definitions(-DNOMINMAX)
  13. # Avoid windows.h from including some usually unused libs like winsocks.h, since this might cause some redefinition errors.
  14. add_definitions(-DWIN32_LEAN_AND_MEAN)
  15. # Ensure that projects build with Unicode support.
  16. add_definitions(-DUNICODE -D_UNICODE)
  17. # /W3 - Level 3 warnings
  18. # /MP - Multi-threaded compilation
  19. # /Zi - Output debugging information
  20. # /Zm - Specifies the precompiled header memory allocation limit
  21. # /Zo - Enhanced debug info for optimized builds
  22. # /permissive- - Enables stricter C++ standards conformance checks
  23. # /EHsc - C++-only exception handling semantics
  24. # /utf-8 - Set source and execution character sets to UTF-8
  25. # /volatile:iso - Use strict standards-compliant volatile semantics.
  26. # /Zc:externConstexpr - Allow extern constexpr variables to have external linkage, like the standard mandates
  27. # /Zc:inline - Let codegen omit inline functions in object files
  28. # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null
  29. # /GT - Supports fiber safety for data allocated using static thread-local storage
  30. add_compile_options(
  31. /MP
  32. /Zm200
  33. /Zo
  34. /permissive-
  35. /EHsc
  36. /std:c++latest
  37. /utf-8
  38. /volatile:iso
  39. /Zc:externConstexpr
  40. /Zc:inline
  41. /Zc:throwingNew
  42. /GT
  43. # External headers diagnostics
  44. /experimental:external # Enables the external headers options. This option isn't required in Visual Studio 2019 version 16.10 and later
  45. /external:anglebrackets # Treats all headers included by #include <header>, where the header file is enclosed in angle brackets (< >), as external headers
  46. /external:W0 # Sets the default warning level to 0 for external headers, effectively turning off warnings for external headers
  47. # Warnings
  48. /W3
  49. /we4018 # 'expression': signed/unsigned mismatch
  50. /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled
  51. /we4101 # 'identifier': unreferenced local variable
  52. /we4189 # 'identifier': local variable is initialized but not referenced
  53. /we4265 # 'class': class has virtual functions, but destructor is not virtual
  54. /we4267 # 'var': conversion from 'size_t' to 'type', possible loss of data
  55. /we4305 # 'context': truncation from 'type1' to 'type2'
  56. /we4388 # 'expression': signed/unsigned mismatch
  57. /we4389 # 'operator': signed/unsigned mismatch
  58. /we4456 # Declaration of 'identifier' hides previous local declaration
  59. /we4457 # Declaration of 'identifier' hides function parameter
  60. /we4458 # Declaration of 'identifier' hides class member
  61. /we4459 # Declaration of 'identifier' hides global declaration
  62. /we4505 # 'function': unreferenced local function has been removed
  63. /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
  64. /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'?
  65. /we4555 # Expression has no effect; expected expression with side-effect
  66. /we4715 # 'function': not all control paths return a value
  67. /we4834 # Discarding return value of function with 'nodiscard' attribute
  68. /we5038 # data member 'member1' will be initialized after data member 'member2'
  69. /we5245 # 'function': unreferenced function with internal linkage has been removed
  70. )
  71. if (USE_CCACHE)
  72. # when caching, we need to use /Z7 to downgrade debug info to use an older but more cachable format
  73. add_compile_options(/Z7)
  74. else()
  75. add_compile_options(/Zi)
  76. endif()
  77. if (ARCHITECTURE_x86_64)
  78. add_compile_options(/QIntel-jcc-erratum)
  79. endif()
  80. # /GS- - No stack buffer overflow checks
  81. add_compile_options("$<$<CONFIG:Release>:/GS->")
  82. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
  83. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
  84. else()
  85. add_compile_options(
  86. -Wall
  87. -Werror=array-bounds
  88. -Werror=implicit-fallthrough
  89. -Werror=missing-declarations
  90. -Werror=missing-field-initializers
  91. -Werror=reorder
  92. -Werror=shadow
  93. -Werror=sign-compare
  94. -Werror=switch
  95. -Werror=uninitialized
  96. -Werror=unused-function
  97. -Werror=unused-result
  98. -Werror=unused-variable
  99. -Wextra
  100. -Wmissing-declarations
  101. -Wno-attributes
  102. -Wno-invalid-offsetof
  103. -Wno-unused-parameter
  104. )
  105. if (ARCHITECTURE_x86_64)
  106. add_compile_options("-mcx16")
  107. endif()
  108. if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  109. add_compile_options("-stdlib=libc++")
  110. endif()
  111. # Set file offset size to 64 bits.
  112. #
  113. # On modern Unixes, this is typically already the case. The lone exception is
  114. # glibc, which may default to 32 bits. glibc allows this to be configured
  115. # by setting _FILE_OFFSET_BITS.
  116. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  117. add_definitions(-D_FILE_OFFSET_BITS=64)
  118. endif()
  119. if (MINGW)
  120. add_definitions(-DMINGW_HAS_SECURE_API)
  121. if (MINGW_STATIC_BUILD)
  122. add_definitions(-DQT_STATICPLUGIN)
  123. add_compile_options("-static")
  124. endif()
  125. endif()
  126. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  127. # GNU ar: Create thin archive files.
  128. # Requires binutils-2.19 or later.
  129. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  130. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  131. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  132. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  133. endif()
  134. endif()
  135. add_subdirectory(common)
  136. add_subdirectory(core)
  137. add_subdirectory(audio_core)
  138. add_subdirectory(video_core)
  139. add_subdirectory(network)
  140. add_subdirectory(input_common)
  141. add_subdirectory(shader_recompiler)
  142. if (YUZU_TESTS)
  143. add_subdirectory(tests)
  144. endif()
  145. if (ENABLE_SDL2)
  146. add_subdirectory(yuzu_cmd)
  147. endif()
  148. if (ENABLE_QT)
  149. add_subdirectory(yuzu)
  150. endif()
  151. if (ENABLE_WEB_SERVICE)
  152. add_subdirectory(web_service)
  153. endif()