CMakeLists.txt 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 are built with Unicode support.
  18. add_definitions(-DUNICODE -D_UNICODE)
  19. # /W4 - Level 4 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:preprocessor - Enable standards-conforming preprocessor
  31. # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null
  32. # /GT - Supports fiber safety for data allocated using static thread-local storage
  33. add_compile_options(
  34. /MP
  35. /Zm200
  36. /Zo
  37. /permissive-
  38. /EHsc
  39. /std:c++20
  40. /utf-8
  41. /volatile:iso
  42. /Zc:externConstexpr
  43. /Zc:inline
  44. /Zc:preprocessor
  45. /Zc:throwingNew
  46. /GT
  47. # Modules
  48. /experimental:module- # Explicitly disable module support due to conflicts with precompiled headers.
  49. # External headers diagnostics
  50. /external:anglebrackets # Treats all headers included by #include <header>, where the header file is enclosed in angle brackets (< >), as external headers
  51. /external:W0 # Sets the default warning level to 0 for external headers, effectively disabling warnings for them.
  52. # Warnings
  53. /W4
  54. /WX
  55. /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled
  56. /we4189 # 'identifier': local variable is initialized but not referenced
  57. /we4265 # 'class': class has virtual functions, but destructor is not virtual
  58. /we4388 # 'expression': signed/unsigned mismatch
  59. /we4389 # 'operator': signed/unsigned mismatch
  60. /we4456 # Declaration of 'identifier' hides previous local declaration
  61. /we4457 # Declaration of 'identifier' hides function parameter
  62. /we4458 # Declaration of 'identifier' hides class member
  63. /we4459 # Declaration of 'identifier' hides global declaration
  64. /we4505 # 'function': unreferenced local function has been removed
  65. /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
  66. /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'?
  67. /we4555 # Expression has no effect; expected expression with side-effect
  68. /we4826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior.
  69. /we5038 # data member 'member1' will be initialized after data member 'member2'
  70. /we5233 # explicit lambda capture 'identifier' is not used
  71. /we5245 # 'function': unreferenced function with internal linkage has been removed
  72. /wd4100 # 'identifier': unreferenced formal parameter
  73. /wd4324 # 'struct_name': structure was padded due to __declspec(align())
  74. /wd4201 # nonstandard extension used : nameless struct/union
  75. /wd4702 # unreachable code (when used with LTO)
  76. )
  77. if (USE_CCACHE OR YUZU_USE_PRECOMPILED_HEADERS)
  78. # when caching, we need to use /Z7 to downgrade debug info to use an older but more cacheable format
  79. # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21
  80. add_compile_options(/Z7)
  81. # Avoid D9025 warning
  82. string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
  83. string(REPLACE "/Zi" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
  84. else()
  85. add_compile_options(/Zi)
  86. endif()
  87. if (ARCHITECTURE_x86_64)
  88. add_compile_options(/QIntel-jcc-erratum)
  89. endif()
  90. # /GS- - No stack buffer overflow checks
  91. add_compile_options("$<$<CONFIG:Release>:/GS->")
  92. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
  93. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
  94. else()
  95. add_compile_options(
  96. -fwrapv
  97. -Werror=all
  98. -Werror=extra
  99. -Werror=missing-declarations
  100. -Werror=shadow
  101. -Werror=unused
  102. -Wno-attributes
  103. -Wno-invalid-offsetof
  104. -Wno-unused-parameter
  105. )
  106. if (CMAKE_CXX_COMPILER_ID MATCHES Clang) # Clang or AppleClang
  107. add_compile_options(
  108. -Wno-braced-scalar-init
  109. -Wno-unused-private-field
  110. -Wno-nullability-completeness
  111. -Werror=shadow-uncaptured-local
  112. -Werror=implicit-fallthrough
  113. -Werror=type-limits
  114. )
  115. endif()
  116. if (ARCHITECTURE_x86_64)
  117. add_compile_options("-mcx16")
  118. endif()
  119. if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  120. add_compile_options("-stdlib=libc++")
  121. endif()
  122. # GCC bugs
  123. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  124. # These diagnostics would be great if they worked, but are just completely broken
  125. # and produce bogus errors on external libraries like fmt.
  126. add_compile_options(
  127. -Wno-array-bounds
  128. -Wno-stringop-overread
  129. -Wno-stringop-overflow
  130. )
  131. endif()
  132. # Set file offset size to 64 bits.
  133. #
  134. # On modern Unixes, this is typically already the case. The lone exception is
  135. # glibc, which may default to 32 bits. glibc allows this to be configured
  136. # by setting _FILE_OFFSET_BITS.
  137. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  138. add_definitions(-D_FILE_OFFSET_BITS=64)
  139. endif()
  140. if (MINGW)
  141. add_definitions(-DMINGW_HAS_SECURE_API)
  142. if (MINGW_STATIC_BUILD)
  143. add_definitions(-DQT_STATICPLUGIN)
  144. add_compile_options("-static")
  145. endif()
  146. endif()
  147. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  148. # GNU ar: Create thin archive files.
  149. # Requires binutils-2.19 or later.
  150. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  151. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  152. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  153. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  154. endif()
  155. endif()
  156. add_subdirectory(common)
  157. add_subdirectory(core)
  158. add_subdirectory(audio_core)
  159. add_subdirectory(video_core)
  160. add_subdirectory(hid_core)
  161. add_subdirectory(network)
  162. add_subdirectory(input_common)
  163. add_subdirectory(frontend_common)
  164. add_subdirectory(shader_recompiler)
  165. if (YUZU_ROOM)
  166. add_subdirectory(dedicated_room)
  167. endif()
  168. if (YUZU_TESTS)
  169. add_subdirectory(tests)
  170. endif()
  171. if (ENABLE_SDL2)
  172. add_subdirectory(yuzu_cmd)
  173. endif()
  174. if (ENABLE_QT)
  175. add_subdirectory(yuzu)
  176. endif()
  177. if (ENABLE_WEB_SERVICE)
  178. add_subdirectory(web_service)
  179. endif()
  180. if (ANDROID)
  181. add_subdirectory(android/app/src/main/jni)
  182. target_include_directories(yuzu-android PRIVATE android/app/src/main)
  183. endif()