#! /usr/bin/perl # Perl script to build my code. use Getopt::Long; $cmake = `which cmake`; chomp($cmake); $optimize = 0; $help = 0; $builddir = "build"; $sourcedir = $ENV{'PWD'}; $intel = 0; $verbose = 0; $ret = GetOptions( "c=s" => \$cmake, 'o' => \$optimize, 'h|?' => \$help, "b=s" => \$builddir, "s=s" => \$sourcedir, 'u' => \$universal, 'i' => \$intel, 'V' => \$verbose ); if ($help || !$ret) { print "Build.pl options:\n"; print " -b name build directory (default is \"build\").\n"; print " -c file cmake to use.\n"; print " -o optimized build (default is debug).\n"; print " -s name source directory (default is \$PWD).\n"; print " -u Universal build (Mac only).\n"; print " -i Intel compiler.\n"; print " -V Verbose.\n"; print " -h this help menu.\n"; exit; } # Make sure we have cmake # if (! -e $cmake) { print "\ncmake not found.\n"; print "Please install cmake.\n"; print "http://cmake.org\n\n"; exit; } print "\nSource directory = $sourcedir\n"; print "Build directory = $builddir\n\n"; # Check that there's a cmake file in the source directory # if (! -e "$sourcedir/CMakeLists.txt") { print "Cannot find CMakeLists.txt in source directory.\n"; exit; } # Created the build directory if needed # if (! -e $builddir) { mkdir $builddir; } chdir $builddir; # configure the build type # if ($optimize) { $buildtype = "-D CMAKE_BUILD_TYPE:STRING=Release"; } else { $buildtype = "-D CMAKE_BUILD_TYPE:STRING=Debug"; } # universal build option for Macs # if ($universal) { $uname = `uname`; chomp($uname); if ($uname eq "Darwin") { $univopt = "-D \"CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64;ppc;ppc64\""; } else { print "Ignoring universal option.\n"; } } # invoke the Intel compiler # if ($intel) { $cxx = "-D \"CMAKE_CXX_COMPILER:FILEPATH=icpc\""; $cc = "-D \"CMAKE_CX_COMPILER:FILEPATH=icc\""; } # tell cmake to run verbosely # if ($verbose) { $verb = "-D \"CMAKE_VERBOSE_MAKEFILE:BOOL=TRUE\""; } # Run CMake # print "\nRunning cmake\n"; $cmd = "$cmake $buildtype $univopt $cxx $cc $verb $sourcedir"; system $cmd; # getting the number of processors $nproc = `$sourcedir/bin/nproc`; chomp($nproc); print "\nCompiling imodel\n\n"; $cmd = "make -j $nproc"; system $cmd;