@@ -12,7 +12,7 @@ module fpm
12
12
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
13
13
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
14
14
FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST
15
- use fpm_compiler, only: new_compiler, new_archiver, set_preprocessor_flags
15
+ use fpm_compiler, only: new_compiler, new_archiver, set_cpp_preprocessor_flags
16
16
17
17
18
18
use fpm_sources, only: add_executable_sources, add_sources_from_dir
@@ -45,6 +45,7 @@ subroutine build_model(model, settings, package, error)
45
45
type (package_config_t) :: dependency
46
46
character (len= :), allocatable :: manifest, lib_dir, flags, cflags, cxxflags, ldflags
47
47
character (len= :), allocatable :: version
48
+ logical :: has_cpp
48
49
49
50
logical :: duplicates_found = .false.
50
51
type (string_t) :: include_dir
@@ -79,8 +80,6 @@ subroutine build_model(model, settings, package, error)
79
80
end select
80
81
end if
81
82
82
- call set_preprocessor_flags(model% compiler% id, flags, package)
83
-
84
83
cflags = trim (settings% cflag)
85
84
cxxflags = trim (settings% cxxflag)
86
85
ldflags = trim (settings% ldflag)
@@ -92,15 +91,11 @@ subroutine build_model(model, settings, package, error)
92
91
end if
93
92
model% build_prefix = join_path(" build" , basename(model% compiler% fc))
94
93
95
- model% fortran_compile_flags = flags
96
- model% c_compile_flags = cflags
97
- model% cxx_compile_flags = cxxflags
98
- model% link_flags = ldflags
99
-
100
94
model% include_tests = settings% build_tests
101
95
102
96
allocate (model% packages(model% deps% ndep))
103
97
98
+ has_cpp = .false.
104
99
do i = 1 , model% deps% ndep
105
100
associate(dep = > model% deps% dep(i))
106
101
manifest = join_path(dep% proj_dir, " fpm.toml" )
@@ -115,8 +110,14 @@ subroutine build_model(model, settings, package, error)
115
110
116
111
if (allocated (dependency% preprocess)) then
117
112
do j = 1 , size (dependency% preprocess)
118
- if (package% preprocess(j)% name == " cpp" .and. allocated (dependency% preprocess(j)% macros)) then
113
+ if (dependency% preprocess(j)% name == " cpp" ) then
114
+ if (.not. has_cpp) has_cpp = .true.
115
+ if (allocated (dependency% preprocess(j)% macros)) then
119
116
model% packages(i)% macros = dependency% preprocess(j)% macros
117
+ end if
118
+ else
119
+ write (stderr, ' (a)' ) ' Warning: Preprocessor ' // package% preprocess(i)% name // &
120
+ ' is not supported; will ignore it'
120
121
end if
121
122
end do
122
123
end if
@@ -156,6 +157,12 @@ subroutine build_model(model, settings, package, error)
156
157
end do
157
158
if (allocated (error)) return
158
159
160
+ if (has_cpp) call set_cpp_preprocessor_flags(model% compiler% id, flags)
161
+ model% fortran_compile_flags = flags
162
+ model% c_compile_flags = cflags
163
+ model% cxx_compile_flags = cxxflags
164
+ model% link_flags = ldflags
165
+
159
166
! Add sources from executable directories
160
167
if (is_dir(' app' ) .and. package% build% auto_executables) then
161
168
call add_sources_from_dir(model% packages(1 )% sources,' app' , FPM_SCOPE_APP, &
0 commit comments