8000 bug: C preprocessor does not propagate directives to executables by gnikit · Pull Request #775 · fortran-lang/fpm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bug: C preprocessor does not propagate directives to executables #775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
build/*

# Visual Studio Code
.vscode/
4 changes: 4 additions & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ pushd c_main
"$fpm" run
popd

pushd c_main_preprocess
"$fpm" build --c-flag "-DVAL"
popd

pushd app_with_c
"$fpm" run
popd
Expand Down
7 changes: 7 additions & 0 deletions example_packages/c_main_preprocess/app/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

#include "val.h"

int main() {
printf("%d\n", variable);
}
7 changes: 7 additions & 0 deletions example_packages/c_main_preprocess/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "c_main_preprocess"
[library]
include-dir = ["src"]

[[executable]]
name="main-c"
main="main.c"
1 change: 1 addition & 0 deletions example_packages/c_main_preprocess/src/stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "val.h"
7 changes: 7 additions & 0 deletions example_packages/c_main_preprocess/src/val.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _VAL_H_
#define _VAL_H_

#ifdef VAL
const int variable = 1;
#endif
#endif
14 changes: 11 additions & 3 deletions src/fpm_targets.f90
A95F
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module fpm_targets
use fpm_model
use fpm_environment, only: get_os_type, OS_WINDOWS, OS_MACOS
use fpm_filesystem, only: dirname, join_path, canon_path
use fpm_strings, only: string_t, operator(.in.), string_cat, fnv_1a, resize
use fpm_strings, only: string_t, operator(.in.), string_cat, fnv_1a, resize, lower, str_ends_with
use fpm_compiler, only: get_macros
implicit none

Expand Down Expand Up @@ -189,7 +189,7 @@ subroutine build_target_list(targets,model)
!> The package model from which to construct the target list
type(fpm_model_t), intent(inout), target :: model

integer :: i, j, n_source
integer :: i, j, n_source, exe_type
character(:), allocatable :: xsuffix, exe_dir
logical :: with_lib

Expand Down Expand Up @@ -268,7 +268,15 @@ subroutine build_target_list(targets,model)

case (FPM_UNIT_PROGRAM)

call add_target(targets,package=model%packages(j)%name,type = FPM_TARGET_OBJECT,&
if (str_ends_with(lower(sources(i)%file_name), [".c"])) then
exe_type = FPM_TARGET_C_OBJECT
else if (str_ends_with(lower(sources(i)%file_name), [".cpp", ".cc "])) then
exe_type = FPM_TARGET_CPP_OBJECT
else ! Default to a Fortran object
exe_type = FPM_TARGET_OBJECT
end if

call add_target(targets,package=model%packages(j)%name,type = exe_type,&
output_name = get_object_name(sources(i)), &
source = sources(i) &
)
Expand Down
0