CMakeLists.txt 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(INIT_SELF -Winit-self)
  42. check_and_add_flag(MISSING_DECLARATIONS -Wmissing-declarations)
  43. check_and_add_flag(MISSING_VARIABLE_DECLARATIONS -Wmissing-variable-declarations)
  44. # Disable -Wstringop-truncation warnings as they result in many false positives.
  45. # In most (all?) cases where std::strncpy is used, we want to fill the entire buffer
  46. # or match emulated code that also ignores the null terminator, so the warnings are not useful.
  47. # Given that Dolphin itself mostly uses std::string, they do not really help catch any bugs.
  48. check_cxx_compiler_flag(-Wstringop-truncation HAS_STRINGOP_TRUNCATION_WARNING)
  49. if (HAS_STRINGOP_TRUNCATION_WARNING)
  50. check_and_add_flag(NO_STRINGOP_TRUNCATION -Wno-stringop-truncation)
  51. endif()
  52. # Format string issues that the compiler can detect should be compile time errors.
  53. check_cxx_compiler_flag(-Wformat HAS_FORMAT_WARNING)
  54. if (HAS_FORMAT_WARNING)
  55. check_and_add_flag(FORMAT_WARNING_TO_ERROR -Werror=format)
  56. endif()
  57. endif()
  58. # These aren't actually needed for C11/C++11
  59. # but some dependencies require them (LLVM, libav).
  60. add_definitions(-D__STDC_LIMIT_MACROS)
  61. add_definitions(-D__STDC_CONSTANT_MACROS)
  62. check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
  63. if(HAVE_ELF_AUX_INFO)
  64. add_definitions(-DHAVE_ELF_AUX_INFO)
  65. endif()
  66. add_subdirectory(Core)
  67. if (ANDROID)
  68. add_subdirectory(Android/jni)
  69. endif()
  70. if (ENABLE_TESTS)
  71. add_subdirectory(UnitTests)
  72. endif()
  73. if (DSPTOOL)
  74. add_subdirectory(DSPTool)
  75. endif()
  76. # TODO: Add DSPSpy. Preferably make it option() and cpack component