-
Notifications
You must be signed in to change notification settings - Fork 78
/
prepare.pl
executable file
·1330 lines (1123 loc) · 42.3 KB
/
prepare.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
#
# TODO:
# - check modules with name colision
# modules
use Term::ANSIColor;
use Getopt::Long;
use File::Path;
use File::Basename;
use Cwd;
use Data::Dumper;
use strict;
# use warnings;
# constant names of files
my $preparepl = "prepare.pl";
my $cmakelist = "CMakeLists.txt";
# svn server structure
my $svn_kernel_dir = "src";
my $svn_plugins_dir = "plugins";
# dependency libraries
my @libraries = ( "mpi",
"curl",
"trilinos",
"parmetis",
"metis",
"mitrem",
"cgns",
"get",
"gsl",
"blitz",
"flens",
"tvmet",
"cblas",
"google_perftools",
"mutationpp",
"plato",
"cuda");
# constants
my $ERRORCOLOR="bold red";
my $OKCOLOR="bold green";
my $HEADINGCOLOR = "bold";
my $SUBSECTIONCOLOR = "yellow";
my $SECTIONCOLOR = "bold yellow";
my $DEBUGCOLOR = "yellow";
# options
my %default_options = (
'help' => 0,
'nocolor' => 0,
'mods-list' => 0,
'mods-update' => 0,
'mods-getall' => 0,
'mods-revision'=> 0,
'coolfluid-version' => "",
'dry-run' => 0,
'debug' => 0,
'verbose' => 0,
'allstatic' => "",
'allactive' => 1,
'find' => 0,
'config' => 0,
'nodeps' => 0,
'with_unit_tests' => "0",
'search_dirs' => "src plugins",
'install_api' => "",
'extra_search_dirs' => "",
'extra_mods_url' => "",
'extra_mods_list' => "",
'svnserver' => "https://github.com/andrealani/COOLFluiD/trunk",
'config_file' => "coolfluid.conf",
'build' => "RelWithDebInfo",
'buildtype' => "",
'basebuild_dir'=> getcwd(),
'plugins_dir' => "plugins",
'coolfluid_dir'=> getcwd(),
'install_dir' => "",
'cmake_generator' => "make",
'cc' => "",
'cxx' => "",
'fc' => "",
'cudac' => "",
'withbuildtype' => 1,
'withmpi' => "",
'withcuda' => 0,
'withviennacl' => 0,
'withomp' => 0,
'with_ibmshared' => 0, # shared with IBM compiler
'with_ibmstatic' => 0, # static with IBM compiler
'with_singleexec' => 0, # only coolfluid-solver will be compiled
'withcurl' => 0,
'with_craystatic' => 0,
'with_mutationpp' => 0,
'with_mutationpp_debug' => 0,
'with_plato' => 0,
'with_paralution' => 0,
'paralution_dir' => "",
'withdocs' => "",
'mpi_extra_libs' => "",
'nofortran' => "",
'withcuda_malloc' => 0,
'with_log4cpp' => 1,
'explicit_templates' => "",
'cflags' => "",
'cxxflags' => "",
'fflags' => "",
'cudacflags' => "",
'ldflags' => "",
'with_testcases' => "",
'internal_deps' => "",
'warnings' => "",
'assertions' => "",
'trace' => "",
'logall' => "",
'logdebug' => "",
'debug_macros' => "",
'profiling' => "",
'profiler_tool' => "gprof",
'blas_dir' => "",
'lapack_dir' => "",
'lapack_libraries' => "",
'curl_dir' => "",
'boost_dir' => "",
'boost_includedir' => "",
'boost_librarydir' => "",
'get_dir' => "",
'cgns_dir' => "",
'trilinos_dir' => "",
'metis_dir' => "",
'parmetis_dir' => "",
'google_perftools_dir' => "",
'plas_dir' => "",
'lesmodels_dir' => "",
'mitrem_dir' => "",
'pardiso_include_dir' => "", # /opt/intel/mkl/10.x.x.xxx/include
'pardiso_dir' => "", # /opt/intel/mkl/10.x.x.xxx/lib/32
'pardiso_gfortran_dir' => "", # /usr/lib/gcc/x/x
'petsc_dir' => "",
'samg_dir' => "",
'samg_options' => "",
'superlu_dir' => "",
'mpi_dir' => "",
'flens_dir' => "",
'blitz_dir' => "",
'tvmet_dir' => "",
'cblas_dir' => "",
'cuda_dir' => "",
'with_gsl' => 0,
'gsl_dir' => "",
'gsl_librarydir' => "/usr/lib64",
'gsl_includedir' => "/usr/include",
'mutationpp_dir' => "",
'mutationpp_librarydir' => "/usr/lib64",
'mutationpp_includedir' => "/usr/include",
'plato_dir' => "",
'plato_librarydir' => "/usr/lib64",
'plato_includedir' => "/usr/include",
'command' => "",
'single_precision' => 0,
'with_longint' => 0,
'with_llongint' => 0,
'libpetsc_name' => "petsc",
'libpetsc_deps_paths' => "",
'libparmetis_name' => "parmetis",
'libmetis_name' => "metis"
);
# add skip default skip options
foreach my $libname ( @libraries )
{
$default_options{"$libname\_skip"} = 0;
}
# variables
my %options = %default_options; # for command line options
my %user_pref; # for config file options
my $extrasearchdirs = ""; # record the extra search dirs
my $extramodsurl = ""; # record the extra mods dirs
my $install_api = ""; # which libraries should have their API installed
my %moddir; # in which dir the module resides
my %modlibs; # which libs are in each module
my %modapps; # which apps are in each module
my %modtests; # which tests are in each module
my @all_mods; # all the modules
my @all_libs; # all the plugin libs
my @all_apps; # all the plugin apps
my @all_tests; # all the plugin unit tests
# list of options to choose the compiler
my $comp_options = "";
# list of other options that affect configuration
my $other_options = "";
# list of options with which plugins to compile or skip
my $plugin_options = "";
#==========================================================================
# Helper funcions
#==========================================================================
sub parse_command_line_options()
{
# parse command line
$options{'help'}=1 unless GetOptions (
'help' => \$options{'help'},
'debug' => \$options{'debug'},
'nocolor' => \$options{'nocolor'},
'mods-list' => \$options{'mods-list'},
'mods-update' => \$options{'mods-update'},
'mods-select=s' => \$options{'mods-select'},
'mods-getall' => \$options{'mods-getall'},
'mods-revision=i'=> \$options{'mods-revision'},
'coolfluid-version=s' => \$options{'coolfluid-version'},
'config' => \$options{'config'},
'nodeps' => \$options{'nodeps'},
'find' => \$options{'find'},
'dry-run' => \$options{'dry-run'},
'with_unit_tests' => \$options{'with_unit_tests'},
'verbose' => \$options{'verbose'},
'allstatic' => \$options{'allstatic'},
'allactive' => \$options{'allactive'},
'search-dirs=s' => \$options{'search_dirs'},
'extra-search-dirs=s' => \$options{'extra_search_dirs'},
'extra-mods-url=s' => \$options{'extra_mods_url'},
'extra-mods-list=s' => \$options{'extra_mods_list'},
'install-api=s' => \$options{'install_api'},
'config-file=s' => \$options{'config_file'},
'build=s' => \$options{'build'},
'buildtype=s' => \$options{'buildtype'},
'coolfluid_dir=s'=> \$options{'coolfluid_dir'},
'install_dir=s' => \$options{'install_dir'},
'cmake_generator=s' => \$options{'cmake_generator'},
'libpetsc_name=s' => \$options{'libpetsc_name'},
'libpetsc_deps_paths' => \$options{'libpetsc_deps_paths'},
'libparmetis_name=s' => \$options{'libparmetis_name'},
'libmetis_name=s' => \$options{'libmetis_name'}
);
# remove duplicated entries in options
while ( my ($key, $value) = each(%default_options) ) {
if ( $value eq $options{$key}) {
delete $options{$key};
};
}
# show help if required
if ($options{'help'} != 0)
{
print <<ZZZ;
prepare.pl : this script prepares the COOLFluiD Build Environment
OPTIONS
behavior:
--help Show this help.
--nocolor Don't color output
--dry-run Don't actually execute the system calls.
Just output what you would do.
--nodeps Don't do check for action dependencies.
--verbose Print extra information.
configuration:
--allactive Makes all libraries active by default.
This is the default.
--allstatic Makes all libraries static by default, instead of dynamic.
They still can be desactivated in the configuration file.
--with_singleexec Create a single executable with no libraries
--with_unit_tests Create the unit tests. [Default: $default_options{'with_unit_tests'}]
--config-file= User config file to overide default configuration options
Default: $default_options{'config_file'}
--basebuild_dir= Location where to build the sources
Default: Current directory
--coolfluid_dir= Location of the COOLFluiD sources directory
Default: Current directory
--install-dir= Location of the COOLFluiD installation directory
Default: $default_options{'install_dir'}
--cmake_generator= Chooses which type of build system will cmake generate
'make' for 'Unix Makefiles'
'kdev' for 'KDevelop3'
'xcode' for 'XCode'
'cb' for 'Code::Blocks'
'vs8' for 'Visual Studio 8 2005'
'vs9' for 'Visual Studio 9 2008'
'eclipse-make' for 'Eclipse CDT4 - Unix Makefiles'
Default: $default_options{'cmake_generator'}
--mods-getall Gets all the modules found in the plugins repository
--mods-revision Chechout or update the modules to a specific svn revision
--mods-select Comma separated list of modules to apply the svn actions
--coolfluid-version Select a tagged version of coolfluid to check out. Ex: "2009.0"
--extra-search-dirs= Comma separated list of directories where to search for modules
Default: $default_options{'extra_search_dirs'}
--extra-mods-url= Comma separated list of svn directories where to search for modules
Default: $default_options{'extra_mods_url'}
--extra-mods-list= Comma separated list of extra modules
Default: $default_options{'extra_mods_list'}
--libpetsc_name= Name of the petsc library (Default: petsc)
--libpetsc_deps_paths Full paths to all petsc dependencies (needed only for static linking)
--libparmetis_name= Name of the parmetis library (Default: parmetis)
--libmetis_name= Name of the metis library (Default: metis)
ACTIONS
build actions:
--find Just report which modules and plugins inside each module you find.
--config Performs the configuration.
--build= Build configuration for the compilation. Implies --config
Default: $default_options{'build'}
modules actions: ( needs network access )
--mods-list Lists the available modules in the svn server
--mods-update Checkout or Updates the selected modules from the svn server
ZZZ
exit(0);
}
}
#==========================================================================
sub wordcaps {
my $line = shift;
$line =~ tr/a-z/A-Z/; # all letters
# $line =~ s/\b(\w)/\U$1/g; # only first letter
return $line;
}
#==========================================================================
sub my_colored($$)
{
return (get_option('nocolor') ? shift : colored($_[0], $_[1]));
}
#==========================================================================
sub get_build() # get the build option
{
my $build;
if ( exists($options{'build'}) ) {
$build = $options{'build'};
} else {
if ( exists($user_pref{'build'}) ) {
$build = $user_pref{'build'};
} else {
$build = $default_options{'build'};
}
}
$build =~ s/\/$//;
return $build;
}
#==========================================================================
sub get_build_path() # gets the build path
{
my $build = get_build();
my $basebuild_dir = get_option('basebuild_dir');
return "$basebuild_dir/$build";
}
#==========================================================================
sub get_search_paths() # gets the paths where to search for sources
{
my $coolfluid_dir = get_option('coolfluid_dir');
my $search_dirs = get_option('search_dirs');
my @sdirs = split (" " , $search_dirs );
my $search_paths;
foreach my $dir ( @sdirs )
{
$search_paths .= "$coolfluid_dir/$dir ";
}
return "$search_paths";
}
#==========================================================================
sub get_option($) # get the option, if the case, overidden by the user
{
my ($key) = @_;
my $build = get_build();
# per build options in the config file have top priority
if ( exists($user_pref{"$build\_$key"}) ) {
return $user_pref{"$build\_$key"};
}
# next come the command line options
if ( exists($options{"$key"}) ) {
return $options{"$key"};
}
# followed by the normal config file options
if ( exists($user_pref{"$key"}) ) {
return $user_pref{"$key"};
}
# followed by the default options
if ( exists($default_options{"$key"}) ) {
return $default_options{$key};
}
# die if option doesnt exist
die("Unknown option $key required");
}
#==========================================================================
sub get_arch() # returns the current architecture
{
my $args="uname -m";
my $output;
# print my_colored("Executing : $args",$OKCOLOR);
my $command = join("",$args,"|");
my $pid=open READER, $command or die "Can't run the program: $args $!\n";
while(<READER>){ $output.=$_; }
close READER;
# print my_colored($output,$OK_COLOR);
my $arch = $output;
chomp($arch);
return $arch;
}
#==========================================================================
sub parse_config_file($) # parse the config file to get the user overiding options
{
my ($filename) = @_;
if ( -e "$filename" ) {
print "Reading config file : $filename\n";
open CONFIG, "<", $filename or die ("Error opening config file $filename!\n");
my $arch = get_arch();
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
s/\$ARCH/$arch/; # subst $ARCH
s/\$(\w+)/$ENV{$1}/g; # subst all $X for environmental variables
my ($key, $value) = split(/\s*=\s*/, $_, 2);
$user_pref{$key} = $value;
}
close CONFIG;
}
}
#==========================================================================
sub find_modules()
{
print my_colored("\nSearching for module directories containing $cmakelist\n",$SECTIONCOLOR);
# check that we are in the toplevel directory
die (my_colored("Cannot find $preparepl; You need to run this command in the toplevel COOLFluiD directory!\n",$ERRORCOLOR)) unless -f "$preparepl";
if (get_option('extra_search_dirs'))
{
# fix the search dir option which comes comma separated
my @array_extradirs = split(',',get_option('extra_search_dirs'));
$extrasearchdirs = join(" ",@array_extradirs);
}
# check out additional user-defined modules into the "plugins" folder
if (get_option('extra_mods_list') and get_option('extra_mods_url'))
{
# fix the mods dir option which comes comma separated
my @array_extramlist = split(',',get_option('extra_mods_list'));
my @array_extramurl = split(',',get_option('extra_mods_url'));
if ( $#array_extramlist != $#array_extramurl )
{
print my_colored("\nERROR: <extra_mods_list> must have same number of entries as <extra_mods_url> in coolfluid.conf\n",$ERRORCOLOR);
exit(0);
}
my $coolfluid_dir = get_option('coolfluid_dir');
for (my $idir = 0; $idir <= $#array_extramlist; $idir++)
{
my $mdir = "$coolfluid_dir/plugins/$array_extramlist[$idir]";
print my_colored("\nChecking whether dir $mdir exists\n",$SECTIONCOLOR);
if (!(-d $mdir) )
{
print my_colored("\nChecking out extra module $array_extramlist[$idir] from $array_extramurl[$idir]\n",$SECTIONCOLOR);
run_command("svn co $array_extramurl[$idir] $mdir");
}
}
}
my $searchdirs = get_search_paths() . " " . $extrasearchdirs;
my $search_unittests = get_option('with_unit_tests');
open FILE, "-|", "find -L $searchdirs -name $cmakelist" or die ("Error searching for $cmakelist - $!");
while (my $file=<FILE>)
{
my $dir = dirname($file);
my $modname = $dir;
$modname =~ s/\//_/g;
#print my_colored("\n##### FILE => $file\n",$SECTIONCOLOR);
#print my_colored("\n##### DIR => $dir\n",$SECTIONCOLOR);
#print my_colored("\n##### MODULE => $modname\n",$SECTIONCOLOR);
push(@all_mods, $modname);
$moddir{$modname} = $dir;
# array handle for local libs, apps and tests
$modlibs{"$modname"} = [];
$modapps{"$modname"} = [];
$modtests{"$modname"} = [];
my $local_libs = $modlibs{"$modname"};
my $local_apps = $modapps{"$modname"};
my $local_tests = $modtests{"$modname"};
# parse module file to find libs, apps or unit tests
open MODMK, "<$file" or die "can't open $file $!";
while (<MODMK>) {
my $line = $_;
# found a plugin library
if ($line =~ m/(\s*)CF_ADD_PLUGIN_LIBRARY(\s*)\((\s*)(.*)(\s*)\)/ )
{
my $libs = $4;
$libs =~ s/(\s+)/\:/g;
push(@all_libs,split('\:',$libs));
push(@$local_libs,split('\:',$libs));
}
# found a kernel library
if ($line =~ m/(\s*)CF_ADD_KERNEL_LIBRARY(\s*)\((\s*)(.*)(\s*)\)/ )
{
my $libs = $4;
$libs =~ s/(\s+)/\:/g;
push(@all_libs,split('\:',$libs));
push(@$local_libs,split('\:',$libs));
}
if ($line =~ m/(\s*)CF_ADD_PLUGIN_APP(\s*)\((\s*)(.*)(\s*)\)/ )
{
my $apps = $4;
$apps =~ s/(\s+)/\:/g;
push(@all_apps,split('\:',$apps));
push(@$local_apps,split('\:',$apps));
}
if ( $search_unittests and $line =~ m/(\s*)CF_ADD_TEST(\s*)\((\s*)(.*)(\s*)\)/ )
{
my $tests = $4;
$tests =~ s/(\s+)/\:/g;
push(@all_tests,split('\:',$tests));
push(@$local_tests,split('\:',$tests));
}
}
close MODMK;
# print info about this config file
if (get_option('verbose')) {
my $nblibs = scalar (@$local_libs);
my $nbapps = scalar (@$local_apps);
my $nbtests = scalar (@$local_tests);
print "Module file " . $file . " defines:\n\t$nblibs lib(s) : @$local_libs\n\t$nbapps app(s) : @$local_apps\n\t$nbtests test(s) : @$local_tests\n";
}
}
close FILE;
@all_libs = sort @all_libs;
@all_apps = sort @all_apps;
@all_tests = sort @all_tests;
@all_mods = sort @all_mods;
my $nblibs = scalar @all_libs;
my $nbapps = scalar @all_apps;
my $nbtests = scalar @all_tests;
my $nbmods = scalar @all_mods;
print my_colored("Searched in directories $searchdirs\n",$OKCOLOR);
print my_colored("Found $nbmods MODULE directories with $cmakelist defining a total of $nblibs lib(s), $nbapps app(s) and $nbtests unit tests(s)\n",$OKCOLOR);
# print summary of module info
if (get_option('verbose')) {
print my_colored("\nList of Modules\n",$SECTIONCOLOR);
foreach my $modname (@all_mods)
{
print my_colored("Module $modname : ",$SUBSECTIONCOLOR) if get_option('verbose');
my $libs_handle = $modlibs{$modname};
my $apps_handle = $modapps{$modname};
my $tests_handle = $modtests{$modname};
if (scalar(@$libs_handle)) { print " " . scalar(@$libs_handle) ." libs (". join(',',@$libs_handle) .") "; }
if (scalar(@$apps_handle)) { print " " . scalar(@$apps_handle) ." apps (". join(',',@$apps_handle) .") "; }
if (scalar(@$tests_handle)) { print " " . scalar(@$tests_handle) ." tests (".join(',',@$tests_handle).") "; }
print "\n";
}
}
print "\n";
print my_colored("All libs :\n ",$OKCOLOR) . " @all_libs\n";
print my_colored("All apps :\n ",$OKCOLOR) . " @all_apps\n";
print my_colored("All tests :\n ",$OKCOLOR) . " @all_tests\n";
}
#==========================================================================
sub set_default_plugins_on() # put the plugins into the default options
{
# set the default value for the libs
# should be the default value of allactive
foreach (@all_libs)
{
if (get_option('allactive'))
{ $default_options{"lib_$_"} = 'on'; }
else
{ $default_options{"lib_$_"} = 'off'; }
}
# by default apps are active
foreach (@all_apps)
{
$default_options{"app_$_"} = 'on';
}
# by default tests are active
foreach (@all_tests)
{
$default_options{"test_$_"} = 'on';
}
}
#==========================================================================
sub print_hash($$)
{
my ($ref_hash, $ordered) = @_;
# unordered
if ($ordered)
{
my %hash = %{$ref_hash};
my @keys = sort keys %{$ref_hash};
foreach my $key (@keys)
{
my $value = $hash{$key};
print "$key => $value\n";
}
}
else
{
while ( my ($key, $value) = each(%{$ref_hash}) ) {
print "$key => $value\n";
}
}
}
#==========================================================================
sub print_debug_options()
{
print my_colored("DefaultOptions\n",$OKCOLOR);
print_hash(\%default_options,1);
print my_colored("Options\n",$OKCOLOR);
print_hash(\%options,1);
print my_colored("UserOptions\n",$OKCOLOR);
print_hash(\%user_pref,1);
}
#==========================================================================
sub run_command($)
{
my ($args)=@_;
my $output;
if (get_option('dry-run'))
{
print my_colored("[dry-run] would have executed : ",$OKCOLOR).$args."\n";
}
else {
print my_colored("[verbose] executing : ",$OKCOLOR).$args."\n" if get_option('verbose');
my $command = join("",$args,"|");
my $pid=open READER, $command or die "Can't run the program: $args $!\n";
while(<READER>){
$output.=$_;
}
close READER;
}
return $output;
}
#==========================================================================
sub print_var($$) # prints a variable and its value in color
{
my ($var,$value)=@_;
print my_colored($var,$OKCOLOR); print " : ";
print my_colored($value,$DEBUGCOLOR); print "\n";
}
#==========================================================================
sub suredir($) # make sure a directory exists, if not, create it
{
my ($dir)=@_;
if (-d $dir)
{
print my_colored($dir,$OKCOLOR); print "\n";
}
else
{
print my_colored($dir,$ERRORCOLOR); print "\n";
mkdir($dir, 0755) || die "Cannot mkdir $dir: $!";
}
}
#==========================================================================
sub cfg_lib($$) # put the disabled libraries in the list
{
my ($lib, $list) = @_;
if ( ! ( get_option("lib_$lib") eq 'on' or get_option("lib_$lib") eq 'ON' ) )
{ push(@$list,"$lib") }
}
#==========================================================================
sub cfg_app($$) # put the disabled application in the list
{
my ($app, $list) = @_;
if ( ! ( get_option("app_$app") eq 'on' or get_option("app_$app") eq 'ON' ) )
{ push(@$list,"$app") }
}
#==========================================================================
sub cfg_test($$) # put the disabled unit test in the list
{
my ($test, $list) = @_;
if ( ! ( get_option("test_$test") eq 'on' or get_option("test_$test") eq 'ON' ) )
{ push(@$list,"$test") }
}
#==========================================================================
sub add_cmake_option($)
{
my ($cmopt) = @_;
my $cmopt_caps = wordcaps ( $cmopt );
my $cmopt_data = get_option( $cmopt );
if ( !($cmopt_data eq '') )
{ $plugin_options .= " -D$cmopt_caps=\"$cmopt_data\""; }
}
#==========================================================================
sub setup_deps()
{
if(get_option('boost_dir'))
{ $plugin_options .= " -DBOOST_ROOT=\"".get_option('boost_dir')."\""; }
# dependency variables
my @dep_variables = ( "boost_includedir",
"boost_librarydir",
"paralution_dir",
"petsc_dir",
"plas_dir",
"pardiso_include_dir",
"pardiso_dir",
"pardiso_gfortran_dir",
"lesmodels_dir",
"samg_dir",
"samg_options",
"blas_dir",
"lapack_dir",
"gsl_includedir",
"gsl_librarydir",
"mutationpp_librarydir",
"mutationpp_includedir",
"plato_librarydir",
"plato_includedir",
"cgns_dir",
"lapack_libraries" );
foreach (@dep_variables) { add_cmake_option($_); }
foreach (@libraries) { setup_library($_); }
}
#==========================================================================
sub setup_library($) # setup a dependecy library
{
my ($lib)=@_;
my $lkey = "$lib\_dir";
my $lib_dir = get_option($lkey);
my $lkey_s = "$lib\_skip";
my $lib_skip = get_option($lkey_s);
my $libcaps = wordcaps($lib);
if ($lib_skip) { $plugin_options .= " -DCF_SKIP_$libcaps=ON"; }
else
{
if ( !($lib_dir eq '') )
{ $plugin_options .= " -D$libcaps\_HOME=\"$lib_dir\""; }
}
}
#==========================================================================
sub setup_option($$)
{
my ($opt_name, $opt_cmake_name) = @_;
my $lopt = get_option("$opt_name");
if ( ($lopt eq 'on') or ($lopt eq 'off') or ($lopt eq '1') or ($lopt eq '0') )
{
$other_options .= " -D$opt_cmake_name=$lopt";
}
else
{
unless ( $lopt eq "" ) { die "Option \'$opt_name\' must have value 'on' of 'off'"; }
}
}
#==========================================================================
sub setup_cfgoptions()
{
setup_deps();
my $enablelibs = [];
my $disablelibs = [];
my $disableapps = [];
my $disabletests = [];
foreach (@all_libs) { cfg_lib($_,$disablelibs); }
foreach (@all_apps) { cfg_app($_,$disableapps); }
foreach (@all_tests) { cfg_test($_,$disabletests); }
# enable libs are all minus the disabled
# compute the intersection of the arrays
my @isect = ();
my %count = ();
foreach my $e (@all_libs, @$disablelibs) { $count{$e}++ }
foreach my $e (keys %count)
{
push @{ $count{$e} == 2 ? \@isect : \@$enablelibs }, $e;
}
# plugins are ON by default, no need to add them to the configuration
foreach (@$disablelibs)
{
$plugin_options .= " -DCF_BUILD_$_=OFF";
$plugin_options .= " -DCF_COMPILES_$_=OFF";
}
foreach (@$disableapps) { $plugin_options .= " -DCF_BUILD_$_=OFF"; }
foreach (@$disabletests) { $plugin_options .= " -DCF_BUILD_$_=OFF"; }
print my_colored("List of enabled libs:\n", $OKCOLOR);
foreach (@$enablelibs)
{
print "$_ ";
$plugin_options .= " -DCF_COMPILES_$_=ON";
}
print "\n";
if ( get_option('install_api') )
{
# fix the option which comes comma separated
my @array_install_api = split(',',get_option('install_api'));
foreach my $lib_api (@array_install_api)
{
$plugin_options .= " -DCF_BUILD_$lib_api\_API=ON";
}
}
if (get_option('extra_search_dirs'))
{
# fix the search dir option which comes comma separated
my @array_extradirs = split(',',get_option('extra_search_dirs'));
$extrasearchdirs = join(";",@array_extradirs);
$other_options .= " -DCF_EXTRA_SEARCH_DIRS=$extrasearchdirs";
}
if (get_option('mpi_extra_libs'))
{
# fix the MPI extra libs option which comes with comma separated list
my @array_mpiextralibs = split(',',get_option('mpi_extra_libs'));
my $mpiextralibs = join(";",@array_mpiextralibs);
$other_options .= " -DMPI_EXTRA_LIBRARY_NAMES=$mpiextralibs";
}
if (get_option('profiling'))
{
my $opt_profiling = get_option('profiling');
my $opt_profiler_tool = get_option('profiler_tool');
unless ( ($opt_profiling eq "on") or ($opt_profiling eq "off") ) { die "Option 'profiling' must have value 'on' of 'off'"; }
$other_options .= " -DCF_ENABLE_PROFILING=$opt_profiling -DCF_PROFILER_TOOL=$opt_profiler_tool";
}
my $libpetsc_name = "petsc";
if (get_option('libpetsc_name'))
{
$libpetsc_name = get_option('libpetsc_name');
$other_options .= " -DCF_LIBPETSC_NAME=$libpetsc_name";
}
my $libpetsc_deps_paths = "";
if (get_option('libpetsc_deps_paths'))
{
$libpetsc_deps_paths = get_option('libpetsc_deps_paths');
$other_options .= " -DCF_LIBPETSC_DEPS_PATHS=\"$libpetsc_deps_paths\"";
}
my $libparmetis_name = "parmetis";
if (get_option('libparmetis_name'))
{
$libparmetis_name = get_option('libparmetis_name');
$other_options .= " -DCF_LIBPARMETIS_NAME=$libparmetis_name";
}
my $libmetis_name = "metis";
if (get_option('libmetis_name'))
{
$libmetis_name = get_option('libmetis_name');
$other_options .= " -DCF_LIBMETIS_NAME=$libmetis_name";
}
setup_option('nofortran', 'CF_SKIP_FORTRAN');
setup_option('withmpi', 'CF_ENABLE_MPI');
setup_option('withcuda', 'CF_ENABLE_CUDA');
setup_option('withviennacl', 'CF_ENABLE_VIENNACL');
setup_option('withomp', 'CF_ENABLE_OMP');
setup_option('with_ibmshared', 'CF_ENABLE_IBMSHARED');
setup_option('with_ibmstatic', 'CF_ENABLE_IBMSTATIC');
setup_option('with_singleexec', 'CF_ENABLE_SINGLEEXEC');
setup_option('withcurl', 'CF_ENABLE_CURL');
setup_option('with_craystatic', 'CF_ENABLE_CRAYSTATIC');
setup_option('with_mutationpp', 'CF_ENABLE_MUTATIONPP');
setup_option('with_mutationpp_debug', 'CF_ENABLE_MUTATIONPP_DEBUG');
setup_option('with_plato', 'CF_ENABLE_PLATO');
setup_option('with_paralution', 'CF_ENABLE_PARALUTION');
setup_option('with_gsl', 'CF_ENABLE_GSL');
setup_option('withdocs', 'CF_ENABLE_DOCS');
setup_option('explicit_templates', 'CF_ENABLE_EXPLICIT_TEMPLATES');
setup_option('with_testcases', 'CF_ENABLE_TESTCASES');
setup_option('with_unit_tests', 'CF_ENABLE_UNITTESTS');
setup_option('internal_deps', 'CF_ENABLE_INTERNAL_DEPS');
setup_option('assertions', 'CF_ENABLE_ASSERTIONS');
setup_option('trace', 'CF_ENABLE_TRACE');
setup_option('logall', 'CF_ENABLE_LOGALL');
setup_option('logdebug', 'CF_ENABLE_LOGDEBUG');
setup_option('debug_macros', 'CF_ENABLE_DEBUG_MACROS');
setup_option('allstatic', 'CF_ENABLE_STATIC');
setup_option('warnings', 'CF_ENABLE_WARNINGS');
setup_option('single_precision', 'CF_PRECISION_SINGLE');
setup_option('with_longint', 'CF_ENABLE_LONG');
setup_option('with_llongint', 'CF_ENABLE_LLONG');
setup_option('withcuda_malloc', 'CF_CUDA_MALLOC');
setup_option('with_log4cpp', 'CF_ENABLE_LOG4CPP');
}
#==========================================================================
sub run_configuration() # run configuration
{
my $build = get_build();