FetchDependencies.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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)
  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. if(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  35. message(STATUS "Downloading ${DEP_FILENAME}.sha.txt...")
  36. file(DOWNLOAD ${DEP_URL}.sha.txt ${DEP_DIR}/${DEP_FILENAME}.sha.txt STATUS SHA_STATUS)
  37. list(GET SHA_STATUS 0 SHASUCCESS)
  38. if(SHASUCCESS EQUAL 0)
  39. file(STRINGS ${DEP_DIR}/${DEP_FILENAME}.sha.txt CONTENT_HASH_RAW LIMIT_COUNT 1)
  40. string(SUBSTRING ${CONTENT_HASH_RAW} 0 40 CONTENT_HASH)
  41. message(STATUS "Downloading ${DEP_FILENAME}...")
  42. file(
  43. DOWNLOAD ${DEP_URL} ${DEP_DIR}/${DEP_FILENAME}
  44. EXPECTED_HASH SHA1=${CONTENT_HASH}
  45. SHOW_PROGRESS
  46. STATUS DEP_STATUS
  47. )
  48. list(GET DEP_STATUS 0 DEP_SUCCESS)
  49. if(NOT DEP_SUCCESS EQUAL 0)
  50. message(FATAL_ERROR "Failed to download ${DEP_URL}")
  51. endif()
  52. if(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  53. message(STATUS "Unpacking ${DEP_FILENAME}...")
  54. execute_process(
  55. COMMAND ${CMAKE_COMMAND} -E tar xjf ${DEP_DIR}/${DEP_FILENAME}
  56. WORKING_DIRECTORY ${DEP_DIR}
  57. )
  58. if(APPLE)
  59. message(STATUS "Fixing install library names...")
  60. execute_process(
  61. COMMAND ${PROJECT_SOURCE_DIR}/scripts/fix-install-names.py ${DEP_DIR}/${DEP_DIRNAME}
  62. WORKING_DIRECTORY ${DEP_DIR}
  63. )
  64. message(STATUS "Done")
  65. endif(APPLE)
  66. if(WIN32 AND EXISTS ${DEP_DIR}/${DEP_DIRNAME}/bin/mpv-1.def)
  67. message(STATUS "Fixing mpv.lib...")
  68. execute_process(
  69. COMMAND LIB /def:bin\\mpv-1.def /out:lib\\mpv.lib /MACHINE:X64
  70. WORKING_DIRECTORY ${DEP_DIR}/${DEP_DIRNAME}
  71. )
  72. endif(WIN32 AND EXISTS ${DEP_DIR}/${DEP_DIRNAME}/bin/mpv-1.def)
  73. endif()
  74. else(SHASUCCESS EQUAL 0)
  75. list(GET SHA_STATUS 1 SHAERROR)
  76. message(FATAL_ERROR "Failed to download ${DEP_FILENAME}.sha.txt error: ${SHAERROR}")
  77. endif(SHASUCCESS EQUAL 0)
  78. else(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  79. message(STATUS "Directory ${DEP_DIR}/${DEP_DIRNAME} already exists, remove it to redownload")
  80. endif(NOT EXISTS ${DEP_DIR}/${DEP_DIRNAME})
  81. else(SUCCESS EQUAL 0)
  82. list(GET HASH_STATUS 1 HASHERROR)
  83. message(FATAL_ERROR "Failed to download ${depname}.hash.txt error: ${HASHERROR}")
  84. endif(SUCCESS EQUAL 0)
  85. endfunction(download_deps depname)