Build.PL 4.2 KB

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