Skip to content

Commit 1c211f6

Browse files
authored
Merge pull request #779 from fortran-lang/gnikit/issue777
bug: macros don't propage to C executables
2 parents 49f2ff3 + 7295d34 commit 1c211f6

File tree

6 files changed

+61
-31
lines changed

6 files changed

+61
-31
lines changed

ci/run_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ pushd preprocess_cpp
138138
"$fpm" build
139139
popd
140140

141+
pushd preprocess_cpp_c
142+
"$fpm" run
143+
popd
144+
141145
pushd preprocess_hello
142146
"$fpm" build
143147
popd

example_packages/README.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,37 @@
33
See the table below for a list of the example packages provided in this directory including
44
the features demonstrated in each package and which versions of fpm are supported.
55

6-
7-
| Name | Features | Bootstrap (Haskell) fpm | fpm |
8-
|---------------------|---------------------------------------------------------------|:-----------------------:|:---:|
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 |
11-
| auto_discovery_off | Default layout with auto-discovery disabled | N | Y |
12-
| c_header_only | C header-only library | N | Y |
13-
| c_includes | C library with c include directory and dependency includes | N | Y |
14-
| circular_example | Local path dependency; circular dependency | Y | Y |
15-
| circular_test | Local path dependency; circular dependency | Y | Y |
16-
| fortran_includes | Fortran library with explicit include directory | Y | N |
17-
| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y |
18-
| hello_complex_2 | Auto-discovery of tests and executables with modules | N | Y |
19-
| hello_fpm | App-only; local path dependency | Y | Y |
20-
| hello_world | App-only | Y | Y |
21-
| with_examples | Example-only | Y | Y |
22-
| makefile_complex | External build command (makefile); local path dependency | Y | N |
23-
| program_with_module | App-only; module+program in single source file | Y | Y |
24-
| submodules | Lib-only; submodules (3 levels) | N | Y |
25-
| tree_shake | Test tree-shaking/pruning of unused module dependencies | N | Y |
26-
| submodule_tree_shake| Test tree-shaking/pruning with submodules dependencies | N | Y |
27-
| link_external | Link external library | N | Y |
28-
| link_executable | Link external library to a single executable | N | Y |
29-
| version_file | Read version number from a file in the project root | N | Y |
30-
| with_c | Compile with `c` source files | N | Y |
31-
| with_makefile | External build command (makefile) | Y | N |
32-
| preprocess_cpp | Lib only; C preprocessing; Macro parsing | N | Y |
33-
| preprocess_hello | App only; Macros remain local to the package | N | Y |
34-
| preprocess_hello_dependency | Lib only; Macros not getting passed here from root | N | Y |
35-
| cpp_files | C++ files get compiled using fpm | N | Y |
6+
| Name | Features | Bootstrap (Haskell) fpm | fpm |
7+
| --------------------------- | ------------------------------------------------------------- | :---------------------: | :-: |
8+
| app_with_c | C files located in app directory (not src) | N | Y |
9+
| app_with_submodule | Submodules located in app directory (not src) | N | Y |
10+
| auto_discovery_off | Default layout with auto-discovery disabled | N | Y |
11+
| c_header_only | C header-only library | N | Y |
12+
| c_includes | C library with c include directory and dependency includes | N | Y |
13+
| circular_example | Local path dependency; circular dependency | Y | Y |
14+
| circular_test | Local path dependency; circular dependency | Y | Y |
15+
| c_main | C App | N | Y |
16+
| c_main_preprocess | C App; propagate command line preprocessor macros to the app | N | Y |
17+
| cpp_files | C++ files get compiled using fpm | N | Y |
18+
| fortran_includes | Fortran library with explicit include directory | Y | N |
19+
| fpm_test_exe_issues | Test parse order of module files and apps | N | Y |
20+
| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y |
21+
| hello_complex_2 | Auto-discovery of tests and executables with modules | N | Y |
22+
| hello_fpm | App-only; local path dependency | Y | Y |
23+
| hello_fpm_path | Define local path dependencies | N | Y |
24+
| hello_world | App-only | Y | Y |
25+
| link_executable | Link external library to a single executable | N | Y |
26+
| link_external | Link external library | N | Y |
27+
| makefile_complex | External build command (makefile); local path dependency | Y | N |
28+
| preprocess_cpp | Lib only; C preprocessing; Macro parsing | N | Y |
29+
| preprocess_cpp_c | C App; progate macros from fpm.toml to app | N | Y |
30+
| preprocess_hello | App only; Macros remain local to the package | N | Y |
31+
| preprocess_hello_dependency | Lib only; Macros not getting passed here from root | N | Y |
32+
| program_with_module | App-only; module+program in single source file | Y | Y |
33+
| submodules | Lib-only; submodules (3 levels) | N | Y |
34+
| submodule_tree_shake | Test tree-shaking/pruning with submodules dependencies | N | Y |
35+
| tree_shake | Test tree-shaking/pruning of unused module dependencies | N | Y |
36+
| version_file | Read version number from a file in the project root | N | Y |
37+
| with_c | Compile with `c` source files | N | Y |
38+
| with_examples | Example-only | Y | Y |
39+
| with_makefile | External build command (makefile) | Y | N |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdio.h>
2+
3+
#include "val.h"
4+
5+
int main() { printf("%d\n", variable); }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "preprocess_cpp_c"
2+
3+
[[executable]]
4+
name = "main"
5+
main = "main.c"
6+
7+
[preprocess]
8+
[preprocess.cpp]
9+
macros = ["VAL"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef _VAL_H_
2+
#define _VAL_H_
3+
4+
#ifdef VAL
5+
const int variable = 1;
6+
#endif
7+
#endif

src/fpm_targets.f90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ subroutine build_target_list(targets,model)
278278

279279
call add_target(targets,package=model%packages(j)%name,type = exe_type,&
280280
output_name = get_object_name(sources(i)), &
281-
source = sources(i) &
281+
source = sources(i), &
282+
macros = model%packages(j)%macros &
282283
)
283284

284285
if (sources(i)%unit_scope == FPM_SCOPE_APP) then

0 commit comments

Comments
 (0)