Skip to content

Commit 64ce7b9

Browse files
authored
Respect user provided main-files (#646)
- add example package for C-main
1 parent 32401f1 commit 64ce7b9

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

ci/run_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,9 @@ pushd c_header_only
9898
"$fpm" build
9999
popd
100100

101+
pushd c_main
102+
"$fpm" run
103+
popd
104+
101105
# Cleanup
102106
rm -rf ./*/build

example_packages/c_main/app/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int
2+
main (void)
3+
{
4+
return 0;
5+
}

example_packages/c_main/fpm.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name = "c-main"
2+
3+
[[executable]]
4+
name = "c-main"
5+
main = "main.c"

src/fpm_sources.f90

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,23 @@ subroutine add_executable_sources(sources,executables,scope,auto_discover,error)
163163
if (allocated(executables(i)%link)) then
164164
sources(j)%link_libraries = executables(i)%link
165165
end if
166+
sources(j)%unit_type = FPM_UNIT_PROGRAM
166167
cycle exe_loop
167168

168169
end if
169170

170171
end do
171172

172173
! Add if not already discovered (auto_discovery off)
173-
exe_source = parse_source(join_path(executables(i)%source_dir,executables(i)%main),error)
174-
exe_source%exe_name = executables(i)%name
175-
if (allocated(executables(i)%link)) then
176-
exe_source%link_libraries = executables(i)%link
177-
end if
178-
exe_source%unit_scope = scope
174+
associate(exe => executables(i))
175+
exe_source = parse_source(join_path(exe%source_dir,exe%main),error)
176+
exe_source%exe_name = exe%name
177+
if (allocated(exe%link)) then
178+
exe_source%link_libraries = exe%link
179+
end if
180+
exe_source%unit_type = FPM_UNIT_PROGRAM
181+
exe_source%unit_scope = scope
182+
end associate
179183

180184
if (allocated(error)) return
181185

0 commit comments

Comments
 (0)