-
Notifications
You must be signed in to change notification settings - Fork 108
feat: added support for C++ files compilation #733
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
Conversation
- Added support for C++ files compilation.
- Added test for the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @arteevraina - you got that done quickly! All looks to be going in the right direction to me. A few minor comments:
-
We don't need a new parsing routine
parse_cpp_source
; we can just reuse theparse_c_source
and add logic to setunit_type
based on the filename suffix. (So we also don't need a new unit test either.) -
We still need to add in a linker flag for the C++ standard library if we do have cpp sources files.
-
Can you add a new test package with C++ source files and add it to
run_tests.sh
? -
For everyone's information: fpm currently doesn't recompile C files if their include files change (it doesn't track changes to include files), and the same issue will affect cpp files - but that is a separate issue to this PR (see Improve support for include statements #358).
Thanks for the review @LKedward. I have addressed the changes mentioned in the comment. Let me know if any further changes are required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good @arteevraina - I've left a few minor comments. I might have a think about how we can make the cpp example package more interesting so that it actually using the c++ standard library, perhaps using std::vector or something.
Oh one more thing: can you update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Well done. In addtion to @LKedward 's comments, here are a couple of minor comments.
Spotted another thing: you need to update this logic to use cpp_compiler_flags for cpp targets: Lines 728 to 732 in 97ea8ce
|
I've created a PR to update the cpp example package in arteevraina#2. This can be merged after the above comments have been addressed. |
Uses std:vector and std:algorithm to check that the cpp standard library is linked and called correctly.
Sure thing, I will add this in a separate Pull Request and update it for all the recently added examples. |
Thanks again for the review @LKedward @jvdp1 I have done the requested changes and also merged your PR here. But, the CI is failing for compile tests for this package in macos. |
Great stuff Arteev @arteevraina. I'll take a look at the MacOS issue and see if I can figure out what's going on. |
if (get_os_type() == OS_MACOS) then | ||
model%link_libraries = [model%link_libraries, string_t("c++")] | ||
else | ||
model%link_libraries = [model%link_libraries, string_t("stdc++")] | ||
end if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this generally true? In case we are using clang++, g++ or icpc on MacOS do we always need -lc++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I don't have an answer unfortunately but it's not a blocker for this PR. I'm know very little about the MacOS ecosystem and I don't have a Mac to test these things out. A quick test in the CI shows that it works with clang++ as well as g++ on MacOS-11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that last sentence, it wasn't actually testing clang++ when I used --cpp-compiler=clang++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, with that fixed I've tried it again and clang++ works on MacOS with -lc++
. I can't comment on other compiler combinations, and how supported that is in C++.
Co-authored-by: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com>
I'm not sure why, but I can't seem to get the |
It seem be that diff --git a/src/fpm.f90 b/src/fpm.f90
index 497cb6a0..74306501 100644
--- a/src/fpm.f90
+++ b/src/fpm.f90
@@ -216,11 +216,13 @@ subroutine build_model(model, settings, package, error)
if (allocated(error)) return
if (settings%verbose) then
- write(*,*)'<INFO> BUILD_NAME: ',model%build_prefix
+ write(*,*)'<INFO> BUILD_NAME: ',model%build_prefix
write(*,*)'<INFO> COMPILER: ',model%compiler%fc
write(*,*)'<INFO> C COMPILER: ',model%compiler%cc
+ write(*,*)'<INFO> CXX COMPILER: ',model%compiler%cxx
write(*,*)'<INFO> COMPILER OPTIONS: ', model%fortran_compile_flags
write(*,*)'<INFO> C COMPILER OPTIONS: ', model%c_compile_flags
+ write(*,*)'<INFO> CXX COMPILER OPTIONS: ', model%cpp_compile_flags
write(*,*)'<INFO> LINKER OPTIONS: ', model%link_flags
write(*,*)'<INFO> INCLUDE DIRECTORIES: [', string_cat(model%include_dirs,','),']'
end if
diff --git a/src/fpm_command_line.f90 b/src/fpm_command_line.f90
index 7401f54c..c34931a7 100644
--- a/src/fpm_command_line.f90
+++ b/src/fpm_command_line.f90
@@ -302,6 +302,7 @@ contains
& prune=.not.lget('no-prune'), &
& compiler=val_compiler, &
& c_compiler=c_compiler, &
+ & cpp_compiler=cpp_compiler, &
& archiver=archiver, &
& flag=val_flag, &
& cflag=val_cflag, &
@@ -332,6 +333,7 @@ contains
& prune=.not.lget('no-prune'), &
& compiler=val_compiler, &
& c_compiler=c_compiler, &
+ & cpp_compiler=cpp_compiler, &
& archiver=archiver, &
& flag=val_flag, &
& cflag=val_cflag, &
@@ -488,6 +490,7 @@ contains
prune=.not.lget('no-prune'), &
compiler=val_compiler, &
c_compiler=c_compiler, &
+ cpp_compiler=cpp_compiler, &
archiver=archiver, &
flag=val_flag, &
cflag=val_cflag, &
@@ -545,6 +548,7 @@ contains
& prune=.not.lget('no-prune'), &
& compiler=val_compiler, &
& c_compiler=c_compiler, &
+ & cpp_compiler=cpp_compiler, &
& archiver=archiver, &
& flag=val_flag, &
& cflag=val_cflag, & Set the cxx compiler and query the cxx compiler in CMake. CMake calls the cxx compiler "CXX compiler". Maybe we need to unify diff --git a/src/fpm.f90 b/src/fpm.f90
index 497cb6a0..74306501 100644
--- a/src/fpm.f90
+++ b/src/fpm.f90
@@ -216,11 +216,13 @@ subroutine build_model(model, settings, package, error)
if (allocated(error)) return
if (settings%verbose) then
- write(*,*)'<INFO> BUILD_NAME: ',model%build_prefix
+ write(*,*)'<INFO> BUILD_NAME: ',model%build_prefix
write(*,*)'<INFO> COMPILER: ',model%compiler%fc
write(*,*)'<INFO> C COMPILER: ',model%compiler%cc
+ write(*,*)'<INFO> CPP COMPILER: ',model%compiler%cxx
write(*,*)'<INFO> COMPILER OPTIONS: ', model%fortran_compile_flags
write(*,*)'<INFO> C COMPILER OPTIONS: ', model%c_compile_flags
+ write(*,*)'<INFO> CPP COMPILER OPTIONS: ', model%cpp_compile_flags
write(*,*)'<INFO> LINKER OPTIONS: ', model%link_flags
write(*,*)'<INFO> INCLUDE DIRECTORIES: [', string_cat(model%include_dirs,','),']'
end if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really remarkable work, LGTM, thanks @arteevraina .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing, great work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thank you @arteevraina
Great work Arteev @arteevraina - I will now merge. Some future things to consider for c++ suppport are:
|
Sure thing. |