compilerconfig.cmake 3.5 KB

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