Skip to content

Commit c99b276

Browse files
committed
Fix: collision between app and example executables of the same name
Use a separate example subdirectory in 'build' to store example executables.
1 parent 58cc203 commit c99b276

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

ci/run_tests.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ del /q /f build
116116
%fpm_path% build
117117
if errorlevel 1 exit 1
118118

119+
.\build\gfortran_debug\example\demo-prog
120+
if errorlevel 1 exit 1
121+
119122
.\build\gfortran_debug\app\demo-prog
120123
if errorlevel 1 exit 1
121124

ci/run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cd ../hello_complex_2
5252

5353
cd ../with_examples
5454
"${f_fpm_path}" build
55+
./build/gfortran_debug/example/demo-prog
5556
./build/gfortran_debug/app/demo-prog
5657

5758
cd ../auto_discovery_off
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
program demo
2+
write(*, '(a)') "This is a simple program"
3+
end program demo

example_packages/with_examples/demo/prog.f90

Lines changed: 0 additions & 3 deletions
This file was deleted.

example_packages/with_examples/fpm.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@ build.auto-examples = false
33

44
[[example]]
55
name = "demo-prog"
6-
source-dir = "demo"
7-
main = "prog.f90"
8-
9-
[[example]]
10-
name = "example-prog"
116
source-dir = "example"
127
main = "prog.f90"

fpm/src/fpm_targets.f90

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ subroutine targets_from_sources(model,sources)
6262
type(srcfile_t), intent(in) :: sources(:)
6363

6464
integer :: i
65-
character(:), allocatable :: xsuffix
65+
character(:), allocatable :: xsuffix, exe_dir
6666
type(build_target_t), pointer :: dep
6767
logical :: with_lib
6868

@@ -99,18 +99,24 @@ subroutine targets_from_sources(model,sources)
9999
source = sources(i) &
100100
)
101101

102-
if (any(sources(i)%unit_scope == [FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE])) then
103-
call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&
104-
link_libraries = sources(i)%link_libraries, &
105-
output_file = join_path(model%output_directory,'app', &
106-
sources(i)%exe_name//xsuffix))
102+
if (sources(i)%unit_scope == FPM_SCOPE_APP) then
103+
104+
exe_dir = 'app'
105+
106+
else if (sources(i)%unit_scope == FPM_SCOPE_EXAMPLE) then
107+
108+
exe_dir = 'example'
109+
107110
else
108-
call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&
111+
112+
exe_dir = 'test'
113+
114+
end if
115+
116+
call add_target(model%targets,type = FPM_TARGET_EXECUTABLE,&
109117
link_libraries = sources(i)%link_libraries, &
110-
output_file = join_path(model%output_directory,'test', &
118+
output_file = join_path(model%output_directory,exe_dir, &
111119
sources(i)%exe_name//xsuffix))
112-
113-
end if
114120

115121
! Executable depends on object
116122
call add_dependency(model%targets(size(model%targets))%ptr, model%targets(size(model%targets)-1)%ptr)

0 commit comments

Comments
 (0)