Build.PL 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Config;
  5. use File::Spec;
  6. my %prereqs = qw(
  7. Devel::CheckLib 0
  8. ExtUtils::MakeMaker 6.80
  9. ExtUtils::ParseXS 3.22
  10. ExtUtils::XSpp 0
  11. ExtUtils::Typemaps 0
  12. ExtUtils::Typemaps::Basic 0
  13. File::Basename 0
  14. File::Spec 0
  15. Getopt::Long 0
  16. Module::Build::WithXSpp 0.14
  17. Moo 1.003001
  18. POSIX 0
  19. Scalar::Util 0
  20. Test::More 0
  21. Thread::Semaphore 0
  22. IO::Scalar 0
  23. threads 1.96
  24. Time::HiRes 0
  25. );
  26. my %recommends = qw(
  27. Class::XSAccessor 0
  28. Test::Harness 0
  29. );
  30. my $sudo = grep { $_ eq '--sudo' } @ARGV;
  31. my $gui = grep { $_ eq '--gui' } @ARGV;
  32. my $nolocal = grep { $_ eq '--nolocal' } @ARGV;
  33. if ($gui) {
  34. %prereqs = qw(
  35. Class::Accessor 0
  36. Wx 0.9918
  37. Socket 2.016
  38. );
  39. %recommends = qw(
  40. Wx::GLCanvas 0
  41. );
  42. if ($^O eq 'MSWin32') {
  43. $recommends{"Win32::TieRegistry"} = 0;
  44. # we need an up-to-date Win32::API because older aren't thread-safe (GH #2517)
  45. $prereqs{'Win32::API'} = 0.79;
  46. }
  47. }
  48. my @missing_prereqs = ();
  49. if ($ENV{SLIC3R_NO_AUTO}) {
  50. foreach my $module (sort keys %prereqs) {
  51. my $version = $prereqs{$module};
  52. next if eval "use $module $version; 1";
  53. push @missing_prereqs, $module if exists $prereqs{$module};
  54. print "Missing prerequisite $module $version\n";
  55. }
  56. foreach my $module (sort keys %recommends) {
  57. my $version = $recommends{$module};
  58. next if eval "use $module $version; 1";
  59. print "Missing optional $module $version\n";
  60. }
  61. } else {
  62. my @try = (
  63. $ENV{CPANM} // (),
  64. File::Spec->catfile($Config{sitebin}, 'cpanm'),
  65. File::Spec->catfile($Config{installscript}, 'cpanm'),
  66. );
  67. my $cpanm;
  68. foreach my $path (@try) {
  69. if (-e $path) { # don't use -x because it fails on Windows
  70. $cpanm = $path;
  71. last;
  72. }
  73. }
  74. if (!$cpanm) {
  75. if ($^O =~ /^(?:darwin|linux)$/ && system(qw(which cpanm)) == 0) {
  76. $cpanm = 'cpanm';
  77. }
  78. }
  79. die <<'EOF'
  80. cpanm was not found. Please install it before running this script.
  81. There are several ways to install cpanm, try one of these:
  82. apt-get install cpanminus
  83. curl -L http://cpanmin.us | perl - --sudo App::cpanminus
  84. cpan App::cpanminus
  85. If it is installed in a non-standard location you can do:
  86. CPANM=/path/to/cpanm perl Build.PL
  87. EOF
  88. if !$cpanm;
  89. my @cpanm_args = ();
  90. push @cpanm_args, "--sudo" if $sudo;
  91. # install local::lib without --local-lib otherwise it's not usable afterwards
  92. if (!eval "use local::lib qw(local-lib); 1") {
  93. my $res = system $cpanm, @cpanm_args, 'local::lib';
  94. warn "Warning: local::lib is required. You might need to run the `cpanm --sudo local::lib` command in order to install it.\n"
  95. if $res != 0;
  96. }
  97. push @cpanm_args, ('--local-lib', 'local-lib') if ! $nolocal;
  98. # make sure our cpanm is updated (old ones don't support the ~ syntax)
  99. system $cpanm, @cpanm_args, 'App::cpanminus';
  100. my %modules = (%prereqs, %recommends);
  101. foreach my $module (sort keys %modules) {
  102. my $version = $modules{$module};
  103. my @cmd = ($cpanm, @cpanm_args);
  104. # temporary workaround for upstream bug in test
  105. push @cmd, '--notest'
  106. if $module =~ /^(?:OpenGL|Test::Harness)$/;
  107. push @cmd, "$module~$version";
  108. my $res = system @cmd;
  109. if ($res != 0) {
  110. if (exists $prereqs{$module}) {
  111. push @missing_prereqs, $module;
  112. } else {
  113. printf "Don't worry, this module is optional.\n";
  114. }
  115. }
  116. }
  117. }
  118. print "\n";
  119. if ($gui) {
  120. print "Perl dependencies for the Slic3r GUI were installed.\n";
  121. } else {
  122. print "Perl dependencies for Slic3r were installed.\n";
  123. print "If you also want to use the GUI you can now run `perl Build.PL --gui` to install the required modules.\n";
  124. }
  125. print "\n";
  126. print "In the next step, you need to build the Slic3r C++ library.\n";
  127. print "1) Create a build directory and change to it\n";
  128. print "2) run cmake .. -DCMAKE_BUILD_TYPE=Release\n";
  129. print "3) run make\n";
  130. print "4) to execute the automatic tests, run ctest --verbose\n";
  131. __END__