CMakeLists.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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++latest
  39. /utf-8
  40. /volatile:iso
  41. /Zc:externConstexpr
  42. /Zc:inline
  43. /Zc:throwingNew
  44. /GT
  45. # External headers diagnostics
  46. /experimental:external # Enables the external headers options. This option isn't required in Visual Studio 2019 version 16.10 and later
  47. /external:anglebrackets # Treats all headers included by #include <header>, where the header file is enclosed in angle brackets (< >), as external headers
  48. /external:W0 # Sets the default warning level to 0 for external headers, effectively turning off warnings for external headers
  49. # Warnings
  50. /W3
  51. /WX
  52. /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled
  53. /we4189 # 'identifier': local variable is initialized but not referenced
  54. /we4265 # 'class': class has virtual functions, but destructor is not virtual
  55. /we4388 # 'expression': signed/unsigned mismatch
  56. /we4389 # 'operator': signed/unsigned mismatch
  57. /we4456 # Declaration of 'identifier' hides previous local declaration
  58. /we4457 # Declaration of 'identifier' hides function parameter
  59. /we4458 # Declaration of 'identifier' hides class member
  60. /we4459 # Declaration of 'identifier' hides global declaration
  61. /we4505 # 'function': unreferenced local function has been removed
  62. /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
  63. /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'?
  64. /we4555 # Expression has no effect; expected expression with side-effect
  65. /we4826 # Conversion from 'type1' to 'type2' is sign-extended. This may cause unexpected runtime behavior.
  66. /we5038 # data member 'member1' will be initialized after data member 'member2'
  67. /we5233 # explicit lambda capture 'identifier' is not used
  68. /we5245 # 'function': unreferenced function with internal linkage has been removed
  69. /wd4100 # 'identifier': unreferenced formal parameter
  70. /wd4324 # 'struct_name': structure was padded due to __declspec(align())
  71. )
  72. if (USE_CCACHE OR YUZU_USE_PRECOMPILED_HEADERS)
  73. # when caching, we need to use /Z7 to downgrade debug info to use an older but more cachable format
  74. # Precompiled headers are deleted if not using /Z7. See https://github.com/nanoant/CMakePCHCompiler/issues/21
  75. add_compile_options(/Z7)
  76. else()
  77. add_compile_options(/Zi)
  78. endif()
  79. if (ARCHITECTURE_x86_64)
  80. add_compile_options(/QIntel-jcc-erratum)
  81. endif()
  82. # /GS- - No stack buffer overflow checks
  83. add_compile_options("$<$<CONFIG:Release>:/GS->")
  84. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
  85. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
  86. else()
  87. add_compile_options(
  88. -Werror=all
  89. -Werror=extra
  90. -Werror=missing-declarations
  91. -Werror=shadow
  92. -Werror=unused
  93. -Wno-attributes
  94. -Wno-invalid-offsetof
  95. -Wno-unused-parameter
  96. $<$<CXX_COMPILER_ID:Clang>:-Wno-braced-scalar-init>
  97. $<$<CXX_COMPILER_ID:Clang>:-Wno-unused-private-field>
  98. $<$<CXX_COMPILER_ID:AppleClang>:-Wno-braced-scalar-init>
  99. $<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-private-field>
  100. )
  101. if (ARCHITECTURE_x86_64)
  102. add_compile_options("-mcx16")
  103. add_compile_options("-fwrapv")
  104. endif()
  105. if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  106. add_compile_options("-stdlib=libc++")
  107. endif()
  108. # Set file offset size to 64 bits.
  109. #
  110. # On modern Unixes, this is typically already the case. The lone exception is
  111. # glibc, which may default to 32 bits. glibc allows this to be configured
  112. # by setting _FILE_OFFSET_BITS.
  113. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  114. add_definitions(-D_FILE_OFFSET_BITS=64)
  115. endif()
  116. if (MINGW)
  117. add_definitions(-DMINGW_HAS_SECURE_API)
  118. if (MINGW_STATIC_BUILD)
  119. add_definitions(-DQT_STATICPLUGIN)
  120. add_compile_options("-static")
  121. endif()
  122. endif()
  123. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  124. # GNU ar: Create thin archive files.
  125. # Requires binutils-2.19 or later.
  126. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  127. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  128. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  129. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  130. endif()
  131. endif()
  132. add_subdirectory(common)
  133. add_subdirectory(core)
  134. add_subdirectory(audio_core)
  135. add_subdirectory(video_core)
  136. add_subdirectory(network)
  137. add_subdirectory(input_common)
  138. add_subdirectory(shader_recompiler)
  139. add_subdirectory(dedicated_room)
  140. if (YUZU_TESTS)
  141. add_subdirectory(tests)
  142. endif()
  143. if (ENABLE_SDL2)
  144. add_subdirectory(yuzu_cmd)
  145. endif()
  146. if (ENABLE_QT)
  147. add_subdirectory(yuzu)
  148. endif()
  149. if (ENABLE_WEB_SERVICE)
  150. add_subdirectory(web_service)
  151. endif()