ObsPluginHelpers.cmake 28 KB

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