CMakeLists.txt 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. # /Zo - Enhanced debug info for optimized builds
  21. # /permissive- - Enables stricter C++ standards conformance checks
  22. # /EHsc - C++-only exception handling semantics
  23. # /utf-8 - Set source and execution character sets to UTF-8
  24. # /volatile:iso - Use strict standards-compliant volatile semantics.
  25. # /Zc:externConstexpr - Allow extern constexpr variables to have external linkage, like the standard mandates
  26. # /Zc:inline - Let codegen omit inline functions in object files
  27. # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null
  28. add_compile_options(
  29. /MP
  30. /Zi
  31. /Zo
  32. /permissive-
  33. /EHsc
  34. /std:c++latest
  35. /utf-8
  36. /volatile:iso
  37. /Zc:externConstexpr
  38. /Zc:inline
  39. /Zc:throwingNew
  40. # External headers diagnostics
  41. /experimental:external # Enables the external headers options. This option isn't required in Visual Studio 2019 version 16.10 and later
  42. /external:anglebrackets # Treats all headers included by #include <header>, where the header file is enclosed in angle brackets (< >), as external headers
  43. /external:W0 # Sets the default warning level to 0 for external headers, effectively turning off warnings for external headers
  44. # Warnings
  45. /W3
  46. /we4018 # 'expression': signed/unsigned mismatch
  47. /we4062 # Enumerator 'identifier' in a switch of enum 'enumeration' is not handled
  48. /we4101 # 'identifier': unreferenced local variable
  49. /we4189 # 'identifier': local variable is initialized but not referenced
  50. /we4265 # 'class': class has virtual functions, but destructor is not virtual
  51. /we4267 # 'var': conversion from 'size_t' to 'type', possible loss of data
  52. /we4305 # 'context': truncation from 'type1' to 'type2'
  53. /we4388 # 'expression': signed/unsigned mismatch
  54. /we4389 # 'operator': signed/unsigned mismatch
  55. /we4547 # 'operator': operator before comma has no effect; expected operator with side-effect
  56. /we4549 # 'operator1': operator before comma has no effect; did you intend 'operator2'?
  57. /we4555 # Expression has no effect; expected expression with side-effect
  58. /we4715 # 'function': not all control paths return a value
  59. /we4834 # Discarding return value of function with 'nodiscard' attribute
  60. /we5038 # data member 'member1' will be initialized after data member 'member2'
  61. )
  62. # /GS- - No stack buffer overflow checks
  63. add_compile_options("$<$<CONFIG:Release>:/GS->")
  64. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG /MANIFEST:NO" CACHE STRING "" FORCE)
  65. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/DEBUG /MANIFEST:NO /INCREMENTAL:NO /OPT:REF,ICF" CACHE STRING "" FORCE)
  66. else()
  67. add_compile_options(
  68. -Wall
  69. -Werror=array-bounds
  70. -Werror=implicit-fallthrough
  71. -Werror=missing-declarations
  72. -Werror=missing-field-initializers
  73. -Werror=reorder
  74. -Werror=sign-compare
  75. -Werror=switch
  76. -Werror=uninitialized
  77. -Werror=unused-function
  78. -Werror=unused-result
  79. -Werror=unused-variable
  80. -Wextra
  81. -Wmissing-declarations
  82. -Wno-attributes
  83. -Wno-invalid-offsetof
  84. -Wno-unused-parameter
  85. )
  86. # TODO: Remove when we update to a GCC compiler that enables this
  87. # by default (i.e. GCC 10 or newer).
  88. if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
  89. add_compile_options(-fconcepts)
  90. endif()
  91. if (ARCHITECTURE_x86_64)
  92. add_compile_options("-mcx16")
  93. endif()
  94. if (APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  95. add_compile_options("-stdlib=libc++")
  96. endif()
  97. # Set file offset size to 64 bits.
  98. #
  99. # On modern Unixes, this is typically already the case. The lone exception is
  100. # glibc, which may default to 32 bits. glibc allows this to be configured
  101. # by setting _FILE_OFFSET_BITS.
  102. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  103. add_definitions(-D_FILE_OFFSET_BITS=64)
  104. endif()
  105. if (MINGW)
  106. add_definitions(-DMINGW_HAS_SECURE_API)
  107. if (MINGW_STATIC_BUILD)
  108. add_definitions(-DQT_STATICPLUGIN)
  109. add_compile_options("-static")
  110. endif()
  111. endif()
  112. if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR MINGW)
  113. # GNU ar: Create thin archive files.
  114. # Requires binutils-2.19 or later.
  115. set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  116. set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  117. set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  118. set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qTP <TARGET> <LINK_FLAGS> <OBJECTS>")
  119. endif()
  120. endif()
  121. add_subdirectory(common)
  122. add_subdirectory(core)
  123. add_subdirectory(audio_core)
  124. add_subdirectory(video_core)
  125. add_subdirectory(input_common)
  126. add_subdirectory(shader_recompiler)
  127. add_subdirectory(tests)
  128. if (ENABLE_SDL2)
  129. add_subdirectory(yuzu_cmd)
  130. endif()
  131. if (ENABLE_QT)
  132. add_subdirectory(yuzu)
  133. endif()
  134. if (ENABLE_WEB_SERVICE)
  135. add_subdirectory(web_service)
  136. endif()