CMakeLists.txt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
  64. if(HAVE_ELF_AUX_INFO)
  65. add_definitions(-DHAVE_ELF_AUX_INFO)
  66. endif()
  67. add_subdirectory(Core)
  68. if (ANDROID)
  69. add_subdirectory(Android/jni)
  70. endif()
  71. if (ENABLE_TESTS)
  72. add_subdirectory(UnitTests)
  73. endif()
  74. if (DSPTOOL)
  75. add_subdirectory(DSPTool)
  76. endif()
  77. # TODO: Add DSPSpy. Preferably make it option() and cpack component