Build.PL 4.1 KB

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