FetchDependencies.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. set(DEP_DIR ${CMAKE_BINARY_DIR}/dependencies)
  2. if(APPLE)
  3. set(OS "darwin")
  4. elseif(WIN32)
  5. set(OS "windows")
  6. elseif(UNIX)
  7. set(OS "linux")
  8. endif()
  9. # note that hardcoding the ARCH here is not correct.
  10. set(ARCHSTR "${OS}-x86_64")
  11. function(download_deps depname dirpath dephash)
  12. file(MAKE_DIRECTORY ${DEP_DIR})
  13. message(STATUS "Downloading ${depname}.hash.txt...")
  14. file(
  15. DOWNLOAD "https://nightlies.plex.tv/directdl/plex-dependencies/${depname}/latest/hash.txt" ${DEP_DIR}/${depname}-hash.txt
  16. STATUS HASH_STATUS
  17. )
  18. list(GET HASH_STATUS 0 SUCCESS)
  19. if(SUCCESS EQUAL 0)
  20. file(STRINGS ${DEP_DIR}/${depname}-hash.txt DEP_HASH LIMIT_COUNT 1)
  21. if(depname STREQUAL plexmediaplayer-qt)
  22. set(DEP_DIRNAME "konvergo-qt-${ARCHSTR}-release-${DEP_HASH}")
  23. elseif(depname STREQUAL plexmediaplayer-dependencies)
  24. set(DEP_DIRNAME "konvergo-depends-${ARCHSTR}-release-${DEP_HASH}")
  25. elseif(depname STREQUAL plexmediaplayer-windows-dependencies)
  26. set(ARCHSTR "mingw32-x86_64")
  27. set(DEP_DIRNAME "konvergo-depends-windows-${ARCHSTR}-release-${DEP_HASH}")
  28. else()
  29. set(DEP_DIRNAME "${depname}-${ARCHSTR}-release-${DEP_HASH}")
  30. endif()
  31. set(DEP_FILENAME ${DEP_DIRNAME}.tbz2)
  32. set(DEP_URL "https://nightlies.plex.tv/directdl/plex-dependencies/${depname}/latest/${DEP_FILENAME}")
  33. set(${dirpath} ${DEP_DIR}/${DEP_DIRNAME} PARENT_SCOPE)
  34. set(${dephash} ${DEP_HASH} PARENT_SCOPE)
  35. if(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  36. message(STATUS "Downloading ${DEP_FILENAME}.sha.txt...")
  37. file(DOWNLOAD ${DEP_URL}.sha.txt ${DEP_DIR}/${DEP_FILENAME}.sha.txt STATUS SHA_STATUS)
  38. list(GET SHA_STATUS 0 SHASUCCESS)
  39. if(SHASUCCESS EQUAL 0)
  40. file(STRINGS ${DEP_DIR}/${DEP_FILENAME}.sha.txt CONTENT_HASH_RAW LIMIT_COUNT 1)
  41. string(SUBSTRING ${CONTENT_HASH_RAW} 0 40 CONTENT_HASH)
  42. message(STATUS "Downloading ${DEP_FILENAME}...")
  43. file(
  44. DOWNLOAD ${DEP_URL} ${DEP_DIR}/${DEP_FILENAME}
  45. EXPECTED_HASH SHA1=${CONTENT_HASH}
  46. SHOW_PROGRESS
  47. STATUS DEP_STATUS
  48. )
  49. list(GET DEP_STATUS 0 DEP_SUCCESS)
  50. if(NOT DEP_SUCCESS EQUAL 0)
  51. message(FATAL_ERROR "Failed to download ${DEP_URL}")
  52. endif()
  53. if(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  54. message(STATUS "Unpacking ${DEP_FILENAME}...")
  55. execute_process(
  56. COMMAND ${CMAKE_COMMAND} -E tar xjf ${DEP_DIR}/${DEP_FILENAME}
  57. WORKING_DIRECTORY ${DEP_DIR}
  58. )
  59. if(APPLE)
  60. message(STATUS "Fixing install library names...")
  61. execute_process(
  62. COMMAND ${PROJECT_SOURCE_DIR}/scripts/fix-install-names.py ${DEP_DIR}/${DEP_DIRNAME}
  63. WORKING_DIRECTORY ${DEP_DIR}
  64. )
  65. message(STATUS "Done")
  66. endif(APPLE)
  67. if(WIN32 AND EXISTS ${DEP_DIR}/${DEP_DIRNAME}/bin/mpv-1.def)
  68. message(STATUS "Fixing mpv.lib...")
  69. execute_process(
  70. COMMAND LIB /def:bin\\mpv-1.def /out:lib\\mpv.lib /MACHINE:X64
  71. WORKING_DIRECTORY ${DEP_DIR}/${DEP_DIRNAME}
  72. )
  73. endif(WIN32 AND EXISTS ${DEP_DIR}/${DEP_DIRNAME}/bin/mpv-1.def)
  74. endif()
  75. else(SHASUCCESS EQUAL 0)
  76. list(GET SHA_STATUS 1 SHAERROR)
  77. message(FATAL_ERROR "Failed to download ${DEP_FILENAME}.sha.txt error: ${SHAERROR}")
  78. endif(SHASUCCESS EQUAL 0)
  79. else(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  80. message(STATUS "Directory ${DEP_DIR}/${DEP_DIRNAME} already exists, remove it to redownload")
  81. endif(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  82. else(SUCCESS EQUAL 0)
  83. list(GET HASH_STATUS 1 HASHERROR)
  84. message(FATAL_ERROR "Failed to download ${depname}.hash.txt error: ${HASHERROR}")
  85. endif(SUCCESS EQUAL 0)
  86. endfunction(download_deps depname)