buildspec_common.cmake 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # OBS common build dependencies module
  2. include_guard(GLOBAL)
  3. # _check_deps_version: Checks for obs-deps VERSION file in prefix paths
  4. function(_check_deps_version version)
  5. set(found FALSE PARENT_SCOPE)
  6. foreach(path IN LISTS CMAKE_PREFIX_PATH)
  7. if(EXISTS "${path}/share/obs-deps/VERSION")
  8. if(dependency STREQUAL qt6 AND NOT EXISTS "${path}/lib/cmake/Qt6/Qt6Config.cmake")
  9. set(found FALSE PARENT_SCOPE)
  10. continue()
  11. endif()
  12. file(READ "${path}/share/obs-deps/VERSION" _check_version)
  13. string(REPLACE "\n" "" _check_version "${_check_version}")
  14. string(REPLACE "-" "." _check_version "${_check_version}")
  15. string(REPLACE "-" "." version "${version}")
  16. if(_check_version VERSION_EQUAL version)
  17. set(found TRUE PARENT_SCOPE)
  18. break()
  19. elseif(_check_version VERSION_LESS version)
  20. message(
  21. AUTHOR_WARNING
  22. "Older ${label} version detected in ${path}: \n"
  23. "Found ${_check_version}, require ${version}"
  24. )
  25. list(REMOVE_ITEM CMAKE_PREFIX_PATH "${path}")
  26. list(APPEND CMAKE_PREFIX_PATH "${path}")
  27. continue()
  28. else()
  29. message(
  30. AUTHOR_WARNING
  31. "Newer ${label} version detected in ${path}: \n"
  32. "Found ${_check_version}, require ${version}"
  33. )
  34. set(found TRUE PARENT_SCOPE)
  35. break()
  36. endif()
  37. endif()
  38. endforeach()
  39. return(PROPAGATE found CMAKE_PREFIX_PATH)
  40. endfunction()
  41. function(_get_dependency_data variable_name)
  42. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/CMakePresets.json" preset_data)
  43. string(JSON configure_presets GET ${preset_data} "configurePresets")
  44. string(JSON preset_count LENGTH "${configure_presets}")
  45. math(EXPR preset_count "${preset_count}-1")
  46. foreach(index RANGE 0 ${preset_count})
  47. string(JSON preset_member_data GET "${configure_presets}" ${index})
  48. string(JSON preset_name GET ${preset_member_data} "name")
  49. if(preset_name STREQUAL dependencies)
  50. string(JSON vendor_data GET ${preset_member_data} "vendor")
  51. string(JSON vendor_data GET ${vendor_data} "obsproject.com/obs-studio")
  52. string(JSON dependency_data GET ${vendor_data} "dependencies")
  53. break()
  54. else()
  55. continue()
  56. endif()
  57. endforeach()
  58. set(${variable_name} "${dependency_data}")
  59. return(PROPAGATE ${variable_name})
  60. endfunction()
  61. # _check_dependencies: Fetch and extract pre-built OBS build dependencies
  62. function(_check_dependencies)
  63. set(dependencies_list ${ARGV})
  64. _get_dependency_data(dependency_data)
  65. foreach(dependency IN LISTS dependencies_list)
  66. if(dependency STREQUAL cef AND NOT ENABLE_BROWSER)
  67. continue()
  68. endif()
  69. if(dependency STREQUAL cef AND arch STREQUAL universal)
  70. if(CMAKE_OSX_ARCHITECTURES MATCHES ".+;.+")
  71. continue()
  72. elseif(CMAKE_OSX_ARCHITECTURES MATCHES "(arm64|x86_64)")
  73. set(arch ${CMAKE_OSX_ARCHITECTURES})
  74. else()
  75. set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})
  76. endif()
  77. set(platform macos-${arch})
  78. endif()
  79. string(JSON data GET ${dependency_data} ${dependency})
  80. string(JSON version GET ${data} version)
  81. string(JSON hash GET ${data} hashes ${platform})
  82. string(JSON url GET ${data} baseUrl)
  83. string(JSON label GET ${data} label)
  84. string(JSON revision ERROR_VARIABLE error GET ${data} revision ${platform})
  85. message(STATUS "Setting up ${label} (${arch})")
  86. set(file "${${dependency}_filename}")
  87. set(destination "${${dependency}_destination}")
  88. string(REPLACE "VERSION" "${version}" file "${file}")
  89. string(REPLACE "VERSION" "${version}" destination "${destination}")
  90. string(REPLACE "ARCH" "${arch}" file "${file}")
  91. string(REPLACE "ARCH" "${arch}" destination "${destination}")
  92. if(revision)
  93. string(REPLACE "_REVISION" "_v${revision}" file "${file}")
  94. string(REPLACE "-REVISION" "-v${revision}" file "${file}")
  95. else()
  96. string(REPLACE "_REVISION" "" file "${file}")
  97. string(REPLACE "-REVISION" "" file "${file}")
  98. endif()
  99. if(EXISTS "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256")
  100. file(
  101. READ "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256"
  102. OBS_DEPENDENCY_${dependency}_${arch}_HASH
  103. )
  104. endif()
  105. set(skip FALSE)
  106. if(dependency STREQUAL prebuilt OR dependency STREQUAL qt6)
  107. if(OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash})
  108. _check_deps_version(${version})
  109. if(found)
  110. set(skip TRUE)
  111. endif()
  112. endif()
  113. elseif(dependency STREQUAL cef)
  114. if(NOT ENABLE_BROWSER)
  115. set(skip TRUE)
  116. elseif(OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash} AND (CEF_ROOT_DIR AND EXISTS "${CEF_ROOT_DIR}"))
  117. set(skip TRUE)
  118. endif()
  119. endif()
  120. if(skip)
  121. message(STATUS "Setting up ${label} (${arch}) - skipped")
  122. continue()
  123. endif()
  124. if(dependency STREQUAL cef)
  125. set(url ${url}/${file})
  126. else()
  127. set(url ${url}/${version}/${file})
  128. endif()
  129. if(NOT EXISTS "${dependencies_dir}/${file}")
  130. message(STATUS "Downloading ${url}")
  131. file(DOWNLOAD "${url}" "${dependencies_dir}/${file}" STATUS download_status 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 OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash})
  143. file(REMOVE_RECURSE "${dependencies_dir}/${destination}")
  144. endif()
  145. if(NOT EXISTS "${dependencies_dir}/${destination}")
  146. file(MAKE_DIRECTORY "${dependencies_dir}/${destination}")
  147. if(dependency STREQUAL obs-studio)
  148. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}")
  149. else()
  150. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}/${destination}")
  151. endif()
  152. endif()
  153. file(WRITE "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256" "${hash}")
  154. if(dependency STREQUAL prebuilt)
  155. set(VLC_PATH "${dependencies_dir}/${destination}" CACHE PATH "VLC source code directory" FORCE)
  156. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  157. elseif(dependency STREQUAL qt6)
  158. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  159. elseif(dependency STREQUAL cef)
  160. set(CEF_ROOT_DIR "${dependencies_dir}/${destination}" CACHE PATH "CEF root directory" FORCE)
  161. endif()
  162. message(STATUS "Setting up ${label} (${arch}) - done")
  163. endforeach()
  164. list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
  165. set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE PATH "CMake prefix search path" FORCE)
  166. endfunction()