CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. cmake_minimum_required(VERSION 3.10)
  2. # Change obs-plugintemplate to your plugin's name in a machine-readable format
  3. # (e.g.: obs-myawesomeplugin) and set
  4. project(obs-plugintemplate VERSION 1.0.0)
  5. # Replace `Your Name Here` with the name (yours or your organization's) you want
  6. # to see as the author of the plugin (in the plugin's metadata itself and in the installers)
  7. set(PLUGIN_AUTHOR "Your Name Here")
  8. # Replace `com.example.obs-plugin-template` with a unique Bundle ID for macOS releases
  9. # (used both in the installer and when submitting the installer for notarization)
  10. set(MACOS_BUNDLEID "com.example.obs-plugintemplate")
  11. # Replace `me@contoso.com` with the maintainer email address you want to put in Linux packages
  12. set(LINUX_MAINTAINER_EMAIL "me@contoso.com")
  13. # TAKE NOTE: No need to edit things past this point
  14. set(CMAKE_PREFIX_PATH "${QTDIR}")
  15. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  16. set(CMAKE_AUTOMOC ON)
  17. set(CMAKE_AUTOUIC ON)
  18. # In case you need C++
  19. set(CMAKE_CXX_STANDARD 11)
  20. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  21. if (WIN32 OR APPLE)
  22. include(external/FindLibObs.cmake)
  23. endif()
  24. find_package(LibObs REQUIRED)
  25. find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
  26. configure_file(
  27. src/plugin-macros.h.in
  28. ../src/plugin-macros.generated.h
  29. )
  30. configure_file(
  31. installer/installer-macOS.pkgproj.in
  32. ../installer/installer-macOS.generated.pkgproj
  33. )
  34. configure_file(
  35. installer/installer-Windows.iss.in
  36. ../installer/installer-Windows.generated.iss
  37. )
  38. configure_file(
  39. ci/ci_includes.sh.in
  40. ../ci/ci_includes.generated.sh
  41. )
  42. configure_file(
  43. ci/ci_includes.cmd.in
  44. ../ci/ci_includes.generated.cmd
  45. )
  46. set(PLUGIN_SOURCES
  47. src/plugin-main.c)
  48. set(PLUGIN_HEADERS
  49. src/plugin-macros.generated.h)
  50. # --- Platform-independent build settings ---
  51. add_library(${CMAKE_PROJECT_NAME} MODULE ${PLUGIN_SOURCES} ${PLUGIN_HEADERS})
  52. include_directories(
  53. "${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api"
  54. ${Qt5Core_INCLUDES}
  55. ${Qt5Widgets_INCLUDES}
  56. )
  57. target_link_libraries(${CMAKE_PROJECT_NAME}
  58. libobs
  59. Qt5::Core
  60. Qt5::Widgets
  61. )
  62. # --- End of section ---
  63. # --- Windows-specific build settings and tasks ---
  64. if(WIN32)
  65. if(NOT DEFINED OBS_FRONTEND_LIB)
  66. set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library")
  67. message(FATAL_ERROR "Could not find OBS Frontend API\'s library !")
  68. endif()
  69. # Enable Multicore Builds and disable FH4 (to not depend on VCRUNTIME140_1.DLL when building with VS2019)
  70. if (MSVC)
  71. add_definitions(/MP /d2FH4-)
  72. endif()
  73. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  74. set(ARCH_NAME "64bit")
  75. set(OBS_BUILDDIR_ARCH "build64")
  76. else()
  77. set(ARCH_NAME "32bit")
  78. set(OBS_BUILDDIR_ARCH "build32")
  79. endif()
  80. include_directories(
  81. "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/UI"
  82. )
  83. target_link_libraries(${CMAKE_PROJECT_NAME}
  84. "${OBS_FRONTEND_LIB}"
  85. )
  86. # --- Release package helper ---
  87. # The "release" folder has a structure similar OBS' one on Windows
  88. set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release")
  89. add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
  90. # If config is Release or RelWithDebInfo, package release files
  91. COMMAND if $<CONFIG:Release>==1 OR $<CONFIG:RelWithDebInfo>==1 (
  92. "${CMAKE_COMMAND}" -E make_directory
  93. "${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
  94. "${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
  95. )
  96. COMMAND if $<CONFIG:Release>==1 OR $<CONFIG:RelWithDebInfo>==1 (
  97. "${CMAKE_COMMAND}" -E copy_directory
  98. "${PROJECT_SOURCE_DIR}/data"
  99. "${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
  100. )
  101. COMMAND if $<CONFIG:Release>==1 OR $<CONFIG:RelWithDebInfo>==1 (
  102. "${CMAKE_COMMAND}" -E copy
  103. "$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
  104. "${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
  105. )
  106. # If config is RelWithDebInfo, copy the pdb file
  107. COMMAND if $<CONFIG:RelWithDebInfo>==1 (
  108. "${CMAKE_COMMAND}" -E copy
  109. "$<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}>"
  110. "${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
  111. )
  112. # Copy to obs-studio dev environment for immediate testing
  113. COMMAND if $<CONFIG:Debug>==1 (
  114. "${CMAKE_COMMAND}" -E copy
  115. "$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
  116. "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
  117. )
  118. COMMAND if $<CONFIG:Debug>==1 (
  119. "${CMAKE_COMMAND}" -E copy
  120. "$<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}>"
  121. "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}"
  122. )
  123. COMMAND if $<CONFIG:Debug>==1 (
  124. "${CMAKE_COMMAND}" -E make_directory
  125. "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/${CMAKE_PROJECT_NAME}"
  126. )
  127. COMMAND if $<CONFIG:Debug>==1 (
  128. "${CMAKE_COMMAND}" -E copy_directory
  129. "${PROJECT_SOURCE_DIR}/data"
  130. "${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/${CMAKE_PROJECT_NAME}"
  131. )
  132. )
  133. # --- End of sub-section ---
  134. endif()
  135. # --- End of section ---
  136. # --- Linux-specific build settings and tasks ---
  137. if(UNIX AND NOT APPLE)
  138. include(GNUInstallDirs)
  139. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "")
  140. target_link_libraries(${CMAKE_PROJECT_NAME} obs-frontend-api)
  141. file(GLOB locale_files data/locale/*.ini)
  142. install(TARGETS ${CMAKE_PROJECT_NAME}
  143. LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/obs-plugins")
  144. install(FILES ${locale_files}
  145. DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/obs/obs-plugins/${CMAKE_PROJECT_NAME}/locale")
  146. endif()
  147. # --- End of section ---
  148. # -- OS X specific build settings and tasks --
  149. if(APPLE)
  150. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default")
  151. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PREFIX "")
  152. target_link_libraries(${CMAKE_PROJECT_NAME} "${OBS_FRONTEND_LIB}")
  153. endif()
  154. # -- End of section --