Skip to content

Commit dc78e5a

Browse files
committed
use CMake presets
1 parent d5c3d4d commit dc78e5a

File tree

7 files changed

+118
-271
lines changed

7 files changed

+118
-271
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/FUNDING.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/ci_cmake.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,29 @@ jobs:
1919
with:
2020
python-version: '3.x'
2121

22-
- run: ctest -S setup.cmake -VV
23-
env:
24-
FC: gfortran-9
25-
CC: gcc-9
26-
CXX: g++-9
22+
- run: cmake --preset=make
23+
- run: cmake --build build --parallel
24+
- run: ctest --parallel 2 --output-on-failure
25+
working-directory: build
26+
2727

2828
macos:
2929
runs-on: macos-latest
3030
steps:
3131
- uses: actions/checkout@v2
3232

33-
- run: ctest -S setup.cmake -VV
34-
env:
35-
FC: gfortran-9
36-
CC: gcc-9
37-
CXX: g++-9
33+
- run: cmake --preset=make
34+
- run: cmake --build build --parallel
35+
- run: ctest --parallel 2 --output-on-failure
36+
working-directory: build
37+
3838

3939
windows:
4040
runs-on: windows-latest
4141
steps:
4242
- uses: actions/checkout@v2
4343

44-
- run: ctest -S setup.cmake -VV
44+
- run: cmake --preset=makewin
45+
- run: cmake --build build --parallel
46+
- run: ctest --parallel 2 --output-on-failure
47+
working-directory: build

.github/workflows/ci_meson.yml

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,8 @@ jobs:
1919
- run: pip install meson ninja
2020

2121
- run: meson setup build
22-
env:
23-
FC: gfortran-9
24-
CC: gcc-9
25-
CXX: g++-9
26-
2722
- run: meson compile -C build
28-
- uses: actions/upload-artifact@v1
29-
if: failure()
30-
with:
31-
name: Linux_Meson_Configlog
32-
path: build/meson-logs/meson-log.txt
33-
3423
- run: meson test -C build -v
35-
- uses: actions/upload-artifact@v1
36-
if: failure()
37-
with:
38-
name: Linux_Meson_Testlog
39-
path: build/meson-logs/testlog.txt
4024

4125
macos:
4226
runs-on: macos-latest
@@ -49,24 +33,8 @@ jobs:
4933
- run: pip install meson ninja
5034

5135
- run: meson setup build
52-
env:
53-
FC: gfortran-9
54-
CC: gcc-9
55-
CXX: g++-9
56-
5736
- run: meson compile -C build
58-
- uses: actions/upload-artifact@v1
59-
if: failure()
60-
with:
61-
name: Mac_Meson_Configlog
62-
path: build/meson-logs/meson-log.txt
63-
6437
- run: meson test -C build -v
65-
- uses: actions/upload-artifact@v1
66-
if: failure()
67-
with:
68-
name: MacOS_Meson_Testlog
69-
path: build/meson-logs/testlog.txt
7038

7139
windows:
7240
runs-on: windows-latest
@@ -79,17 +47,5 @@ jobs:
7947
- run: pip install meson ninja
8048

8149
- run: meson setup build
82-
8350
- run: meson compile -C build
84-
- uses: actions/upload-artifact@v1
85-
if: failure()
86-
with:
87-
name: Windows_Meson_Configlog
88-
path: build/meson-logs/meson-log.txt
89-
9051
- run: meson test -C build -v
91-
- uses: actions/upload-artifact@v1
92-
if: failure()
93-
with:
94-
name: Windows_Meson_Testlog
95-
path: build/meson-logs/testlog.txt

CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
1-
cmake_minimum_required(VERSION 3.15)
2-
project(Fortran_C_CXX_interface
3-
LANGUAGES C Fortran CXX)
4-
enable_testing()
5-
61
# Demonstrate linking of
72
# * C++ calling Fortran
83
# * Fortran calling C++
94
# * Fortran calling C
105

116
# https://stackoverflow.com/tags/fortran-iso-c-binding/info
127

8+
# this also works between ABI compatible compilers e.g. Clang 11.0 and GCC 10.2
9+
10+
# in general, CMake >= 3.14 have better link resolution than CMake 3.13.
11+
cmake_minimum_required(VERSION 3.14)
12+
13+
project(Fortran_C_CXX_interface
14+
LANGUAGES C Fortran CXX)
15+
16+
include(CTest)
17+
18+
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
19+
# this helps show the options are/aren't conflicting between C and Fortran
20+
# at build time
21+
string(APPEND CMAKE_Fortran_FLAGS -fimplicit-none)
22+
endif()
23+
24+
add_compile_options(-Wall)
25+
1326
add_library(c_lib call_c.c)
1427
target_compile_features(c_lib PRIVATE c_std_99)
1528

