@@ -27,8 +27,9 @@ module fpm_command_line
27
27
OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_WINDOWS, &
28
28
OS_CYGWIN, OS_SOLARIS, OS_FREEBSD
29
29
use M_CLI2, only : set_args, lget, sget, unnamed, remaining, specified
30
- use fpm_strings, only : lower, split
30
+ use fpm_strings, only : lower, split, fnv_1a
31
31
use fpm_filesystem, only : basename, canon_path, to_fortran_name
32
+ use fpm_compiler, only : get_default_compile_flags
32
33
use ,intrinsic :: iso_fortran_env, only : stdin= >input_unit, &
33
34
& stdout= >output_unit, &
34
35
& stderr= >error_unit
@@ -65,6 +66,7 @@ module fpm_command_line
65
66
logical :: show_model= .false.
66
67
character (len= :),allocatable :: compiler
67
68
character (len= :),allocatable :: build_name
69
+ character (len= :),allocatable :: flag
68
70
end type
69
71
70
72
type, extends(fpm_build_settings) :: fpm_run_settings
@@ -106,7 +108,7 @@ module fpm_command_line
106
108
& ' ' , ' fpm' , ' new' , ' build' , ' run' , &
107
109
& ' test' , ' runner' , ' install' , ' update' , ' list' , ' help' , ' version' ]
108
110
109
- character (len= :), allocatable :: val_runner, val_build, val_compiler
111
+ character (len= :), allocatable :: val_runner, val_build, val_compiler, val_flag
110
112
111
113
contains
112
114
subroutine get_command_line_settings (cmd_settings )
@@ -157,6 +159,7 @@ subroutine get_command_line_settings(cmd_settings)
157
159
& --example F&
158
160
& --runner " " &
159
161
& --compiler "' // get_env(' FPM_COMPILER' ,' gfortran' )// ' " &
162
+ & --flag:: " "&
160
163
& --verbose F&
161
164
& --' ,help_run,version_text)
162
165
@@ -192,6 +195,7 @@ subroutine get_command_line_settings(cmd_settings)
192
195
& args= remaining,&
193
196
& build_name= val_build,&
194
197
& compiler= val_compiler, &
198
+ & flag= val_flag, &
195
199
& example= lget(' example' ), &
196
200
& list= lget(' list' ),&
197
201
& name= names,&
@@ -204,6 +208,7 @@ subroutine get_command_line_settings(cmd_settings)
204
208
& --list F &
205
209
& --show-model F &
206
210
& --compiler "' // get_env(' FPM_COMPILER' ,' gfortran' )// ' " &
211
+ & --flag:: " "&
207
212
& --verbose F&
208
213
& --' ,help_build,version_text)
209
214
@@ -213,6 +218,7 @@ subroutine get_command_line_settings(cmd_settings)
213
218
cmd_settings= fpm_build_settings( &
214
219
& build_name= val_build,&
215
220
& compiler= val_compiler, &
221
+ & flag= val_flag, &
216
222
& list= lget(' list' ),&
217
223
& show_model= lget(' show-model' ),&
218
224
& verbose= lget(' verbose' ) )
@@ -339,6 +345,7 @@ subroutine get_command_line_settings(cmd_settings)
339
345
call set_args(' --release F --no-rebuild F --verbose F --prefix " " &
340
346
& --list F &
341
347
& --compiler "' // get_env(' FPM_COMPILER' ,' gfortran' )// ' " &
348
+ & --flag:: " "&
342
349
& --libdir "lib" --bindir "bin" --includedir "include"' , &
343
350
help_install, version_text)
344
351
@@ -349,6 +356,7 @@ subroutine get_command_line_settings(cmd_settings)
349
356
list= lget(' list' ), &
350
357
build_name= val_build, &
351
358
compiler= val_compiler, &
359
+ flag= val_flag, &
352
360
no_rebuild= lget(' no-rebuild' ), &
353
361
verbose= lget(' verbose' ))
354
362
call get_char_arg(install_settings% prefix, ' prefix' )
@@ -373,6 +381,7 @@ subroutine get_command_line_settings(cmd_settings)
373
381
& --release F&
374
382
& --runner " " &
375
383
& --compiler "' // get_env(' FPM_COMPILER' ,' gfortran' )// ' " &
384
+ & --flag:: " "&
376
385
& --verbose F&
377
386
& --' ,help_test,version_text)
378
387
@@ -402,6 +411,7 @@ subroutine get_command_line_settings(cmd_settings)
402
411
& args= remaining, &
403
412
& build_name= val_build, &
404
413
& compiler= val_compiler, &
414
+ & flag= val_flag, &
405
415
& example= .false. , &
406
416
& list= lget(' list' ), &
407
417
& name= names, &
@@ -455,7 +465,17 @@ subroutine check_build_vals()
455
465
val_compiler= ' gfortran'
456
466
endif
457
467
458
- val_build= trim (merge (' release' ,' debug ' ,lget(' release' )))
468
+ val_flag = sget(' flag' )
469
+ if (val_flag == ' ' ) then
470
+ call get_default_compile_flags(val_compiler, lget(' release' ), val_flag)
471
+ else
472
+ if (lget(' release' )) then
473
+ write (stdout,' (a)' ) &
474
+ ' <WARNING> --release ignored since explicit --flag argument provided'
475
+ end if
476
+ end if
477
+ allocate (character (len= 16 ) :: val_build)
478
+ write (val_build, ' (z16.16)' ) fnv_1a(val_flag)
459
479
460
480
end subroutine check_build_vals
461
481
@@ -516,17 +536,17 @@ subroutine set_help()
516
536
' ' ]
517
537
help_list_dash = [character (len= 80 ) :: &
518
538
' ' , &
519
- ' build [--compiler COMPILER_NAME] [--release] [--list] ' , &
539
+ ' build [--compiler COMPILER_NAME] [--release] [--flag FFLAGS] [--list] ' , &
520
540
' help [NAME(s)] ' , &
521
541
' new NAME [[--lib|--src] [--app] [--test] [--example]]| ' , &
522
542
' [--full|--bare][--backfill] ' , &
523
543
' update [NAME(s)] [--fetch-only] [--clean] [--verbose] ' , &
524
544
' list [--list] ' , &
525
- ' run [[--target] NAME(s) [--example] [--release] [--all ] [--runner "CMD"] ' , &
526
- ' [--compiler COMPILER_NAME] [--list] [-- ARGS] ' , &
527
- ' test [[--target] NAME(s)] [--release] [--runner "CMD"] [--list] ' , &
545
+ ' run [[--target] NAME(s) [--example] [--release] [--flag FFLAGS ] [--all] ' , &
546
+ ' [--runner "CMD"] [-- compiler COMPILER_NAME] [--list] [-- ARGS] ' , &
547
+ ' test [[--target] NAME(s)] [--release] [--flag FFLAGS] [-- runner "CMD"] [--list]' , &
528
548
' [--compiler COMPILER_NAME] [-- ARGS] ' , &
529
- ' install [--release] [--no-rebuild] [--prefix PATH] [options] ' , &
549
+ ' install [--release] [--flag FFLAGS] [-- no-rebuild] [--prefix PATH] [options] ' , &
530
550
' ' ]
531
551
help_usage= [character (len= 80 ) :: &
532
552
' ' ]
@@ -632,24 +652,26 @@ subroutine set_help()
632
652
' ' , &
633
653
' Their syntax is ' , &
634
654
' ' , &
635
- ' build [--release] [--list] [--compiler COMPILER_NAME] ' , &
655
+ ' build [--release] [--flag FFLAGS] [-- list] [--compiler COMPILER_NAME]' , &
636
656
' new NAME [[--lib|--src] [--app] [--test] [--example]]| ' , &
637
- ' [--full|--bare][--backfill] ' , &
657
+ ' [--full|--bare][--backfill] ' , &
638
658
' update [NAME(s)] [--fetch-only] [--clean] ' , &
639
- ' run [[--target] NAME(s)] [--release] [--list ] [--example ] [--all] ' , &
640
- ' [--runner "CMD"] [--compiler COMPILER_NAME] [-- ARGS] ' , &
641
- ' test [[--target] NAME(s)] [--release] [--list] ' , &
659
+ ' run [[--target] NAME(s)] [--release] [--flag FFLAGS ] [--list ] [--example] ' , &
660
+ ' [--all] [-- runner "CMD"] [--compiler COMPILER_NAME] [-- ARGS] ' , &
661
+ ' test [[--target] NAME(s)] [--release] [--flag FFLAGS] [--list] ' , &
642
662
' [--runner "CMD"] [--compiler COMPILER_NAME] [-- ARGS] ' , &
643
663
' help [NAME(s)] ' , &
644
664
' list [--list] ' , &
645
- ' install [--release] [--no-rebuild] [--prefix PATH] [options] ' , &
665
+ ' install [--release] [--flag FFLAGS] [-- no-rebuild] [--prefix PATH] [options]' , &
646
666
' ' , &
647
667
' SUBCOMMAND OPTIONS ' , &
648
668
' --release Builds or runs in release mode (versus debug mode). fpm(1)' , &
649
- ' Defaults to using common compiler debug flags and building' , &
650
- ' in "build/*_debug/". When this flag is present build ' , &
651
- ' output goes into "build/*_release/" and common compiler ' , &
652
- ' optimization flags are used. ' , &
669
+ ' Defaults to using common compiler debug flags. ' , &
670
+ ' When this flag is present common compiler optimization flags' , &
671
+ ' are used.' , &
672
+ ' --flag FFLAGS Use compile arguments provided in FFLAGS rather than' , &
673
+ ' defaults from debug or release mode, module flags are' , &
674
+ ' provided by fpm(1) and must not be present in FFLAGS' , &
653
675
' --list List candidates instead of building or running them. On ' , &
654
676
' the fpm(1) command this shows a brief list of subcommands.' , &
655
677
' --runner CMD Provides a command to prefix program execution paths. ' , &
@@ -708,8 +730,9 @@ subroutine set_help()
708
730
' run(1) - the fpm(1) subcommand to run project applications ' , &
709
731
' ' , &
710
732
' SYNOPSIS ' , &
711
- ' fpm run [[--target] NAME(s)[--release][--compiler COMPILER_NAME] ' , &
712
- ' [--runner "CMD"] [--example] [--list] [--all] [-- ARGS] ' , &
733
+ ' fpm run [[--target] NAME(s) [--release] [--flag FFLAGS]' , &
734
+ ' [--compiler COMPILER_NAME] [--runner "CMD"] [--example]' , &
735
+ ' [--list] [--all] [-- ARGS]' , &
713
736
' ' , &
714
737
' fpm run --help|--version ' , &
715
738
' ' , &
@@ -734,6 +757,7 @@ subroutine set_help()
734
757
' --all Run all examples or applications. An alias for --target '' *'' . ' , &
735
758
' --example Run example programs instead of applications. ' , &
736
759
' --release selects the optimized build instead of the debug build. ' , &
760
+ ' --flags FFLAGS selects compile arguments for the build' , &
737
761
' --compiler COMPILER_NAME Specify a compiler name. The default is ' , &
738
762
' "gfortran" unless set by the environment ' , &
739
763
' variable FPM_COMPILER. ' , &
@@ -774,7 +798,7 @@ subroutine set_help()
774
798
' build(1) - the fpm(1) subcommand to build a project ' , &
775
799
' ' , &
776
800
' SYNOPSIS ' , &
777
- ' fpm build [--release][--compiler COMPILER_NAME] [-list] ' , &
801
+ ' fpm build [--release] [--flags FFLAGS] [-- compiler COMPILER_NAME] [-list]' , &
778
802
' ' , &
779
803
' fpm build --help|--version ' , &
780
804
' ' , &
@@ -798,6 +822,7 @@ subroutine set_help()
798
822
' OPTIONS ' , &
799
823
' --release build in build/*_release instead of build/*_debug with ' , &
800
824
' high optimization instead of full debug options. ' , &
825
+ ' --flags FFLAGS selects compile arguments for the build' , &
801
826
' --compiler COMPILER_NAME Specify a compiler name. The default is ' , &
802
827
' "gfortran" unless set by the environment ' , &
803
828
' variable FPM_COMPILER. ' , &
@@ -954,8 +979,8 @@ subroutine set_help()
954
979
' test(1) - the fpm(1) subcommand to run project tests ' , &
955
980
' ' , &
956
981
' SYNOPSIS ' , &
957
- ' fpm test [[--target] NAME(s)][--release][--compiler COMPILER_NAME ] ' , &
958
- ' [--runner "CMD"] [--list][-- ARGS] ' , &
982
+ ' fpm test [[--target] NAME(s)] [--release] [--flag FFLAGS] ' , &
983
+ ' [--compiler COMPILER_NAME ] [-- runner "CMD"] [--list][-- ARGS]' , &
959
984
' ' , &
960
985
' fpm test --help|--version ' , &
961
986
' ' , &
@@ -971,8 +996,8 @@ subroutine set_help()
971
996
' any single character and "*" represents any string. ' , &
972
997
' Note The glob string normally needs quoted to ' , &
973
998
' protect the special characters from shell expansion.' , &
974
- ' --release selects the optimized build instead of the debug ' , &
975
- ' build. ' , &
999
+ ' --release selects the optimized build instead of the debug build. ' , &
1000
+ ' --flags FFLAGS selects compile arguments for the build' , &
976
1001
' --compiler COMPILER_NAME Specify a compiler name. The default is ' , &
977
1002
' "gfortran" unless set by the environment ' , &
978
1003
' variable FPM_COMPILER. ' , &
@@ -1021,7 +1046,7 @@ subroutine set_help()
1021
1046
' install(1) - install fpm projects' , &
1022
1047
' ' , &
1023
1048
' SYNOPSIS' , &
1024
- ' fpm install [--release] [--list] [--no-rebuild] [--prefix DIR]' , &
1049
+ ' fpm install [--release] [--flag FFLAGS] [-- list] [--no-rebuild] [--prefix DIR]' , &
1025
1050
' [--bindir DIR] [--libdir DIR] [--includedir DIR]' , &
1026
1051
' [--verbose]' , &
1027
1052
' ' , &
@@ -1036,6 +1061,7 @@ subroutine set_help()
1036
1061
' --list list all installable targets for this project,' , &
1037
1062
' but do not install any of them' , &
1038
1063
' --release selects the optimized build instead of the debug build' , &
1064
+ ' --flags FFLAGS selects compile arguments for the build' , &
1039
1065
' --no-rebuild do not rebuild project before installation' , &
1040
1066
' --prefix DIR path to installation directory (requires write access),' , &
1041
1067
' the default prefix on Unix systems is $HOME/.local' , &
0 commit comments