Build.PL 4.7 KB

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