buildspec_common.cmake 5.9 KB

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