Schematic editor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Win32Depends.cmake 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # Usage: cmake -P Win32Depends.cmake
  2. # Only CMake 3.1+ supports XZ archives and 7z doesn't also untar automatically
  3. cmake_minimum_required (VERSION 3.1)
  4. # Directories
  5. set (working_dir ${CMAKE_CURRENT_BINARY_DIR}/win32-depends)
  6. set (pkg_dir ${working_dir}/packages)
  7. set (tools_dir ${working_dir}/tools)
  8. set (sevenzip_executable ${tools_dir}/7za)
  9. set (tmp_dir ${working_dir}/tmp)
  10. file (MAKE_DIRECTORY ${working_dir})
  11. file (MAKE_DIRECTORY ${pkg_dir})
  12. # Cleanup
  13. message (STATUS "Cleaning up...")
  14. file (GLOB files ${working_dir}/*)
  15. list (REMOVE_ITEM files ${pkg_dir})
  16. if (files)
  17. file (REMOVE_RECURSE ${files})
  18. endif (files)
  19. # Packages
  20. set (pkg_list "7za" "gtk" "gtkalt" "winlibs" "mingw_lua")
  21. set (pkg_7za_root "http://sourceforge.net/projects/sevenzip/files")
  22. set (pkg_7za_urls "${pkg_7za_root}/7-Zip/9.20/7za920.zip")
  23. set (pkg_7za_md5 "2fac454a90ae96021f4ffc607d4c00f8")
  24. set (pkg_gtk_root "http://ftp.gnome.org/pub/gnome/binaries/win32")
  25. set (pkg_gtk_urls "${pkg_gtk_root}/dependencies/gettext-tools-0.17.zip")
  26. set (pkg_gtk_md5 "09baff956ebd1c391c7f71e9bd768edd")
  27. set (pkg_gtkalt_root "http://win32builder.gnome.org")
  28. set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.8.2-20131001_win32.zip")
  29. set (pkg_gtkalt_md5 "3f9b159207edf44937f209b4a5e6bb63")
  30. # Doesn't work, no gtk+-3.0.pc file present
  31. #set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.10.4-20131202_win32.zip")
  32. #set (pkg_gtkalt_md5 "520bed70943974efdaeea2a1dbe48f84")
  33. # Too old
  34. #set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.6.4-20130921_win32.zip")
  35. #set (pkg_gtkalt_md5 "9bcb87d917982a6e52a69141ade8bd56")
  36. set (pkg_winlibs_root "http://sourceforge.net/projects/winlibs/files")
  37. set (pkg_winlibs_urls "${pkg_winlibs_root}/GTK+/libjson-glib-1.0-1-mingw32.7z")
  38. set (pkg_winlibs_md5 "f06e42c5998dae5fb6245fecc96a403e")
  39. set (pkg_mingw_lua_root "http://sourceforge.net/projects/mingw/files/MinGW/Extension")
  40. set (pkg_mingw_lua_urls
  41. "${pkg_mingw_lua_root}/lua/lua-5.2.0-1/lua-5.2.0-1-mingw32-dll-52.tar.xz"
  42. "${pkg_mingw_lua_root}/lua/lua-5.2.0-1/lua-5.2.0-1-mingw32-dev.tar.xz")
  43. set (pkg_mingw_lua_md5
  44. "150b27cab05b78ba40bbd7225630c00d"
  45. "6abe77c1e1a783075fe73c53b7c235fb")
  46. # Stage 1: fetch missing packages
  47. foreach (pkg_set ${pkg_list})
  48. set (pkg_md5 ${pkg_${pkg_set}_md5})
  49. foreach (url ${pkg_${pkg_set}_urls})
  50. get_filename_component (basename ${url} NAME)
  51. set (filename ${pkg_dir}/${basename})
  52. if (NOT pkg_md5)
  53. message (WARNING "MD5 checksum missing for ${basename}")
  54. set (pkg_md5_sum)
  55. set (pkg_md5_param)
  56. else (NOT pkg_md5)
  57. list (GET pkg_md5 0 pkg_md5_sum)
  58. list (REMOVE_AT pkg_md5 0)
  59. set (pkg_md5_param EXPECTED_MD5 ${pkg_md5_sum})
  60. endif (NOT pkg_md5)
  61. if (NOT EXISTS ${filename})
  62. message (STATUS "Downloading ${url}...")
  63. file (DOWNLOAD ${url} ${filename} STATUS status ${pkg_md5_param})
  64. list (GET status 0 status_errno)
  65. list (GET status 1 status_msg)
  66. if (status_errno)
  67. file (REMOVE ${filename})
  68. message (FATAL_ERROR "Download failed: ${status_msg}")
  69. endif (status_errno)
  70. elseif (pkg_md5_sum)
  71. execute_process (COMMAND ${CMAKE_COMMAND} -E md5sum ${filename}
  72. OUTPUT_VARIABLE output)
  73. if (NOT output MATCHES "^${pkg_md5_sum}")
  74. message (FATAL_ERROR "MD5 mismatch for ${basename}")
  75. endif (NOT output MATCHES "^${pkg_md5_sum}")
  76. endif (NOT EXISTS ${filename})
  77. endforeach (url)
  78. endforeach (pkg_set)
  79. if (NOT WIN32)
  80. unset (sevenzip_executable)
  81. find_program (sevenzip_executable 7za)
  82. if (NOT sevenzip_executable)
  83. message (FATAL_ERROR "Could not find 7za (part of p7zip)")
  84. endif (NOT sevenzip_executable)
  85. endif (NOT WIN32)
  86. # Stage 2: setup 7za first
  87. file (MAKE_DIRECTORY ${tmp_dir})
  88. foreach (url ${pkg_7za_urls})
  89. get_filename_component (filename ${url} NAME)
  90. message (STATUS "Extracting ${filename}...")
  91. set (filename ${pkg_dir}/${filename})
  92. execute_process (COMMAND ${CMAKE_COMMAND} -E tar xf ${filename}
  93. WORKING_DIRECTORY ${tmp_dir}
  94. RESULT_VARIABLE status)
  95. if (status)
  96. message (FATAL_ERROR "Extraction failed: ${status}")
  97. endif (status)
  98. endforeach (url)
  99. file (MAKE_DIRECTORY ${tools_dir})
  100. file (COPY ${tmp_dir}/7za.exe DESTINATION ${tools_dir})
  101. file (REMOVE_RECURSE ${tmp_dir})
  102. list (REMOVE_ITEM pkg_list "7za")
  103. # Stage 3: extract the rest of packages
  104. foreach (pkg_set ${pkg_list})
  105. foreach (url ${pkg_${pkg_set}_urls})
  106. get_filename_component (filename ${url} NAME)
  107. message (STATUS "Extracting ${filename}...")
  108. if (filename MATCHES "\\.7z$")
  109. set (extract_command ${sevenzip_executable} x)
  110. set (quiet OUTPUT_QUIET)
  111. else (filename MATCHES "\\.7z$")
  112. set (extract_command ${CMAKE_COMMAND} -E tar xf)
  113. set (quiet)
  114. endif (filename MATCHES "\\.7z$")
  115. set (filename ${pkg_dir}/${filename})
  116. if (pkg_${pkg_set}_strip)
  117. file (MAKE_DIRECTORY ${tmp_dir})
  118. execute_process (COMMAND ${extract_command} ${filename}
  119. WORKING_DIRECTORY ${tmp_dir}
  120. RESULT_VARIABLE status ${quiet})
  121. file (COPY ${tmp_dir}/${pkg_${pkg_set}_strip}/
  122. DESTINATION ${working_dir})
  123. file (REMOVE_RECURSE ${tmp_dir})
  124. else (pkg_${pkg_set}_strip)
  125. execute_process (COMMAND ${extract_command} ${filename}
  126. WORKING_DIRECTORY ${working_dir}
  127. RESULT_VARIABLE status ${quiet})
  128. endif (pkg_${pkg_set}_strip)
  129. if (status)
  130. message (FATAL_ERROR "Extraction failed: ${status}")
  131. endif (status)
  132. endforeach (url)
  133. endforeach (pkg_set)
  134. # Stage 4: final touches
  135. # We have to fix the prefix path as it is completely wrong everywhere
  136. file (GLOB files ${working_dir}/lib/pkgconfig/*.pc)
  137. foreach (file ${files})
  138. message (STATUS "Fixing ${file}...")
  139. file (READ ${file} file_content)
  140. string (REGEX REPLACE "prefix=[^\r\n]*(.*)" "prefix=${working_dir}\\1"
  141. file_content_fixed "${file_content}")
  142. file (WRITE ${file} "${file_content_fixed}")
  143. endforeach (file)