CMakeLists.txt 8.3 KB

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