compilerconfig.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # OBS CMake macOS compiler configuration module
  2. include_guard(GLOBAL)
  3. option(ENABLE_COMPILER_TRACE "Enable clang time-trace" OFF)
  4. mark_as_advanced(ENABLE_COMPILER_TRACE)
  5. if(NOT XCODE)
  6. message(FATAL_ERROR "Building OBS Studio on macOS requires Xcode generator.")
  7. endif()
  8. include(compiler_common)
  9. add_compile_options("$<$<NOT:$<COMPILE_LANGUAGE:Swift>>:-fopenmp-simd>")
  10. if(CMAKE_CXX_STANDARD GREATER_EQUAL 20)
  11. add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-char8_t>)
  12. endif()
  13. # Ensure recent enough Xcode and platform SDK
  14. function(check_sdk_requirements)
  15. set(obs_macos_minimum_sdk 15.0) # Keep in sync with Xcode
  16. set(obs_macos_minimum_xcode 16.0) # Keep in sync with SDK
  17. execute_process(
  18. COMMAND xcrun --sdk macosx --show-sdk-platform-version
  19. OUTPUT_VARIABLE obs_macos_current_sdk
  20. RESULT_VARIABLE result
  21. OUTPUT_STRIP_TRAILING_WHITESPACE
  22. )
  23. if(NOT result EQUAL 0)
  24. message(
  25. FATAL_ERROR
  26. "Failed to fetch macOS SDK version. "
  27. "Ensure that the macOS SDK is installed and that xcode-select points at the Xcode developer directory."
  28. )
  29. endif()
  30. message(DEBUG "macOS SDK version: ${obs_macos_current_sdk}")
  31. if(obs_macos_current_sdk VERSION_LESS obs_macos_minimum_sdk)
  32. message(
  33. FATAL_ERROR
  34. "Your macOS SDK version (${obs_macos_current_sdk}) is too low. "
  35. "The macOS ${obs_macos_minimum_sdk} SDK (Xcode ${obs_macos_minimum_xcode}) is required to build OBS."
  36. )
  37. endif()
  38. execute_process(COMMAND xcrun --find xcodebuild OUTPUT_VARIABLE obs_macos_xcodebuild RESULT_VARIABLE result)
  39. if(NOT result EQUAL 0)
  40. message(
  41. FATAL_ERROR
  42. "Xcode was not found. "
  43. "Ensure you have installed Xcode and that xcode-select points at the Xcode developer directory."
  44. )
  45. endif()
  46. message(DEBUG "Path to xcodebuild binary: ${obs_macos_xcodebuild}")
  47. if(XCODE_VERSION VERSION_LESS obs_macos_minimum_xcode)
  48. message(
  49. FATAL_ERROR
  50. "Your Xcode version (${XCODE_VERSION}) is too low. Xcode ${obs_macos_minimum_xcode} is required to build OBS."
  51. )
  52. endif()
  53. endfunction()
  54. check_sdk_requirements()
  55. # Enable dSYM generator for release builds
  56. string(APPEND CMAKE_C_FLAGS_RELEASE " -g")
  57. string(APPEND CMAKE_CXX_FLAGS_RELEASE " -g")
  58. string(APPEND CMAKE_OBJC_FLAGS_RELEASE " -g")
  59. string(APPEND CMAKE_OBJCXX_FLAGS_RELEASE " -g")
  60. # Default ObjC compiler options used by Xcode:
  61. #
  62. # * -Wno-implicit-atomic-properties
  63. # * -Wno-objc-interface-ivars
  64. # * -Warc-repeated-use-of-weak
  65. # * -Wno-arc-maybe-repeated-use-of-weak
  66. # * -Wimplicit-retain-self
  67. # * -Wduplicate-method-match
  68. # * -Wshadow
  69. # * -Wfloat-conversion
  70. # * -Wobjc-literal-conversion
  71. # * -Wno-selector
  72. # * -Wno-strict-selector-match
  73. # * -Wundeclared-selector
  74. # * -Wdeprecated-implementations
  75. # * -Wprotocol
  76. # * -Werror=block-capture-autoreleasing
  77. # * -Wrange-loop-analysis
  78. # Default ObjC++ compiler options used by Xcode:
  79. #
  80. # * -Wno-non-virtual-dtor
  81. add_compile_definitions(
  82. $<$<CONFIG:DEBUG>:DEBUG>
  83. $<$<NOT:$<COMPILE_LANGUAGE:Swift>>:$<$<CONFIG:DEBUG>:_DEBUG>>
  84. $<$<NOT:$<COMPILE_LANGUAGE:Swift>>:SIMDE_ENABLE_OPENMP>
  85. )
  86. if(ENABLE_COMPILER_TRACE)
  87. add_compile_options(
  88. $<$<NOT:$<COMPILE_LANGUAGE:Swift>>:-ftime-trace>
  89. "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -debug-time-expression-type-checking>"
  90. "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -debug-time-function-bodies>"
  91. )
  92. add_link_options(LINKER:-print_statistics)
  93. endif()