buildspec.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # OBS CMake macOS build dependencies module
  2. # cmake-format: off
  3. # cmake-lint: disable=E1126
  4. # cmake-lint: disable=R0912
  5. # cmake-lint: disable=R0915
  6. # cmake-format: on
  7. # _check_deps_version: Checks for obs-deps VERSION file in prefix paths
  8. macro(_check_deps_version version)
  9. set(found FALSE)
  10. foreach(path IN LISTS CMAKE_PREFIX_PATH)
  11. if(EXISTS "${path}/share/obs-deps/VERSION")
  12. if(dependency STREQUAL qt6 AND NOT EXISTS "${path}/lib/cmake/Qt6/Qt6Config.cmake")
  13. set(found FALSE)
  14. continue()
  15. endif()
  16. file(READ "${path}/share/obs-deps/VERSION" _check_version)
  17. string(REPLACE "\n" "" _check_version "${_check_version}")
  18. string(REPLACE "-" "." _check_version "${_check_version}")
  19. string(REPLACE "-" "." version "${version}")
  20. if(_check_version VERSION_EQUAL version)
  21. set(found TRUE)
  22. break()
  23. elseif(_check_version VERSION_LESS version)
  24. message(AUTHOR_WARNING "Outdated ${label} version detected in ${path}: \n"
  25. "Found ${_check_version}, require ${version}")
  26. list(REMOVE_ITEM CMAKE_PREFIX_PATH "${path}")
  27. list(APPEND CMAKE_PREFIX_PATH "${path}")
  28. continue()
  29. else()
  30. message(AUTHOR_WARNING "Future ${label} version detected in ${path}: \n"
  31. "Found ${_check_version}, require ${version}")
  32. set(found TRUE)
  33. break()
  34. endif()
  35. endif()
  36. endforeach()
  37. endmacro()
  38. # _check_dependencies: Fetch and extract pre-built OBS build dependencies
  39. function(_check_dependencies)
  40. if(CMAKE_OSX_ARCHITECTURES MATCHES ".+;.+")
  41. set(arch universal)
  42. else()
  43. set(arch ${CMAKE_OSX_ARCHITECTURES})
  44. endif()
  45. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec)
  46. # cmake-format: off
  47. string(JSON deployment_target GET ${buildspec} platformConfig macos-${arch} deploymentTarget)
  48. string(JSON dependency_data GET ${buildspec} dependencies)
  49. # cmake-format: on
  50. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  51. set(CMAKE_OSX_DEPLOYMENT_TARGET
  52. ${_deployment_target}
  53. CACHE STRING "Minimum macOS version to target for deployment (at runtime). Newer APIs will be weak-linked."
  54. FORCE)
  55. endif()
  56. set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps")
  57. set(prebuilt_filename "macos-deps-VERSION-ARCH-REVISION.tar.xz")
  58. set(prebuilt_destination "obs-deps-VERSION-ARCH")
  59. set(qt6_filename "macos-deps-qt6-VERSION-ARCH-REVISION.tar.xz")
  60. set(qt6_destination "obs-deps-qt6-VERSION-ARCH")
  61. set(cef_filename "cef_binary_VERSION_macos_ARCH_REVISION.tar.xz")
  62. set(cef_destination "cef_binary_VERSION_macos_ARCH")
  63. foreach(dependency IN ITEMS prebuilt qt6 cef)
  64. if(dependency STREQUAL cef AND arch STREQUAL universal)
  65. continue()
  66. endif()
  67. # cmake-format: off
  68. string(JSON data GET ${dependency_data} ${dependency})
  69. string(JSON version GET ${data} version)
  70. string(JSON hash GET ${data} hashes macos-${arch})
  71. string(JSON url GET ${data} baseUrl)
  72. string(JSON label GET ${data} label)
  73. string(JSON revision ERROR_VARIABLE error GET ${data} revision macos-${arch})
  74. # cmake-format: on
  75. message(STATUS "Setting up ${label}")
  76. set(file "${${dependency}_filename}")
  77. set(destination "${${dependency}_destination}")
  78. string(REPLACE "VERSION" "${version}" file "${file}")
  79. string(REPLACE "VERSION" "${version}" destination "${destination}")
  80. string(REPLACE "ARCH" "${arch}" file "${file}")
  81. string(REPLACE "ARCH" "${arch}" destination "${destination}")
  82. if(revision)
  83. string(REPLACE "_REVISION" "_v${revision}" file "${file}")
  84. string(REPLACE "-REVISION" "-v${revision}" file "${file}")
  85. else()
  86. string(REPLACE "_REVISION" "" file "${file}")
  87. string(REPLACE "-REVISION" "" file "${file}")
  88. endif()
  89. set(skip FALSE)
  90. if(dependency STREQUAL prebuilt OR dependency STREQUAL qt6)
  91. _check_deps_version(${version})
  92. if(found)
  93. set(skip TRUE)
  94. endif()
  95. elseif(_dependency STREQUAL sparkle)
  96. find_library(SPARKLE Sparkle)
  97. if(NOT ENABLE_SPARKLE OR SPARKLE)
  98. set(skip TRUE)
  99. else()
  100. unset(SPARKLE CACHE)
  101. endif()
  102. elseif(dependency STREQUAL vlc)
  103. if(NOT ENABLE_VLC OR (VLC_PATH AND EXISTS "${VLC_PATH}"))
  104. set(skip TRUE)
  105. endif()
  106. elseif(dependency STREQUAL cef)
  107. if(NOT ENABLE_BROWSER OR (CEF_ROOT_DIR AND EXISTS "${CEF_ROOT_DIR}"))
  108. set(skip TRUE)
  109. endif()
  110. endif()
  111. if(skip)
  112. message(STATUS "Setting up ${label} - skipped")
  113. continue()
  114. endif()
  115. if(dependency STREQUAL qt6 AND "$ENV{CI}")
  116. # cmake-format: off
  117. string(JSON hash GET ${buildspec} dependencies qt6 hashes macos-universal)
  118. # cmake-format: on
  119. string(REPLACE "${arch}" "universal" file "${file}")
  120. endif()
  121. if(dependency STREQUAL cef)
  122. set(url ${url}/${file})
  123. else()
  124. set(url ${url}/${version}/${file})
  125. endif()
  126. if(NOT EXISTS "${dependencies_dir}/${file}")
  127. message(STATUS "Downloading ${url}")
  128. file(
  129. DOWNLOAD "${url}" "${dependencies_dir}/${file}"
  130. STATUS download_status
  131. EXPECTED_HASH SHA256=${hash})
  132. list(GET download_status 0 error_code)
  133. list(GET download_status 1 error_message)
  134. if(error_code GREATER 0)
  135. message(STATUS "Downloading ${url} - Failure")
  136. message(FATAL_ERROR "Unable to download ${url}, failed with error: ${error_message}")
  137. file(REMOVE "${dependencies_dir}/${file}")
  138. else()
  139. message(STATUS "Downloading ${url} - done")
  140. endif()
  141. endif()
  142. if(NOT EXISTS "${dependencies_dir}/${destination}")
  143. file(MAKE_DIRECTORY "${dependencies_dir}/${destination}")
  144. if(dependency STREQUAL vlc)
  145. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}")
  146. else()
  147. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}/${destination}")
  148. endif()
  149. execute_process(COMMAND "xattr" -r -d com.apple.quarantine "${dependencies_dir}/${destination}"
  150. RESULT_VARIABLE result COMMAND_ERROR_IS_FATAL ANY)
  151. endif()
  152. if(dependency STREQUAL cef)
  153. set(CEF_ROOT_DIR
  154. "${dependencies_dir}/${destination}"
  155. CACHE PATH "CEF Root directory" FORCE)
  156. elseif(dependency STREQUAL prebuilt)
  157. set(VLC_PATH
  158. "${dependencies_dir}/${destination}"
  159. CACHE PATH "VLC source code directory" FORCE)
  160. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  161. elseif(dependency STREQUAL qt6)
  162. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  163. endif()
  164. message(STATUS "Setting up ${label} - done")
  165. endforeach()
  166. list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
  167. set(CMAKE_PREFIX_PATH
  168. ${CMAKE_PREFIX_PATH}
  169. CACHE PATH "CMake prefix search path" FORCE)
  170. endfunction()
  171. _check_dependencies()