@@ -12,7 +12,7 @@ module fpm
1212use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
1313 FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
1414 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
1616
1717
1818use fpm_sources, only: add_executable_sources, add_sources_from_dir
@@ -45,6 +45,7 @@ subroutine build_model(model, settings, package, error)
4545 type (package_config_t) :: dependency
4646 character (len= :), allocatable :: manifest, lib_dir, flags, cflags, cxxflags, ldflags
4747 character (len= :), allocatable :: version
48+ logical :: has_cpp
4849
4950 logical :: duplicates_found = .false.
5051 type (string_t) :: include_dir
@@ -79,8 +80,6 @@ subroutine build_model(model, settings, package, error)
7980 end select
8081 end if
8182
82- call set_preprocessor_flags(model% compiler% id, flags, package)
83-
8483 cflags = trim (settings% cflag)
8584 cxxflags = trim (settings% cxxflag)
8685 ldflags = trim (settings% ldflag)
@@ -92,15 +91,11 @@ subroutine build_model(model, settings, package, error)
9291 end if
9392 model% build_prefix = join_path(" build" , basename(model% compiler% fc))
9493
95- model% fortran_compile_flags = flags
96- model% c_compile_flags = cflags
97- model% cxx_compile_flags = cxxflags
98- model% link_flags = ldflags
99-
10094 model% include_tests = settings% build_tests
10195
10296 allocate (model% packages(model% deps% ndep))
10397
98+ has_cpp = .false.
10499 do i = 1 , model% deps% ndep
105100 associate(dep = > model% deps% dep(i))
106101 manifest = join_path(dep% proj_dir, " fpm.toml" )
@@ -115,8 +110,14 @@ subroutine build_model(model, settings, package, error)
115110
116111 if (allocated (dependency% preprocess)) then
117112 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
119116 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'
120121 end if
121122 end do
122123 end if
@@ -156,6 +157,12 @@ subroutine build_model(model, settings, package, error)
156157 end do
157158 if (allocated (error)) return
158159
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+
159166 ! Add sources from executable directories
160167 if (is_dir(' app' ) .and. package% build% auto_executables) then
161168 call add_sources_from_dir(model% packages(1 )% sources,' app' , FPM_SCOPE_APP, &
0 commit comments