1
0

ObsPluginHelpers.cmake 28 KB

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