Skip to content

Commit 9842deb

Browse files
authored
Introduce compilation profile and add flag option (#390)
Exploratory implementation of --flag and --profile for Fortran fpm.
2 parents 70346eb + 5d36af8 commit 9842deb

File tree

9 files changed

+660
-361
lines changed

9 files changed

+660
-361
lines changed

ci/run_tests.bat

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ del /q /f build
3939
%fpm_path% build
4040
if errorlevel 1 exit 1
4141

42-
.\build\gfortran_debug\app\hello_world
42+
%fpm_path% run --target hello_world
4343
if errorlevel 1 exit 1
4444

4545
%fpm_path% run
@@ -53,7 +53,7 @@ del /q /f build
5353
%fpm_path% build
5454
if errorlevel 1 exit 1
5555

56-
.\build\gfortran_debug\app\hello_fpm
56+
%fpm_path% run --target hello_fpm
5757
if errorlevel 1 exit 1
5858

5959

@@ -83,16 +83,16 @@ if errorlevel 1 exit 1
8383
%fpm_path% test
8484
if errorlevel 1 exit 1
8585

86-
.\build\gfortran_debug\app\say_Hello
86+
%fpm_path% run --target say_Hello
8787
if errorlevel 1 exit 1
8888

89-
.\build\gfortran_debug\app\say_goodbye
89+
%fpm_path% run --target say_goodbye
9090
if errorlevel 1 exit 1
9191

92-
.\build\gfortran_debug\test\greet_test
92+
%fpm_path% test --target greet_test
9393
if errorlevel 1 exit 1
9494

95-
.\build\gfortran_debug\test\farewell_test
95+
%fpm_path% test --target farewell_test
9696
if errorlevel 1 exit 1
9797

9898

@@ -103,16 +103,16 @@ del /q /f build
103103
%fpm_path% build
104104
if errorlevel 1 exit 1
105105

106-
.\build\gfortran_debug\app\say_hello_world
106+
%fpm_path% run --target say_hello_world
107107
if errorlevel 1 exit 1
108108

109-
.\build\gfortran_debug\app\say_goodbye
109+
%fpm_path% run --target say_goodbye
110110
if errorlevel 1 exit 1
111111

112-
.\build\gfortran_debug\test\greet_test
112+
%fpm_path% test --target greet_test
113113
if errorlevel 1 exit 1
114114

115-
.\build\gfortran_debug\test\farewell_test
115+
%fpm_path% test --target farewell_test
116116

117117

118118
cd ..\with_examples
@@ -122,10 +122,10 @@ del /q /f build
122122
%fpm_path% build
123123
if errorlevel 1 exit 1
124124

125-
.\build\gfortran_debug\example\demo-prog
125+
%fpm_path% run --example --target demo-prog
126126
if errorlevel 1 exit 1
127127

128-
.\build\gfortran_debug\app\demo-prog
128+
%fpm_path% run --target demo-prog
129129
if errorlevel 1 exit 1
130130

131131

@@ -136,15 +136,15 @@ del /q /f build
136136
%fpm_path% build
137137
if errorlevel 1 exit 1
138138

139-
.\build\gfortran_debug\app\auto_discovery_off
139+
%fpm_path% run --target auto_discovery_off
140140
if errorlevel 1 exit 1
141141

142-
.\build\gfortran_debug\test\my_test
142+
%fpm_path% test --target my_test
143143
if errorlevel 1 exit 1
144144

145-
if exist .\build\gfortran_debug\app\unused exit /B 1
145+
if exist .\build\gfortran_*\app\unused exit /B 1
146146

147-
if exist .\build\gfortran_debug\test\unused_test exit /B 1
147+
if exist .\build\gfortran_*\test\unused_test exit /B 1
148148

149149

150150
cd ..\with_c
@@ -154,7 +154,7 @@ del /q /f build
154154
%fpm_path% build
155155
if errorlevel 1 exit 1
156156

157-
.\build\gfortran_debug\app\with_c
157+
%fpm_path% run --target with_c
158158
if errorlevel 1 exit 1
159159

160160

@@ -173,7 +173,7 @@ del /q /f build
173173
%fpm_path% build
174174
if errorlevel 1 exit 1
175175

176-
.\build\gfortran_debug\app\Program_with_module
176+
%fpm_path% run --target Program_with_module
177177
if errorlevel 1 exit 1
178178

179179

@@ -184,7 +184,7 @@ del /q /f build
184184
%fpm_path% build
185185
if errorlevel 1 exit 1
186186

187-
.\build\gfortran_debug\app\gomp_test
187+
%fpm_path% run --target gomp_test
188188
if errorlevel 1 exit 1
189189

190190
cd ..\..

ci/run_tests.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ rm -rf ./*/build
3030
cd hello_world
3131

3232
"${f_fpm_path}" build
33-
./build/gfortran_debug/app/hello_world
33+
"${f_fpm_path}" run --target hello_world
3434
"${f_fpm_path}" run
3535

3636
cd ../hello_fpm
3737
"${f_fpm_path}" build
38-
./build/gfortran_debug/app/hello_fpm
38+
"${f_fpm_path}" run --target hello_fpm
3939

4040
cd ../circular_test
4141
"${f_fpm_path}" build
@@ -46,48 +46,48 @@ cd ../circular_example
4646
cd ../hello_complex
4747
"${f_fpm_path}" build
4848
"${f_fpm_path}" test
49-
./build/gfortran_debug/app/say_Hello
50-
./build/gfortran_debug/app/say_goodbye
51-
./build/gfortran_debug/test/greet_test
52-
./build/gfortran_debug/test/farewell_test
49+
"${f_fpm_path}" run --target say_Hello
50+
"${f_fpm_path}" run --target say_goodbye
51+
"${f_fpm_path}" test --target greet_test
52+
"${f_fpm_path}" test --target farewell_test
5353

5454
cd ../hello_complex_2
5555
"${f_fpm_path}" build
56-
./build/gfortran_debug/app/say_hello_world
57-
./build/gfortran_debug/app/say_goodbye
58-
./build/gfortran_debug/test/greet_test
59-
./build/gfortran_debug/test/farewell_test
56+
"${f_fpm_path}" run --target say_hello_world
57+
"${f_fpm_path}" run --target say_goodbye
58+
"${f_fpm_path}" test --target greet_test
59+
"${f_fpm_path}" test --target farewell_test
6060

6161
cd ../with_examples
6262
"${f_fpm_path}" build
63-
./build/gfortran_debug/example/demo-prog
64-
./build/gfortran_debug/app/demo-prog
63+
"${f_fpm_path}" run --example --target demo-prog
64+
"${f_fpm_path}" run --target demo-prog
6565

6666
cd ../auto_discovery_off
6767
"${f_fpm_path}" build
68-
./build/gfortran_debug/app/auto_discovery_off
69-
./build/gfortran_debug/test/my_test
70-
test ! -x ./build/gfortran_debug/app/unused
71-
test ! -x ./build/gfortran_debug/test/unused_test
68+
"${f_fpm_path}" run --target auto_discovery_off
69+
"${f_fpm_path}" test --target my_test
70+
test ! -x ./build/gfortran_*/app/unused
71+
test ! -x ./build/gfortran_*/test/unused_test
7272

7373
cd ../with_c
7474
"${f_fpm_path}" build
75-
./build/gfortran_debug/app/with_c
75+
"${f_fpm_path}" run --target with_c
7676

7777
cd ../submodules
7878
"${f_fpm_path}" build
7979

8080
cd ../program_with_module
8181
"${f_fpm_path}" build
82-
./build/gfortran_debug/app/Program_with_module
82+
"${f_fpm_path}" run --target Program_with_module
8383

8484
cd ../link_external
8585
"${f_fpm_path}" build
86-
./build/gfortran_debug/app/link_external
86+
"${f_fpm_path}" run --target link_external
8787

8888
cd ../link_executable
8989
"${f_fpm_path}" build
90-
./build/gfortran_debug/app/gomp_test
90+
"${f_fpm_path}" run --target gomp_test
9191

9292
# Cleanup
9393
rm -rf ./*/build

fpm/src/fpm.f90

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module fpm
99
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
1010
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
1111
FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST
12-
use fpm_compiler, only: add_compile_flag_defaults
12+
use fpm_compiler, only: get_module_flags, is_unknown_compiler
1313

1414

1515
use fpm_sources, only: add_executable_sources, add_sources_from_dir
@@ -62,9 +62,17 @@ subroutine build_model(model, settings, package, error)
6262
model%fortran_compiler = settings%compiler
6363
endif
6464

65+
if (is_unknown_compiler(model%fortran_compiler)) then
66+
write(*, '(*(a:,1x))') &
67+
"<WARN>", "Unknown compiler", model%fortran_compiler, "requested!", &
68+
"Defaults for this compiler might be incorrect"
69+
end if
6570
model%output_directory = join_path('build',basename(model%fortran_compiler)//'_'//settings%build_name)
6671

67-
call add_compile_flag_defaults(settings%build_name, basename(model%fortran_compiler), model)
72+
call get_module_flags(model%fortran_compiler, &
73+
& join_path(model%output_directory,model%package_name), &
74+
& model%fortran_compile_flags)
75+
model%fortran_compile_flags = settings%flag // model%fortran_compile_flags
6876
if(settings%verbose)then
6977
write(*,*)'<INFO>COMPILER OPTIONS: ', model%fortran_compile_flags
7078
endif

0 commit comments

Comments
 (0)