compilerconfig.cmake 3.3 KB

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