ObsPluginHelpers.cmake 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. if(POLICY CMP0087)
  2. cmake_policy(SET CMP0087 NEW)
  3. endif()
  4. set(OBS_STANDALONE_PLUGIN_DIR ${CMAKE_SOURCE_DIR}/release)
  5. include(GNUInstallDirs)
  6. if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
  7. set(OS_MACOS ON)
  8. set(OS_POSIX ON)
  9. elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD")
  10. set(OS_POSIX ON)
  11. string(TOUPPER "${CMAKE_SYSTEM_NAME}" _SYSTEM_NAME_U)
  12. set(OS_${_SYSTEM_NAME_U} ON)
  13. elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  14. set(OS_WINDOWS ON)
  15. set(OS_POSIX OFF)
  16. endif()
  17. # Old-Style plugin detected, find "modern" libobs variant instead and set global include directories to fix "bad" plugin
  18. # behavior
  19. if(DEFINED LIBOBS_INCLUDE_DIR AND NOT TARGET OBS::libobs)
  20. message(
  21. DEPRECATION
  22. "You are using an outdated method of adding 'libobs' to your project. Refer to the updated wiki on how to build and export 'libobs' and use it in your plugin projects."
  23. )
  24. find_package(libobs REQUIRED)
  25. if(TARGET OBS::libobs)
  26. set_target_properties(OBS::libobs PROPERTIES IMPORTED_GLOBAL TRUE)
  27. message(STATUS "OBS: Using modern libobs target")
  28. add_library(libobs ALIAS OBS::libobs)
  29. if(OS_WINDOWS)
  30. add_library(w32-pthreads ALIAS OBS::w32-pthreads)
  31. endif()
  32. endif()
  33. endif()
  34. # Set macOS and Windows specific if default value is used
  35. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND (OS_WINDOWS OR OS_MACOS))
  36. set(CMAKE_INSTALL_PREFIX
  37. ${OBS_STANDALONE_PLUGIN_DIR}
  38. CACHE STRING "Directory to install OBS plugin after building" FORCE)
  39. endif()
  40. # Set default build type to RelWithDebInfo and specify allowed alternative values
  41. if(NOT CMAKE_BUILD_TYPE)
  42. set(CMAKE_BUILD_TYPE
  43. "RelWithDebInfo"
  44. CACHE STRING "OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE)
  45. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel)
  46. endif()
  47. # Set default Qt version to AUTO, preferring an available Qt6 with a fallback to Qt5
  48. if(NOT QT_VERSION)
  49. set(QT_VERSION
  50. AUTO
  51. CACHE STRING "OBS Qt version [AUTO, 6, 5]" FORCE)
  52. set_property(CACHE QT_VERSION PROPERTY STRINGS AUTO 6 5)
  53. endif()
  54. # Macro to find best possible Qt version for use with the project:
  55. #
  56. # * Use QT_VERSION value as a hint for desired Qt version
  57. # * If "AUTO" was specified, prefer Qt6 over Qt5
  58. # * Creates versionless targets of desired component if none had been created by Qt itself (Qt versions < 5.15)
  59. #
  60. macro(find_qt)
  61. set(multiValueArgs COMPONENTS COMPONENTS_WIN COMPONENTS_MAC COMPONENTS_LINUX)
  62. cmake_parse_arguments(FIND_QT "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  63. # Do not use versionless targets in the first step to avoid Qt::Core being clobbered by later opportunistic
  64. # find_package runs
  65. set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
  66. # Loop until _QT_VERSION is set (or FATAL_ERROR aborts script execution early)
  67. while(NOT _QT_VERSION)
  68. if(QT_VERSION STREQUAL AUTO AND NOT _QT_TEST_VERSION)
  69. set(_QT_TEST_VERSION 6)
  70. elseif(NOT QT_VERSION STREQUAL AUTO)
  71. set(_QT_TEST_VERSION ${QT_VERSION})
  72. endif()
  73. find_package(
  74. Qt${_QT_TEST_VERSION}
  75. COMPONENTS Core
  76. QUIET)
  77. if(TARGET Qt${_QT_TEST_VERSION}::Core)
  78. set(_QT_VERSION
  79. ${_QT_TEST_VERSION}
  80. CACHE INTERNAL "")
  81. message(STATUS "Qt version found: ${_QT_VERSION}")
  82. unset(_QT_TEST_VERSION)
  83. break()
  84. elseif(QT_VERSION STREQUAL AUTO)
  85. if(_QT_TEST_VERSION EQUAL 6)
  86. message(WARNING "Qt6 was not found, falling back to Qt5")
  87. set(_QT_TEST_VERSION 5)
  88. continue()
  89. endif()
  90. endif()
  91. message(FATAL_ERROR "Neither Qt6 nor Qt5 found.")
  92. endwhile()
  93. # Enable versionless targets for the remaining Qt components
  94. set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF)
  95. set(_QT_COMPONENTS ${FIND_QT_COMPONENTS})
  96. if(OS_WINDOWS)
  97. list(APPEND _QT_COMPONENTS ${FIND_QT_COMPONENTS_WIN})
  98. elseif(OS_MACOS)
  99. list(APPEND _QT_COMPONENTS ${FIND_QT_COMPONENTS_MAC})
  100. else()
  101. list(APPEND _QT_COMPONENTS ${FIND_QT_COMPONENTS_LINUX})
  102. endif()
  103. find_package(
  104. Qt${_QT_VERSION}
  105. COMPONENTS ${_QT_COMPONENTS}
  106. REQUIRED)
  107. list(APPEND _QT_COMPONENTS Core)
  108. if("Gui" IN_LIST FIND_QT_COMPONENTS_LINUX)
  109. list(APPEND _QT_COMPONENTS "GuiPrivate")
  110. endif()
  111. # Check for versionless targets of each requested component and create if necessary
  112. foreach(_COMPONENT IN LISTS _QT_COMPONENTS)
  113. if(NOT TARGET Qt::${_COMPONENT} AND TARGET Qt${_QT_VERSION}::${_COMPONENT})
  114. add_library(Qt::${_COMPONENT} INTERFACE IMPORTED)
  115. set_target_properties(Qt::${_COMPONENT} PROPERTIES INTERFACE_LINK_LIBRARIES Qt${_QT_VERSION}::${_COMPONENT})
  116. endif()
  117. endforeach()
  118. endmacro()
  119. # Set relative path variables for file configurations
  120. file(RELATIVE_PATH RELATIVE_INSTALL_PATH ${CMAKE_SOURCE_DIR} ${CMAKE_INSTALL_PREFIX})
  121. file(RELATIVE_PATH RELATIVE_BUILD_PATH ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
  122. if(OS_POSIX)
  123. # Set default GCC/clang compile options:
  124. #
  125. # * Treat warnings as errors
  126. # * Enable extra warnings, https://clang.llvm.org/docs/DiagnosticsReference.html#wextra
  127. # * Warning about usage of variable length array, https://clang.llvm.org/docs/DiagnosticsReference.html#wvla
  128. # * Warning about bad format specifiers, https://clang.llvm.org/docs/DiagnosticsReference.html#wformat
  129. # * Warning about non-strings used as format strings,
  130. # https://clang.llvm.org/docs/DiagnosticsReference.html#wformat-security
  131. # * Warning about non-exhaustive switch blocks, https://clang.llvm.org/docs/DiagnosticsReference.html#wswitch
  132. # * Warning about unused parameters, https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-parameter
  133. # * DISABLE warning about unused functions, https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function
  134. # * DISABLE warning about missing field initializers,
  135. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-field-initializers
  136. # * DISABLE strict aliasing optimisations
  137. # * C ONLY - treat implicit function declarations (use before declare) as errors,
  138. # https://clang.llvm.org/docs/DiagnosticsReference.html#wimplicit-function-declaration
  139. # * C ONLY - DISABLE warning about missing braces around subobject initalizers,
  140. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-braces
  141. # * C ONLY, Clang ONLY - Warning about implicit conversion of NULL to another type,
  142. # https://clang.llvm.org/docs/DiagnosticsReference.html#wnull-conversion
  143. # * C & C++, Clang ONLY - Disable warning about integer conversion losing precision,
  144. # https://clang.llvm.org/docs/DiagnosticsReference.html#wshorten-64-to-32
  145. # * C++, GCC ONLY - Warning about implicit conversion of NULL to another type
  146. # * Enable color diagnostics on Clang (CMAKE_COLOR_DIAGNOSTICS available in CMake 3.24)
  147. target_compile_options(
  148. ${CMAKE_PROJECT_NAME}
  149. PRIVATE
  150. -Werror
  151. -Wextra
  152. -Wvla
  153. -Wformat
  154. -Wformat-security
  155. -Wswitch
  156. -Wunused-parameter
  157. -Wno-unused-function
  158. -Wno-missing-field-initializers
  159. -fno-strict-aliasing
  160. "$<$<COMPILE_LANGUAGE:C>:-Werror-implicit-function-declaration;-Wno-missing-braces>"
  161. "$<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang>:-Wnull-conversion;-Wno-error=shorten-64-to-32;-fcolor-diagnostics>"
  162. "$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:-Wnull-conversion;-Wno-error=shorten-64-to-32;-fcolor-diagnostics>"
  163. "$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wconversion-null>"
  164. "$<$<CONFIG:DEBUG>:-DDEBUG=1;-D_DEBUG=1>")
  165. # GCC 12.1.0 has a regression bug which trigger maybe-uninitialized warnings where there is not.
  166. # (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105562)
  167. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "12.1.0")
  168. target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wno-error=maybe-uninitialized)
  169. endif()
  170. if(NOT CCACHE_SET)
  171. # Try to find and enable ccache
  172. find_program(CCACHE_PROGRAM "ccache")
  173. set(CCACHE_SUPPORT
  174. ON
  175. CACHE BOOL "Enable ccache support")
  176. mark_as_advanced(CCACHE_PROGRAM)
  177. if(CCACHE_PROGRAM AND CCACHE_SUPPORT)
  178. set(CMAKE_CXX_COMPILER_LAUNCHER
  179. ${CCACHE_PROGRAM}
  180. CACHE INTERNAL "")
  181. set(CMAKE_C_COMPILER_LAUNCHER
  182. ${CCACHE_PROGRAM}
  183. CACHE INTERNAL "")
  184. set(CMAKE_OBJC_COMPILER_LAUNCHER
  185. ${CCACHE_PROGRAM}
  186. CACHE INTERNAL "")
  187. set(CMAKE_OBJCXX_COMPILER_LAUNCHER
  188. ${CCACHE_PROGRAM}
  189. CACHE INTERNAL "")
  190. set(CMAKE_CUDA_COMPILER_LAUNCHER
  191. ${CCACHE_PROGRAM}
  192. CACHE INTERNAL "") # CMake 3.9+
  193. set(CCACHE_SET
  194. ON
  195. CACHE INTERNAL "")
  196. endif()
  197. endif()
  198. endif()
  199. # Set required C++ standard to C++17
  200. set(CMAKE_CXX_STANDARD 17)
  201. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  202. set(CMAKE_CXX_EXTENSIONS OFF)
  203. # Get lowercase host architecture for easier comparison
  204. if(MSVC_CXX_ARCHITECTURE_ID)
  205. string(TOLOWER ${MSVC_CXX_ARCHITECTURE_ID} _HOST_ARCH)
  206. else()
  207. string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} _HOST_ARCH)
  208. endif()
  209. if(_HOST_ARCH MATCHES "i[3-6]86|x86|x64|x86_64|amd64" AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
  210. # Enable MMX, SSE and SSE2 on compatible host systems (assuming no cross-compile)
  211. set(ARCH_SIMD_FLAGS -mmmx -msse -msse2)
  212. elseif(_HOST_ARCH MATCHES "arm64|arm64e|aarch64")
  213. # Enable available built-in SIMD support in Clang and GCC
  214. if(CMAKE_C_COMPILER_ID MATCHES "^(Apple)?Clang|GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang|GNU")
  215. include(CheckCCompilerFlag)
  216. include(CheckCXXCompilerFlag)
  217. check_c_compiler_flag("-fopenmp-simd" C_COMPILER_SUPPORTS_OPENMP_SIMD)
  218. check_cxx_compiler_flag("-fopenmp-simd" CXX_COMPILER_SUPPORTS_OPENMP_SIMD)
  219. target_compile_options(
  220. ${CMAKE_PROJECT_NAME}
  221. PRIVATE -DSIMDE_ENABLE_OPENMP
  222. "$<$<AND:$<COMPILE_LANGUAGE:C>,$<BOOL:C_COMPILER_SUPPORTS_OPENMP_SIMD>>:-fopenmp-simd>"
  223. "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<BOOL:CXX_COMPILER_SUPPORTS_OPENMP_SIMD>>:-fopenmp-simd>")
  224. endif()
  225. endif()
  226. # macOS specific settings
  227. if(OS_MACOS)
  228. # Set macOS-specific C++ standard library
  229. target_compile_options(${CMAKE_PROJECT_NAME}
  230. PRIVATE "$<$<COMPILE_LANG_AND_ID:OBJC,AppleClang,Clang>:-fcolor-diagnostics>" -stdlib=libc++)
  231. # Set build architecture to host architecture by default
  232. if(NOT CMAKE_OSX_ARCHITECTURES)
  233. set(CMAKE_OSX_ARCHITECTURES
  234. ${CMAKE_HOST_SYSTEM_PROCESSOR}
  235. CACHE STRING "Build architecture for macOS" FORCE)
  236. endif()
  237. set_property(CACHE CMAKE_OSX_ARCHITECTURES PROPERTY STRINGS arm64 x86_64 "arm64;x86_64")
  238. # Set deployment target to 11.0 for Apple Silicon or 10.15 for Intel and Universal builds
  239. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  240. set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64] "11.0")
  241. set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=x86_64] "10.15")
  242. if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
  243. set(_MACOS_DEPLOYMENT_TARGET "11.0")
  244. else()
  245. set(_MACOS_DEPLOYMENT_TARGET "10.15")
  246. endif()
  247. set(CMAKE_OSX_DEPLOYMENT_TARGET
  248. ${_MACOS_DEPLOYMENT_TARGET}
  249. CACHE STRING "Minimum macOS version to target for deployment (at runtime); newer APIs weak linked" FORCE)
  250. unset(_MACOS_DEPLOYMENT_TARGET)
  251. endif()
  252. set_property(CACHE CMAKE_OSX_DEPLOYMENT_TARGET PROPERTY STRINGS 13.0 12.0 11.0 10.15)
  253. # Override macOS install directory
  254. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  255. set(CMAKE_INSTALL_PREFIX
  256. ${CMAKE_BINARY_DIR}/install
  257. CACHE STRING "Directory to install OBS to after building" FORCE)
  258. endif()
  259. # Set up codesigning for Xcode builds with team IDs or standalone builds with developer identity
  260. if(NOT OBS_BUNDLE_CODESIGN_TEAM)
  261. if(NOT OBS_BUNDLE_CODESIGN_IDENTITY)
  262. set(OBS_BUNDLE_CODESIGN_IDENTITY
  263. "-"
  264. CACHE STRING "OBS code signing identity for macOS" FORCE)
  265. endif()
  266. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${OBS_BUNDLE_CODESIGN_IDENTITY})
  267. else()
  268. # Team ID specified, warn if Xcode generator is not used and fall back to ad-hoc signing
  269. if(NOT XCODE)
  270. message(
  271. WARNING
  272. "Code signing with a team identifier is only supported with the Xcode generator. Using ad-hoc code signature instead."
  273. )
  274. if(NOT OBS_BUNDLE_CODESIGN_IDENTITY)
  275. set(OBS_BUNDLE_CODESIGN_IDENTITY
  276. "-"
  277. CACHE STRING "OBS code signing identity for macOS" FORCE)
  278. endif()
  279. else()
  280. unset(OBS_BUNDLE_CODESIGN_IDENTITY)
  281. set_property(CACHE OBS_BUNDLE_CODESIGN_TEAM PROPERTY HELPSTRING "OBS code signing team for macOS")
  282. set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Automatic)
  283. set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${OBS_BUNDLE_CODESIGN_TEAM})
  284. endif()
  285. endif()
  286. # Set path to entitlements property list for codesigning. Entitlements should match the host binary, in this case
  287. # OBS.app.
  288. set(OBS_CODESIGN_ENTITLEMENTS
  289. ${CMAKE_SOURCE_DIR}/cmake/bundle/macos/entitlements.plist
  290. CACHE INTERNAL "Path to codesign entitlements plist")
  291. # Enable linker codesigning by default. Building OBS or plugins on host systems older than macOS 10.15 is not
  292. # supported
  293. set(OBS_CODESIGN_LINKER
  294. ON
  295. CACHE BOOL "Enable linker codesigning on macOS (macOS 11+ required)")
  296. # Tell Xcode to pretend the linker signed binaries so that editing with install_name_tool preserves ad-hoc signatures.
  297. # This option is supported by codesign on macOS 11 or higher. See CMake Issue 21854:
  298. # https://gitlab.kitware.com/cmake/cmake/-/issues/21854
  299. if(OBS_CODESIGN_LINKER)
  300. set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed")
  301. endif()
  302. # Set default options for bundling on macOS
  303. set(CMAKE_MACOSX_RPATH ON)
  304. set(CMAKE_SKIP_BUILD_RPATH OFF)
  305. set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
  306. set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks/")
  307. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF)
  308. # Helper function for plugin targets (macOS version)
  309. function(setup_plugin_target target)
  310. # Sanity check for required bundle information
  311. #
  312. # * Bundle identifier
  313. # * Bundle version
  314. # * Short version string
  315. if(NOT DEFINED MACOSX_PLUGIN_GUI_IDENTIFIER)
  316. message(
  317. FATAL_ERROR
  318. "No 'MACOSX_PLUGIN_GUI_IDENTIFIER' set, but is required to build plugin bundles on macOS - example: 'com.yourname.pluginname'"
  319. )
  320. endif()
  321. if(NOT DEFINED MACOSX_PLUGIN_BUNDLE_VERSION)
  322. message(
  323. FATAL_ERROR
  324. "No 'MACOSX_PLUGIN_BUNDLE_VERSION' set, but is required to build plugin bundles on macOS - example: '25'")
  325. endif()
  326. if(NOT DEFINED MACOSX_PLUGIN_SHORT_VERSION_STRING)
  327. message(
  328. FATAL_ERROR
  329. "No 'MACOSX_PLUGIN_SHORT_VERSION_STRING' set, but is required to build plugin bundles on macOS - example: '1.0.2'"
  330. )
  331. endif()
  332. # Set variables for automatic property list generation
  333. set(MACOSX_PLUGIN_BUNDLE_NAME
  334. "${target}"
  335. PARENT_SCOPE)
  336. set(MACOSX_PLUGIN_BUNDLE_VERSION
  337. "${MACOSX_PLUGIN_BUNDLE_VERSION}"
  338. PARENT_SCOPE)
  339. set(MACOSX_PLUGIN_SHORT_VERSION_STRING
  340. "${MACOSX_PLUGIN_SHORT_VERSION_STRING}"
  341. PARENT_SCOPE)
  342. set(MACOSX_PLUGIN_EXECUTABLE_NAME
  343. "${target}"
  344. PARENT_SCOPE)
  345. set(MACOSX_PLUGIN_BUNDLE_TYPE
  346. "BNDL"
  347. PARENT_SCOPE)
  348. # Set installation target to install prefix root (default for bundles)
  349. install(
  350. TARGETS ${target}
  351. LIBRARY DESTINATION "."
  352. COMPONENT obs_plugins
  353. NAMELINK_COMPONENT ${target}_Development)
  354. if(TARGET Qt::Core)
  355. # Framework version has changed between Qt5 (uses wrong numerical version) and Qt6 (uses correct alphabetical
  356. # version)
  357. if(${_QT_VERSION} EQUAL 5)
  358. set(_QT_FW_VERSION "${QT_VERSION}")
  359. else()
  360. set(_QT_FW_VERSION "A")
  361. endif()
  362. # Set up install-time command to fix Qt library references to point into OBS.app bundle
  363. set(_COMMAND
  364. "${CMAKE_INSTALL_NAME_TOOL} \\
  365. -change ${CMAKE_PREFIX_PATH}/lib/QtWidgets.framework/Versions/${QT_VERSION}/QtWidgets @rpath/QtWidgets.framework/Versions/${_QT_FW_VERSION}/QtWidgets \\
  366. -change ${CMAKE_PREFIX_PATH}/lib/QtCore.framework/Versions/${QT_VERSION}/QtCore @rpath/QtCore.framework/Versions/${_QT_FW_VERSION}/QtCore \\
  367. -change ${CMAKE_PREFIX_PATH}/lib/QtGui.framework/Versions/${QT_VERSION}/QtGui @rpath/QtGui.framework/Versions/${_QT_FW_VERSION}/QtGui \\
  368. \\\"\${CMAKE_INSTALL_PREFIX}/${target}.plugin/Contents/MacOS/${target}\\\"")
  369. install(CODE "execute_process(COMMAND /bin/sh -c \"${_COMMAND}\")" COMPONENT obs_plugins)
  370. unset(_QT_FW_VERSION)
  371. endif()
  372. # Set macOS bundle properties
  373. set_target_properties(
  374. ${target}
  375. PROPERTIES PREFIX ""
  376. BUNDLE ON
  377. BUNDLE_EXTENSION "plugin"
  378. OUTPUT_NAME ${target}
  379. MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/bundle/macOS/Plugin-Info.plist.in"
  380. XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${MACOSX_PLUGIN_GUI_IDENTIFIER}"
  381. XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS
  382. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/bundle/macOS/entitlements.plist")
  383. # If not building with Xcode, manually code-sign the plugin
  384. if(NOT XCODE)
  385. set(_COMMAND
  386. "/usr/bin/codesign --force \\
  387. --sign \\\"${OBS_BUNDLE_CODESIGN_IDENTITY}\\\" \\
  388. --options runtime \\
  389. --entitlements \\\"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/bundle/macOS/entitlements.plist\\\" \\
  390. \\\"\${CMAKE_INSTALL_PREFIX}/${target}.plugin\\\"")
  391. install(CODE "execute_process(COMMAND /bin/sh -c \"${_COMMAND}\")" COMPONENT obs_plugins)
  392. endif()
  393. install_bundle_resources(${target})
  394. endfunction()
  395. # Helper function to add resources from "data" directory as bundle resources
  396. function(install_bundle_resources target)
  397. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data)
  398. file(GLOB_RECURSE _DATA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
  399. foreach(_DATA_FILE IN LISTS _DATA_FILES)
  400. file(RELATIVE_PATH _RELATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/data/ ${_DATA_FILE})
  401. get_filename_component(_RELATIVE_PATH ${_RELATIVE_PATH} PATH)
  402. target_sources(${target} PRIVATE ${_DATA_FILE})
  403. set_source_files_properties(${_DATA_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/${_RELATIVE_PATH})
  404. string(REPLACE "\\" "\\\\" _GROUP_NAME ${_RELATIVE_PATH})
  405. source_group("Resources\\${_GROUP_NAME}" FILES ${_DATA_FILE})
  406. endforeach()
  407. endif()
  408. endfunction()
  409. else()
  410. # Check for target architecture (64bit vs 32bit)
  411. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  412. set(_ARCH_SUFFIX 64)
  413. else()
  414. set(_ARCH_SUFFIX 32)
  415. endif()
  416. set(OBS_OUTPUT_DIR ${CMAKE_BINARY_DIR}/rundir)
  417. # Unix specific settings
  418. if(OS_POSIX)
  419. # Paths to binaries and plugins differ between portable and non-portable builds on Linux
  420. option(LINUX_PORTABLE "Build portable version (Linux)" ON)
  421. if(NOT LINUX_PORTABLE)
  422. set(OBS_LIBRARY_DESTINATION ${CMAKE_INSTALL_LIBDIR})
  423. set(OBS_PLUGIN_DESTINATION ${OBS_LIBRARY_DESTINATION}/obs-plugins)
  424. set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
  425. set(OBS_DATA_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/obs)
  426. else()
  427. set(OBS_LIBRARY_DESTINATION bin/${_ARCH_SUFFIX}bit)
  428. set(OBS_PLUGIN_DESTINATION obs-plugins/${_ARCH_SUFFIX}bit)
  429. set(CMAKE_INSTALL_RPATH "$ORIGIN/" "${CMAKE_INSTALL_PREFIX}/${OBS_LIBRARY_DESTINATION}")
  430. set(OBS_DATA_DESTINATION "data")
  431. endif()
  432. # Setup Linux-specific CPack values for "deb" package generation
  433. if(OS_LINUX)
  434. set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
  435. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${LINUX_MAINTAINER_EMAIL}")
  436. set(CPACK_PACKAGE_VERSION "${CMAKE_PROJECT_VERSION}")
  437. set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-linux-x86_64")
  438. set(CPACK_GENERATOR "DEB")
  439. set(CPACK_DEBIAN_PACKAGE_DEPENDS
  440. "obs-studio (>= 27.0.0), libqt5core5a (>= 5.9.0~beta), libqt5gui5 (>= 5.3.0), libqt5widgets5 (>= 5.7.0)")
  441. set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_SOURCE_DIR}/release)
  442. if(NOT LINUX_PORTABLE)
  443. set(CPACK_SET_DESTDIR ON)
  444. endif()
  445. include(CPack)
  446. endif()
  447. # Windows specific settings
  448. else()
  449. set(OBS_LIBRARY_DESTINATION "bin/${_ARCH_SUFFIX}bit")
  450. set(OBS_LIBRARY32_DESTINATION "bin/32bit")
  451. set(OBS_LIBRARY64_DESTINATION "bin/64bit")
  452. set(OBS_PLUGIN_DESTINATION "obs-plugins/${_ARCH_SUFFIX}bit")
  453. set(OBS_PLUGIN32_DESTINATION "obs-plugins/32bit")
  454. set(OBS_PLUGIN64_DESTINATION "obs-plugins/64bit")
  455. set(OBS_DATA_DESTINATION "data")
  456. if(MSVC)
  457. # Set default Visual Studio CL.exe compile options.
  458. #
  459. # * Enable building with multiple processes,
  460. # https://docs.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes?view=msvc-170
  461. # * Enable lint-like warnings,
  462. # https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
  463. # * Enable treating all warnings as errors,
  464. # https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
  465. # * RelWithDebInfo ONLY - Enable expanding of all functions not explicitly marked for no inlining,
  466. # https://docs.microsoft.com/en-us/cpp/build/reference/ob-inline-function-expansion?view=msvc-170
  467. # * Enable UNICODE support,
  468. # https://docs.microsoft.com/en-us/windows/win32/learnwin32/working-with-strings#unicode-and-ansi-functions
  469. # * DISABLE warnings about using POSIX function names,
  470. # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=msvc-170#posix-function-names
  471. # * DISABLE warnings about unsafe CRT library functions,
  472. # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=msvc-170#unsafe-crt-library-functions
  473. # * DISABLE warnings about nonstandard nameless structs/unions,
  474. # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4201?view=msvc-170
  475. target_compile_options(
  476. ${CMAKE_PROJECT_NAME}
  477. PRIVATE /MP
  478. /W3
  479. /WX
  480. /wd4201
  481. "$<$<CONFIG:RELWITHDEBINFO>:/Ob2>"
  482. "$<$<CONFIG:DEBUG>:/DDEBUG=1;/D_DEBUG=1>"
  483. /DUNICODE
  484. /D_UNICODE
  485. /D_CRT_SECURE_NO_WARNINGS
  486. /D_CRT_NONSTDC_NO_WARNINGS)
  487. # Set default Visual Studio linker options.
  488. #
  489. # * Enable removal of functions and data that are never used,
  490. # https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170
  491. # * Enable treating all warnings as errors,
  492. # https://docs.microsoft.com/en-us/cpp/build/reference/wx-treat-linker-warnings-as-errors?view=msvc-170
  493. # * x64 ONLY - DISABLE creation of table of safe exception handlers,
  494. # https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers?view=msvc-170
  495. # * Debug ONLY - DISABLE incremental linking,
  496. # https://docs.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=msvc-170
  497. # * RelWithDebInfo ONLY - Disable incremental linking, but enable COMDAT folding,
  498. # https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170
  499. target_link_options(
  500. ${CMAKE_PROJECT_NAME}
  501. PRIVATE
  502. "LINKER:/OPT:REF"
  503. "LINKER:/WX"
  504. "$<$<NOT:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>>:LINKER\:/SAFESEH\:NO>"
  505. "$<$<CONFIG:DEBUG>:LINKER\:/INCREMENTAL\:NO>"
  506. "$<$<CONFIG:RELWITHDEBINFO>:LINKER\:/INCREMENTAL\:NO;/OPT\:ICF>")
  507. endif()
  508. endif()
  509. # Helper function for plugin targets (Windows and Linux version)
  510. function(setup_plugin_target target)
  511. # Set prefix to empty string to avoid automatic naming of generated library, i.e. "lib<YOUR_PLUGIN_NAME>"
  512. set_target_properties(${target} PROPERTIES PREFIX "")
  513. # Set install directories
  514. install(
  515. TARGETS ${target}
  516. RUNTIME DESTINATION "${OBS_PLUGIN_DESTINATION}" COMPONENT ${target}_Runtime
  517. LIBRARY DESTINATION "${OBS_PLUGIN_DESTINATION}"
  518. COMPONENT ${target}_Runtime
  519. NAMELINK_COMPONENT ${target}_Development)
  520. # Set rundir install directory
  521. install(
  522. FILES $<TARGET_FILE:${target}>
  523. DESTINATION $<CONFIG>/${OBS_PLUGIN_DESTINATION}
  524. COMPONENT obs_rundir
  525. EXCLUDE_FROM_ALL)
  526. if(OS_WINDOWS)
  527. # Set install directory for optional PDB symbol files
  528. install(
  529. FILES $<TARGET_PDB_FILE:${target}>
  530. CONFIGURATIONS "RelWithDebInfo" "Debug"
  531. DESTINATION ${OBS_PLUGIN_DESTINATION}
  532. COMPONENT ${target}_Runtime
  533. OPTIONAL)
  534. # Set rundir install directory for optional PDB symbol files
  535. install(
  536. FILES $<TARGET_PDB_FILE:${target}>
  537. CONFIGURATIONS "RelWithDebInfo" "Debug"
  538. DESTINATION $<CONFIG>/${OBS_PLUGIN_DESTINATION}
  539. COMPONENT obs_rundir
  540. OPTIONAL EXCLUDE_FROM_ALL)
  541. endif()
  542. # Add resources from data directory
  543. setup_target_resources(${target} obs-plugins/${target})
  544. # Set up plugin for testing in available OBS build on Windows
  545. if(OS_WINDOWS AND DEFINED OBS_BUILD_DIR)
  546. setup_target_for_testing(${target} obs-plugins/${target})
  547. endif()
  548. # Custom command to install generated plugin into rundir
  549. add_custom_command(
  550. TARGET ${target}
  551. POST_BUILD
  552. COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_PREFIX=${OBS_OUTPUT_DIR} -DCMAKE_INSTALL_COMPONENT=obs_rundir
  553. -DCMAKE_INSTALL_CONFIG_NAME=$<CONFIG> -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
  554. COMMENT "Installing to plugin rundir"
  555. VERBATIM)
  556. endfunction()
  557. # Helper function to add resources from "data" directory
  558. function(setup_target_resources target destination)
  559. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data)
  560. install(
  561. DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/
  562. DESTINATION ${OBS_DATA_DESTINATION}/${destination}
  563. USE_SOURCE_PERMISSIONS
  564. COMPONENT obs_plugins)
  565. install(
  566. DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data
  567. DESTINATION $<CONFIG>/${OBS_DATA_DESTINATION}/${destination}
  568. USE_SOURCE_PERMISSIONS
  569. COMPONENT obs_rundir
  570. EXCLUDE_FROM_ALL)
  571. endif()
  572. endfunction()
  573. if(OS_WINDOWS)
  574. # Additional Windows-only helper function to copy plugin to existing OBS development directory:
  575. #
  576. # Copies plugin with associated PDB symbol files as well as contents of data directory into the OBS rundir as
  577. # specified by "OBS_BUILD_DIR".
  578. function(setup_target_for_testing target destination)
  579. install(
  580. FILES $<TARGET_FILE:${target}>
  581. DESTINATION $<CONFIG>/${OBS_PLUGIN_DESTINATION}
  582. COMPONENT obs_testing
  583. EXCLUDE_FROM_ALL)
  584. install(
  585. FILES $<TARGET_PDB_FILE:${target}>
  586. CONFIGURATIONS "RelWithDebInfo" "Debug"
  587. DESTINATION $<CONFIG>/${OBS_PLUGIN_DESTINATION}
  588. COMPONENT obs_testing
  589. OPTIONAL EXCLUDE_FROM_ALL)
  590. install(
  591. DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/
  592. DESTINATION $<CONFIG>/${OBS_DATA_DESTINATION}/${destination}
  593. USE_SOURCE_PERMISSIONS
  594. COMPONENT obs_testing
  595. EXCLUDE_FROM_ALL)
  596. add_custom_command(
  597. TARGET ${target}
  598. POST_BUILD
  599. COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_PREFIX=${OBS_BUILD_DIR}/rundir -DCMAKE_INSTALL_COMPONENT=obs_testing
  600. -DCMAKE_INSTALL_CONFIG_NAME=$<CONFIG> -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
  601. COMMENT "Installing to OBS test directory"
  602. VERBATIM)
  603. endfunction()
  604. endif()
  605. endif()