Skip to content

Commit 1f2831f

Browse files
arteevrainazoziha
andauthored
feat: ability to read macros from manifest (#720)
Co-authored-by: zoziha <[email protected]>
1 parent 3045817 commit 1f2831f

File tree

15 files changed

+278
-18
lines changed

15 files changed

+278
-18
lines changed

ci/run_tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,13 @@ pushd c_main
118118
"$fpm" run
119119
popd
120120

121+
pushd preprocess_cpp
122+
"$fpm" build
123+
popd
124+
125+
pushd preprocess_hello
126+
"$fpm" build
127+
popd
128+
121129
# Cleanup
122130
rm -rf ./*/build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
name = "preprocess_cpp"
22

3+
version = "1"
4+
35
[preprocess]
46
[preprocess.cpp]
7+
macros = ["TESTMACRO", "TESTMACRO2=3", "TESTMACRO3={version}"]

example_packages/preprocess_cpp/src/preprocess_cpp.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,14 @@ subroutine say_hello
99
#ifndef TESTMACRO
1010
This breaks the build.
1111
#endif
12+
13+
#if TESTMACRO2 != 3
14+
This breaks the build.
15+
#endif
16+
17+
#if TESTMACRO3 != 1
18+
This breaks the build.
19+
#endif
20+
1221
end subroutine say_hello
1322
end module preprocess_cpp
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# preprocess_hello
2+
My cool new project!
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
program preprocess_hello
2+
use preprocess_hello_dependency, only: say_hello
3+
4+
implicit none
5+
call say_hello()
6+
end program preprocess_hello
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name = "preprocess_hello"
2+
3+
[preprocess]
4+
[preprocess.cpp]
5+
macros = ["FOO"]
6+
7+
[dependencies]
8+
preprocess_hello_dependency = { path = "../preprocess_hello_dependency" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# preprocess_hello_dependency
2+
My cool new project!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name = "preprocess_hello_dependency"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module preprocess_hello_dependency
2+
implicit none
3+
private
4+
5+
public :: say_hello
6+
contains
7+
subroutine say_hello
8+
9+
!> If this build fails, then it implies that macros are getting passed to the dependency.
10+
#ifdef FOO
11+
This breaks the build inside dependency. This implies that macros are getting passed to the dependeny.
12+
#endif
13+
print *, "Hello, preprocess_hello_dependency!"
14+
end subroutine say_hello
15+
end module preprocess_hello_dependency

src/fpm.f90

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ subroutine build_model(model, settings, package, error)
4444
integer :: i, j
4545
type(package_config_t) :: dependency
4646
character(len=:), allocatable :: manifest, lib_dir, flags, cflags, ldflags
47+
character(len=:), allocatable :: version
4748

4849
logical :: duplicates_found = .false.
4950
type(string_t) :: include_dir
@@ -78,7 +79,7 @@ subroutine build_model(model, settings, package, error)
7879
end select
7980
end if
8081

81-
call set_preprocessor_flags(model%compiler%id, flags)
82+
call set_preprocessor_flags(model%compiler%id, flags, package)
8283

8384
cflags = trim(settings%cflag)
8485
ldflags = trim(settings%ldflag)
@@ -166,6 +167,17 @@ subroutine build_model(model, settings, package, error)
166167
if (allocated(error)) exit
167168

168169
model%packages(i)%name = dependency%name
170+
call package%version%to_string(version)
171+
model%packages(i)%version = version
172+
173+
if (allocated(dependency%preprocess)) then
174+
do j = 1, size(dependency%preprocess)
175+
if (package%preprocess(j)%name == "cpp") then
176+
model%packages(i)%macros = dependency%preprocess(j)%macros
177+
end if
178+
end do
179+
end if
180+
169181
if (.not.allocated(model%packages(i)%sources)) allocate(model%packages(i)%sources(0))
170182

171183
if (allocated(dependency%library)) then

0 commit comments

Comments
 (0)