16-
add_executable(f_call_c f_call_c.f90)
17-
target_link_libraries(f_call_c PRIVATE c_lib)
29+
add_executable(f_call_c f_call_c.f90 $<TARGET_OBJECTS:c_lib>)
1830
add_test(NAME FortranCallC COMMAND f_call_c)
1931

2032
# -- C++ calling Fortran
2133
add_library(call_f OBJECT c_call_f.f90)
2234

23-
add_executable(cxx_call_f cxx_call_f.cxx)
24-
target_link_libraries(cxx_call_f PRIVATE call_f)
35+
add_executable(cxx_call_f cxx_call_f.cxx $<TARGET_OBJECTS:call_f>)
2536
target_compile_features(cxx_call_f PRIVATE cxx_std_11)
2637
add_test(NAME CXXCallFortran COMMAND cxx_call_f)
2738

2839
# -- Fortran calling C++
2940
add_library(cxx_lib OBJECT call_cxx.cxx)
3041
target_compile_features(cxx_lib PRIVATE cxx_std_11)
3142

32-
add_executable(f_call_cxx f_call_cxx.f90)
33-
target_link_libraries(f_call_cxx PRIVATE cxx_lib)
43+
add_executable(f_call_cxx f_call_cxx.f90 $<TARGET_OBJECTS:cxx_lib>)
3444
# LINKER_LANGUAGE option is necessary for ifort at least
3545
set_target_properties(f_call_cxx PROPERTIES LINKER_LANGUAGE Fortran)
3646
add_test(NAME FortranCallC++ COMMAND f_call_cxx)

CMakePresets.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"version": 1,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
9+
"configurePresets": [
10+
{
11+
"name": "_default", "hidden": true,
12+
"binaryDir": "${sourceDir}/build"
13+
},
14+
{
15+
"name": "ninja", "inherits": "_default",
16+
"displayName": "build with Ninja",
17+
"description": "Ninja is faster and more reliable than Make",
18+
"generator": "Ninja"
19+
},
20+
{
21+
"name": "gcc10", "inherits": "ninja",
22+
"displayName": "GCC-10",
23+
"description": "specify GCC version -- helpful for MacOS Homebrew to avoid Clang /usr/bin/gcc",
24+
"environment": {
25+
"CC": "gcc-10",
26+
"CXX": "g++-10",
27+
"FC": "gfortran-10"
28+
}
29+
},
30+
{
31+
"name": "make", "inherits": "_default",
32+
"displayName": "build with GNU Make: Linux/MacOS",
33+
"description": "build with GNU Make on Linux/MacOS",
34+
"generator": "Unix Makefiles"
35+
},
36+
{
37+
"name": "makegcc10", "inherits": ["make", "gcc10"],
38+
"displayName": "build with GNU Make and GCC",
39+
"description": "build with GNU Make and GCC -- useful for MacOS"
40+
},
41+
{
42+
"name": "makewin", "inherits": "_default",
43+
"displayName": "build with GNU Make: Windows",
44+
"description": "build with GNU Make on Windows",
45+
"generator": "MinGW Makefiles"
46+
},
47+
{
48+
"name": "intel", "inherits": "ninja",
49+
"displayName": "Intel Classic compiler: Linux/MacOS",
50+
"description": "build with Intel Classic on Linux/MacOS",
51+
"environment": {
52+
"CC": "icc",
53+
"CXX": "icpc",
54+
"FC": "ifort",
55+
"LAPACK_ROOT": "$env{MKLROOT}",
56+
"MPI_ROOT": "$env{I_MPI_ROOT}"
57+
}
58+
},
59+
{
60+
"name": "intelwin", "inherits": "intel",
61+
"displayName": "Intel Classic compiler: Windows",
62+
"description": "build with Intel Classic on Windows",
63+
"environment": {
64+
"CC": "icl",
65+
"CXX": "icl"
66+
}
67+
},
68+
{
69+
"name": "intelnext", "inherits": "intel",
70+
"displayName": "Intel oneAPI LLVM",
71+
"description": "build with Intel oneAPI NextGen LLVM",
72+
"environment": {
73+
"CC": "icx",
74+
"CXX": "icx",
75+
"FC": "ifx"
76+
}
77+
}
78+
79+
]
80+
81+
82+
83+
}

0 commit comments

Comments
 (0)