From 64ce7b9da5826b3b728d470ae11994c23e234440 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Mon, 10 Jan 2022 08:13:42 +0100 Subject: Respect user provided main-files (#646) - add example package for C-main --- ci/run_tests.sh | 4 ++++ example_packages/c_main/app/main.c | 5 +++++ example_packages/c_main/fpm.toml | 5 +++++ src/fpm_sources.f90 | 16 ++++++++++------ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 example_packages/c_main/app/main.c create mode 100644 example_packages/c_main/fpm.toml diff --git a/ci/run_tests.sh b/ci/run_tests.sh index ff477e7..9525422 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -98,5 +98,9 @@ pushd c_header_only "$fpm" build popd +pushd c_main +"$fpm" run +popd + # Cleanup rm -rf ./*/build diff --git a/example_packages/c_main/app/main.c b/example_packages/c_main/app/main.c new file mode 100644 index 0000000..398ec67 --- /dev/null +++ b/example_packages/c_main/app/main.c @@ -0,0 +1,5 @@ +int +main (void) +{ + return 0; +} diff --git a/example_packages/c_main/fpm.toml b/example_packages/c_main/fpm.toml new file mode 100644 index 0000000..eb18e9b --- /dev/null +++ b/example_packages/c_main/fpm.toml @@ -0,0 +1,5 @@ +name = "c-main" + +[[executable]] +name = "c-main" +main = "main.c" diff --git a/src/fpm_sources.f90 b/src/fpm_sources.f90 index f349a0e..af2870f 100644 --- a/src/fpm_sources.f90 +++ b/src/fpm_sources.f90 @@ -163,6 +163,7 @@ subroutine add_executable_sources(sources,executables,scope,auto_discover,error) if (allocated(executables(i)%link)) then sources(j)%link_libraries = executables(i)%link end if + sources(j)%unit_type = FPM_UNIT_PROGRAM cycle exe_loop end if @@ -170,12 +171,15 @@ subroutine add_executable_sources(sources,executables,scope,auto_discover,error) end do ! Add if not already discovered (auto_discovery off) - exe_source = parse_source(join_path(executables(i)%source_dir,executables(i)%main),error) - exe_source%exe_name = executables(i)%name - if (allocated(executables(i)%link)) then - exe_source%link_libraries = executables(i)%link - end if - exe_source%unit_scope = scope + associate(exe => executables(i)) + exe_source = parse_source(join_path(exe%source_dir,exe%main),error) + exe_source%exe_name = exe%name + if (allocated(exe%link)) then + exe_source%link_libraries = exe%link + end if + exe_source%unit_type = FPM_UNIT_PROGRAM + exe_source%unit_scope = scope + end associate if (allocated(error)) return -- cgit v1.2.3