Skip to content

Commit e2f00d8

Browse files
authored
Merge pull request #743 from LKedward/fix-exe-linking
Fix executables linking
2 parents 2570975 + fc11893 commit e2f00d8

File tree

15 files changed

+190
-0
lines changed

15 files changed

+190
-0
lines changed

ci/run_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ pushd submodules
9292
"$fpm" build
9393
popd
9494

95+
pushd app_with_submodule
96+
"$fpm" run --all
97+
popd
98+
9599
pushd program_with_module
96100
"$fpm" build
97101
"$fpm" run --target Program_with_module
@@ -118,6 +122,10 @@ pushd c_main
118122
"$fpm" run
119123
popd
120124

125+
pushd app_with_c
126+
"$fpm" run
127+
popd
128+
121129
pushd hello_fpm_path
122130
"$fpm" run
123131
popd

example_packages/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ the features demonstrated in each package and which versions of fpm are supporte
66

77
| Name | Features | Bootstrap (Haskell) fpm | fpm |
88
|---------------------|---------------------------------------------------------------|:-----------------------:|:---:|
9+
| app_with_c | C files located in app directory (not src) | N | Y |
10+
| app_with_submodule | Submodules located in app directory (not src) | N | Y |
911
| auto_discovery_off | Default layout with auto-discovery disabled | N | Y |
1012
| c_header_only | C header-only library | N | Y |
1113
| c_includes | C library with c include directory and dependency includes | N | Y |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <sys/stat.h>
2+
/*
3+
* Decides whether a given file name is a directory.
4+
* return 1 if file exists and is a directory
5+
* Source (Public domain): https://github.com/urbanjost/M_system
6+
*/
7+
int my_isdir(const char *path)
8+
{
9+
struct stat sb;
10+
return stat(path, &sb) == 0 && S_ISDIR(sb.st_mode);
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module with_c
2+
use iso_c_binding, only: c_char, c_int, c_null_char
3+
implicit none
4+
5+
contains
6+
7+
function system_isdir(dirname)
8+
! Source (Public domain): https://github.com/urbanjost/M_system
9+
!
10+
implicit none
11+
character(len=*), intent(in) :: dirname
12+
logical :: system_isdir
13+
14+
interface
15+
function c_isdir(dirname) bind(C, name="my_isdir") result(c_ierr)
16+
import c_char, c_int
17+
character(kind=c_char, len=1), intent(in) :: dirname(*)
18+
integer(kind=c_int) :: c_ierr
19+
end function c_isdir
20+
end interface
21+
22+
system_isdir = c_isdir(trim(dirname)//c_null_char) == 1
23+
24+
end function system_isdir
25+
26+
end module with_c
27+
28+
program with_c_app
29+
use with_c
30+
implicit none
31+
32+
write (*, *) "isdir('app') = ", system_isdir('app')
33+
write (*, *) "isdir('src') = ", system_isdir('src')
34+
write (*, *) "isdir('test') = ", system_isdir('test')
35+
write (*, *) "isdir('bench') = ", system_isdir('bench')
36+
37+
end program with_c_app

example_packages/app_with_c/fpm.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "with_c"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/*
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
submodule(parent) child1
2+
implicit none
3+
4+
interface
5+
module function my_fun() result (b)
6+
integer :: b
7+
end function my_fun
8+
end interface
9+
10+
contains
11+
12+
module procedure my_sub1
13+
a = my_fun()
14+
end procedure my_sub1
15+
16+
end submodule child1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
submodule(parent:child1) grandchild
2+
implicit none
3+
4+
contains
5+
6+
module procedure my_fun
7+
b = 1
8+
end procedure my_fun
9+
10+
end submodule grandchild
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program test
2+
use parent
3+
implicit none
4+
5+
integer :: a
6+
7+
call my_sub1(a)
8+
9+
if (a /= 1) then
10+
write(*,*) 'FAILED: Unexpected value of a'
11+
stop 1
12+
end if
13+
14+
end program test

0 commit comments

Comments
 (0)