slic3r-makedeps.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!powershell
  2. #
  3. # This script downloads, configures and builds Slic3r PE dependencies for Unix.
  4. # (That is, all dependencies except perl + wxWidgets.)
  5. #
  6. # To use this script, launch the Visual Studio command line,
  7. # `cd` into the directory containing this script and use this command:
  8. #
  9. # powershell .\slic3r-makedeps.ps1
  10. #
  11. # The dependencies will be downloaded and unpacked into the current dir.
  12. # This script WILL NOT try to guess the build architecture (64 vs 32 bits),
  13. # it will by default build the 64-bit variant. To build the 32-bit variant, use:
  14. #
  15. # powershell .\slic3r-makedeps.ps1 -b32
  16. #
  17. # Built libraries are installed into $destdir,
  18. # which by default is C:\local\slic3r-destdir-$bits
  19. # You can customize the $destdir using:
  20. #
  21. # powershell .\slic3r-makedeps.ps1 -destdir C:\foo\bar
  22. #
  23. # To pass the $destdir path along to cmake, set the use CMAKE_PREFIX_PATH variable
  24. # and set it to $destdir\usr\local
  25. #
  26. # Script requirements: PowerShell 3.0, .NET 4.5
  27. #
  28. param(
  29. [switch]$b32 = $false,
  30. [string]$destdir = ""
  31. )
  32. if ($destdir -eq "") {
  33. $destdir = "C:\local\slic3r-destdir-" + ('32', '64')[!$b32]
  34. }
  35. $BOOST = 'boost_1_63_0'
  36. $CURL = 'curl-7.58.0'
  37. $TBB_SHA = 'a0dc9bf76d0120f917b641ed095360448cabc85b'
  38. $TBB = "tbb-$TBB_SHA"
  39. try
  40. {
  41. # Set up various settings and utilities:
  42. [Environment]::CurrentDirectory = Get-Location
  43. $NPROC = (Get-WmiObject -class Win32_processor).NumberOfLogicalProcessors
  44. Add-Type -A System.IO.Compression.FileSystem
  45. # This fxies SSL/TLS errors, credit goes to Ansible; see their `win_get_url.ps1` file
  46. $security_protcols = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::SystemDefault
  47. if ([Net.SecurityProtocolType].GetMember('Tls11').Count -gt 0) {
  48. $security_protcols = $security_protcols -bor [Net.SecurityProtocolType]::Tls11
  49. }
  50. if ([Net.SecurityProtocolType].GetMember('Tls12').Count -gt 0) {
  51. $security_protcols = $security_protcols -bor [Net.SecurityProtocolType]::Tls12
  52. }
  53. [Net.ServicePointManager]::SecurityProtocol = $security_protcols
  54. $webclient = New-Object System.Net.WebClient
  55. # Ensure DESTDIR exists:
  56. mkdir $destdir -ea 0
  57. mkdir "$destdir\usr\local" -ea 0
  58. # Download sources:
  59. echo 'Downloading sources ...'
  60. if (!(Test-Path "$BOOST.zip")) { $webclient.DownloadFile("https://dl.bintray.com/boostorg/release/1.63.0/source/$BOOST.zip", "$BOOST.zip") }
  61. if (!(Test-Path "$TBB.zip")) { $webclient.DownloadFile("https://github.com/wjakob/tbb/archive/$TBB_SHA.zip", "$TBB.zip") }
  62. if (!(Test-Path "$CURL.zip")) { $webclient.DownloadFile("https://curl.haxx.se/download/$CURL.zip", ".\$CURL.zip") }
  63. # Unpack sources:
  64. echo 'Unpacking ...'
  65. if (!(Test-Path $BOOST)) { [IO.Compression.ZipFile]::ExtractToDirectory("$BOOST.zip", '.') }
  66. if (!(Test-Path $TBB)) { [IO.Compression.ZipFile]::ExtractToDirectory("$TBB.zip", '.') }
  67. if (!(Test-Path $CURL)) { [IO.Compression.ZipFile]::ExtractToDirectory("$CURL.zip", '.') }
  68. # Build libraries:
  69. echo 'Building ...'
  70. # Build boost
  71. pushd "$BOOST"
  72. .\bootstrap
  73. $adr_mode = ('32', '64')[!$b32]
  74. .\b2 `
  75. -j "$NPROC" `
  76. --with-system `
  77. --with-filesystem `
  78. --with-thread `
  79. --with-log `
  80. --with-locale `
  81. --with-regex `
  82. "--prefix=$destdir/usr/local" `
  83. "address-model=$adr_mode" `
  84. toolset=msvc-12.0 `
  85. link=static `
  86. variant=release `
  87. threading=multi `
  88. boost.locale.icu=off `
  89. install
  90. popd
  91. # Build TBB
  92. pushd "$TBB"
  93. mkdir 'mybuild' -ea 0
  94. cd 'mybuild'
  95. $generator = ('Visual Studio 12', 'Visual Studio 12 Win64')[!$b32]
  96. cmake .. `
  97. -G "$generator" `
  98. -DCMAKE_CONFIGURATION_TYPES=Release `
  99. -DTBB_BUILD_SHARED=OFF `
  100. -DTBB_BUILD_TESTS=OFF "-DCMAKE_INSTALL_PREFIX:PATH=$destdir\usr\local"
  101. msbuild /P:Configuration=Release INSTALL.vcxproj
  102. popd
  103. # Build libcurl:
  104. pushd "$CURL\winbuild"
  105. $machine = ("x86", "x64")[!$b32]
  106. nmake /f Makefile.vc mode=static VC=12 GEN_PDB=yes DEBUG=no "MACHINE=$machine"
  107. Copy-Item -R -Force ..\builds\libcurl-*-winssl\include\* "$destdir\usr\local\include\"
  108. Copy-Item -R -Force ..\builds\libcurl-*-winssl\lib\* "$destdir\usr\local\lib\"
  109. popd
  110. echo ""
  111. echo "All done!"
  112. echo ""
  113. }
  114. catch [Exception]
  115. {
  116. # This prints errors in a verbose manner
  117. echo $_.Exception|format-list -force
  118. }