CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # SPDX-FileCopyrightText: 2018 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Enable modules to include each other's files
  4. include_directories(.)
  5. # CMake seems to only define _DEBUG on Windows
  6. set_property(DIRECTORY APPEND PROPERTY
  7. COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG> $<$<NOT:$<CONFIG:Debug>>:NDEBUG>)
  8. # Set compilation flags
  9. if (MSVC)
  10. set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)
  11. # Silence "deprecation" warnings
  12. add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
  13. # Avoid windows.h junk
  14. add_definitions(-DNOMINMAX)
  15. # Avoid windows.h from including some usually unused libs like winsocks.h, since this might cause some redefinition errors.
  16. add_definitions(-DWIN32_LEAN_AND_MEAN)
  17. # Ensure that projects build with Unicode support.
  18. add_definitions(-DUNICODE -D_UNICODE)
  19. # /W3 - Level 3 warnings
  20. # /MP - Multi-threaded compilation
  21. # /Zi - Output debugging information
  22. # /Zm - Specifies the precompiled header memory allocation limit
  23. # /Zo - Enhanced debug info for optimized builds
  24. # /permissive- - Enables stricter C++ standards conformance checks
  25. # /EHsc - C++-only exception handling semantics
  26. # /utf-8 - Set source and execution character sets to UTF-8
  27. # /volatile:iso - Use strict standards-compliant volatile semantics.
  28. # /Zc:externConstexpr - Allow extern constexpr variables to have external linkage, like the standard mandates
  29. # /Zc:inline - Let codegen omit inline functions in object files
  30. # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null
  31. # /GT - Supports fiber safety for data allocated using static thread-local storage
  32. add_compile_options(
  33. /MP
  34. /Zm200
  35. /Zo
  36. /permissive-
  37. /EHsc
  38. /std:c++20
  39. /utf-8
  40. /volatile:iso
  41. /Zc:externConstexpr
  42. /Zc:inline
  43. /Zc:throwingNew
  44. /GT
  45. # Modules
  46. /experimental:module- # Disable module support explicitly due to conflicts with precompiled headers
  47. # External headers diagnostics
  48. /external:anglebrackets # Treats all headers included by #include <header>, where the header file is enclosed in angle brackets (< >), as external headers
  49. /external:W0 # Sets the default warning level to 0 for external headers, effectively turning off warnings for external headers
  50. # Warnings
  51. /W3
  52. /WX
  53. /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled
  54. /we4189 # 'identifier': local variable is initialized but not referenced
  55. /we4265 # 'class': class has virtual functions, but destructor is not virtual
  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. /we4826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior.
  67. /we5038 # data member 'member1' will be initialized after data member 'member2'
  68. /we5233 # explicit lambda capture 'identifier' is not used
  69. /we5245 # 'function': unreferenced function with internal linkage has been removed
  70. /wd4100 # 'identifier': unreferenced formal parameter
  71. /wd4324 # 'struct_name': structure was padded due to __declspec(align())
  72. )
  73. if (USE_CCACHE OR YUZU_USE_PRECOMPILED_HEADERS)
  74. # when caching, we need to use /Z7 to downgrade debug info to use an older but more cacheable format
  75. # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21
  76. add_compile_options(/Z7)
  77. else()
  78. add_compile_options(/Zi)
  79. endif()
  80. if (ARCHITECTURE_x86_64)
  81. add_compile_options(/QIntel-jcc-erratum)
  82. endif()
  83. # /GS- - No stack buffer overflow checks
  84. add_compile_options("$<$<CONFIG:Release>:/GS->")
  85. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
  86. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
  87. else()
  88. add_compile_options(
  89. -Werror=all
  90. -Werror=extra
  91. -Werror=missing-declarations
  92. -Werror=shadow
  93. -Werror=unused
  94. -Wno-attributes
  95. -Wno-invalid-offsetof
  96. -Wno-unused-parameter
  97. $<$<CXX_COMPILER_ID:Clang>:-Wno-braced-scalar-init>
  98. $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-private-field>
  99. $<$<CXX_COMPILER_ID:Clang>:-Werror=shadow-uncaptured-local>
  100. $<$<CXX_COMPILER_ID:Clang>:-Werror=implicit-fallthrough>
  101. $<$<CXX_COMPILER_ID:Clang>:-Werror=type-limits>
  102. $<$<CXX_COMPILER_ID:AppleClang>:-Wno-braced-scalar-init>
  103. $<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-private-field>
  104. )
  105. if (ARCHITECTURE_x86_64)
  106. add_compile_options("-mcx16")
  107. add_compile_options("-fwrapv")
  108. endif()
  109. if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  110. add_compile_options("-stdlib=libc++")
  111. endif()
  112. # GCC bugs
  113. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  114. # These diagnostics would be great if they worked, but are just completely broken
  115. # and produce bogus errors on external libraries like fmt.
  116. add_compile_options(
  117. -Wno-array-bounds
  118. -Wno-stringop-overread
  119. -Wno-stringop-overflow
  120. )
  121. endif()
  122. # Set file offset size to 64 bits.
  123. #
  124. # On modern Unixes, this is typically already the case. The lone exception is
  125. # glibc, which may default to 32 bits. glibc allows this to be configured
  126. # by setting _FILE_OFFSET_BITS.
  127. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  128. add_definitions(-D_FILE_OFFSET_BITS=64)
  129. endif()
  130. if (MINGW)
  131. add_definitions(-DMINGW_HAS_SECURE_API)
  132. if (MINGW_STATIC_BUILD)
  133. add_definitions(-DQT_STATICPLUGIN)
  134. add_compile_options("-static")
  135. endif()
  136. endif()
  137. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  138. # GNU ar: Create thin archive files.
  139. # Requires binutils-2.19 or later.
  140. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  141. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  142. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  143. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  144. endif()
  145. endif()
  146. add_subdirectory(common)
  147. add_subdirectory(core)
  148. add_subdirectory(audio_core)
  149. add_subdirectory(video_core)
  150. add_subdirectory(network)
  151. add_subdirectory(input_common)
  152. add_subdirectory(shader_recompiler)
  153. if (YUZU_ROOM)
  154. add_subdirectory(dedicated_room)
  155. endif()
  156. if (YUZU_TESTS)
  157. add_subdirectory(tests)
  158. endif()
  159. if (ENABLE_SDL2)
  160. add_subdirectory(yuzu_cmd)
  161. endif()
  162. if (ENABLE_QT)
  163. add_subdirectory(yuzu)
  164. endif()
  165. if (ENABLE_WEB_SERVICE)
  166. add_subdirectory(web_service)
  167. endif()
  168. if (ANDROID)
  169. add_subdirectory(android/app/src/main/jni)
  170. target_include_directories(yuzu-android PRIVATE android/app/src/main)
  171. endif()