You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

linux-compile-cmake.pl 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/perl
  2. # Intended to be run from linux-install_dependencies.pl which defines the dependencies_dir variable.
  3. #
  4. # Variables are wrt that parent scope
  5. #
  6. use strict;
  7. use warnings;
  8. use Getopt::Long;
  9. use English;
  10. use FindBin;
  11. use File::Copy;
  12. use File::Spec;
  13. # Version of CMake to install if needed (latest as of 08/2020)
  14. my $version_major = 3;
  15. my $version_minor = 18;
  16. my $version_patch = 1;
  17. # Minimum version needed for the project.
  18. # 3.12 for FindPython functionalities.
  19. my $minimum_major = 3;
  20. my $minimum_minor = 15;
  21. my $install_dir = $dependencies_dir;
  22. # Updating path with potentially installed cmake before looking for it.
  23. if ("$dependencies_dir/cmake") {
  24. print "Found cmake folder in deps\n";
  25. my $path = $ENV{'PATH'};
  26. $path = "$dependencies_dir/cmake/bin:$path";
  27. $ENV{'PATH'} = $path;
  28. #system("PATH=$dependencies_dir/cmake/bin:$PATH")
  29. }
  30. # Checking for CMake presence
  31. my $major_found = 0;
  32. my $minor_found = 0;
  33. if (`which cmake`) {
  34. `cmake --version` =~ /.*(\d)\.(\d\d)\.*/;
  35. print "cmake version found: $1.$2\n";
  36. $major_found = $1;
  37. $minor_found = $2;
  38. }
  39. # Minimum cmake version required for the project: 3.12
  40. if (int($major_found) < $minimum_major || int($minor_found) < $minimum_minor) {
  41. my $old_dir = Cwd::getcwd();
  42. my $cmake_archive = "cmake-${version_major}.${version_minor}.${version_patch}.tar.gz";
  43. my $cmake_folder = "cmake-${version_major}.${version_minor}.${version_patch}";
  44. print "CMake version too low. Installing newer one in $install_dir\n";
  45. if (! -d $install_dir) {
  46. mkdir($install_dir) or die("Failed to create directory [$install_dir]");
  47. }
  48. # Download
  49. print "Downloading ${cmake_archive}\n";
  50. system("wget http://www.cmake.org/files/v${version_major}.${version_minor}/${cmake_archive}") == 0
  51. or die "Could not download the CMake sources - err $?";
  52. # Extract
  53. system("tar -xzf ${cmake_archive}") == 0
  54. or die ("Could not extract the CMake archive - err $?");
  55. # Configure, compile and install
  56. chdir $cmake_folder;
  57. system("./configure --prefix=$install_dir/cmake") == 0
  58. or die("Failed to configure for cmake - err $?");
  59. system("make install") == 0
  60. or die ("Failed make install cmake - err $?");
  61. # Go back to previous folder
  62. chdir $old_dir;
  63. #Clear
  64. system("rm -r ${cmake_archive} ${cmake_folder}") == 0
  65. or die ("Failed to clear after install - err $?");
  66. }