buildspec_common.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
  28. continue()
  29. else()
  30. message(
  31. AUTHOR_WARNING
  32. "Newer ${label} version detected in ${path}: \n"
  33. "Found ${_check_version}, require ${version}"
  34. )
  35. set(found TRUE PARENT_SCOPE)
  36. break()
  37. endif()
  38. endif()
  39. endforeach()
  40. endfunction()
  41. # _check_dependencies: Fetch and extract pre-built OBS build dependencies
  42. function(_check_dependencies)
  43. file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec)
  44. string(JSON dependency_data GET ${buildspec} dependencies)
  45. foreach(dependency IN LISTS dependencies_list)
  46. if(dependency STREQUAL cef AND arch STREQUAL universal)
  47. if(CMAKE_OSX_ARCHITECTURES MATCHES ".+;.+")
  48. continue()
  49. endif()
  50. set(arch ${CMAKE_OSX_ARCHITECTURES})
  51. set(platform macos-${arch})
  52. endif()
  53. string(JSON data GET ${dependency_data} ${dependency})
  54. string(JSON version GET ${data} version)
  55. string(JSON hash GET ${data} hashes ${platform})
  56. string(JSON url GET ${data} baseUrl)
  57. string(JSON label GET ${data} label)
  58. string(JSON revision ERROR_VARIABLE error GET ${data} revision ${platform})
  59. message(STATUS "Setting up ${label} (${arch})")
  60. set(file "${${dependency}_filename}")
  61. set(destination "${${dependency}_destination}")
  62. string(REPLACE "VERSION" "${version}" file "${file}")
  63. string(REPLACE "VERSION" "${version}" destination "${destination}")
  64. string(REPLACE "ARCH" "${arch}" file "${file}")
  65. string(REPLACE "ARCH" "${arch}" destination "${destination}")
  66. if(revision)
  67. string(REPLACE "_REVISION" "_v${revision}" file "${file}")
  68. string(REPLACE "-REVISION" "-v${revision}" file "${file}")
  69. else()
  70. string(REPLACE "_REVISION" "" file "${file}")
  71. string(REPLACE "-REVISION" "" file "${file}")
  72. endif()
  73. if(EXISTS "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256")
  74. file(
  75. READ
  76. "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256"
  77. OBS_DEPENDENCY_${dependency}_${arch}_HASH
  78. )
  79. endif()
  80. set(skip FALSE)
  81. if(dependency STREQUAL prebuilt OR dependency STREQUAL qt6)
  82. if(OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash})
  83. _check_deps_version(${version})
  84. if(found)
  85. set(skip TRUE)
  86. endif()
  87. endif()
  88. elseif(dependency STREQUAL cef)
  89. if(NOT ENABLE_BROWSER)
  90. set(skip TRUE)
  91. elseif(OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash} AND (CEF_ROOT_DIR AND EXISTS "${CEF_ROOT_DIR}"))
  92. set(skip TRUE)
  93. endif()
  94. endif()
  95. if(skip)
  96. message(STATUS "Setting up ${label} (${arch}) - skipped")
  97. continue()
  98. endif()
  99. if(dependency STREQUAL cef)
  100. set(url ${url}/${file})
  101. else()
  102. set(url ${url}/${version}/${file})
  103. endif()
  104. if(NOT EXISTS "${dependencies_dir}/${file}")
  105. message(STATUS "Downloading ${url}")
  106. file(DOWNLOAD "${url}" "${dependencies_dir}/${file}" STATUS download_status EXPECTED_HASH SHA256=${hash})
  107. list(GET download_status 0 error_code)
  108. list(GET download_status 1 error_message)
  109. if(error_code GREATER 0)
  110. message(STATUS "Downloading ${url} - Failure")
  111. message(FATAL_ERROR "Unable to download ${url}, failed with error: ${error_message}")
  112. file(REMOVE "${dependencies_dir}/${file}")
  113. else()
  114. message(STATUS "Downloading ${url} - done")
  115. endif()
  116. endif()
  117. if(NOT OBS_DEPENDENCY_${dependency}_${arch}_HASH STREQUAL ${hash})
  118. file(REMOVE_RECURSE "${dependencies_dir}/${destination}")
  119. endif()
  120. if(NOT EXISTS "${dependencies_dir}/${destination}")
  121. file(MAKE_DIRECTORY "${dependencies_dir}/${destination}")
  122. if(dependency STREQUAL obs-studio)
  123. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}")
  124. else()
  125. file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}/${destination}")
  126. endif()
  127. endif()
  128. file(WRITE "${dependencies_dir}/.dependency_${dependency}_${arch}.sha256" "${hash}")
  129. if(dependency STREQUAL prebuilt)
  130. set(VLC_PATH "${dependencies_dir}/${destination}" CACHE PATH "VLC source code directory" FORCE)
  131. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  132. elseif(dependency STREQUAL qt6)
  133. list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
  134. elseif(dependency STREQUAL cef)
  135. set(CEF_ROOT_DIR "${dependencies_dir}/${destination}" CACHE PATH "CEF root directory" FORCE)
  136. endif()
  137. message(STATUS "Setting up ${label} (${arch}) - done")
  138. endforeach()
  139. list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
  140. set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} CACHE PATH "CMake prefix search path" FORCE)
  141. endfunction()