CMakeLists.txt 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. option(DOLPHIN_CXX_FLAGS "Flags used to compile Dolphin-only sources" "")
  2. if(DOLPHIN_CXX_FLAGS)
  3. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DOLPHIN_CXX_FLAGS}")
  4. endif()
  5. if(CMAKE_SYSTEM_NAME MATCHES "Windows")
  6. add_definitions(-DNOMINMAX)
  7. add_definitions(-DUNICODE)
  8. add_definitions(-D_UNICODE)
  9. add_definitions(-DWIN32_LEAN_AND_MEAN)
  10. add_definitions(-D_SCL_SECURE_NO_WARNINGS)
  11. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  12. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  13. add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
  14. add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
  15. endif()
  16. if (NOT MSVC)
  17. set(CMAKE_CXX_STANDARD 20)
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. endif()
  21. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  22. if (MSVC)
  23. # Compile PCH
  24. add_subdirectory(PCH)
  25. else()
  26. check_and_add_flag(HAVE_WALL -Wall)
  27. # TODO: would like these but they produce overwhelming amounts of warnings
  28. #check_and_add_flag(EXTRA -Wextra)
  29. #check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers)
  30. #check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
  31. #check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
  32. #check_and_add_flag(CONVERSION -Wconversion)
  33. #check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
  34. check_and_add_flag(TYPE_LIMITS -Wtype-limits)
  35. check_and_add_flag(SIGN_COMPARE -Wsign-compare)
  36. check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
  37. check_and_add_flag(UNINITIALIZED -Wuninitialized)
  38. check_and_add_flag(LOGICAL_OP -Wlogical-op)
  39. check_and_add_flag(SHADOW -Wshadow)
  40. check_and_add_flag(SHADOW_FIELD_IN_CONSTRUCTOR -Wshadow-field-in-constructor)
  41. check_and_add_flag(SHADOW_UNCAPTURED_LOCAL -Wshadow-uncaptured-local)
  42. check_and_add_flag(INIT_SELF -Winit-self)
  43. check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations)
  44. check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations)
  45. # Disable -Wstringop-truncation warnings as they result in many false positives.
  46. # In most (all?) cases where std::strncpy is used, we want to fill the entire buffer
  47. # or match emulated code that also ignores the null terminator, so the warnings are not useful.
  48. # Given that Dolphin itself mostly uses std::string, they do not really help catch any bugs.
  49. check_cxx_compiler_flag(-Wstringop-truncation HAS_STRINGOP_TRUNCATION_WARNING)
  50. if (HAS_STRINGOP_TRUNCATION_WARNING)
  51. check_and_add_flag(NO_STRINGOP_TRUNCATION -Wno-stringop-truncation)
  52. endif()
  53. # Format string issues that the compiler can detect should be compile time errors.
  54. check_cxx_compiler_flag(-Wformat HAS_FORMAT_WARNING)
  55. if (HAS_FORMAT_WARNING)
  56. check_and_add_flag(FORMAT_WARNING_TO_ERROR -Werror=format)
  57. endif()
  58. endif()
  59. # These aren't actually needed for C11/C++11
  60. # but some dependencies require them (LLVM, libav).
  61. add_definitions(-D__STDC_LIMIT_MACROS)
  62. add_definitions(-D__STDC_CONSTANT_MACROS)
  63. add_subdirectory(Core)
  64. if (ANDROID)
  65. add_subdirectory(Android/jni)
  66. endif()
  67. if (ENABLE_TESTS)
  68. add_subdirectory(UnitTests)
  69. endif()
  70. if (DSPTOOL)
  71. add_subdirectory(DSPTool)
  72. endif()
  73. # TODO: Add DSPSpy. Preferably make it option() and cpack component