Skip to content

Commit f964dfe

Browse files
authored
Rebuild with flang 19 (#22)
* Set a build directory for cmake * Build on Windows with bmi-fortran from conda * Explicitly request flang >=19 * Remove space between package name and version * Revert to conda fortran compiler * Set the FC environment variable * Use status messages * Use object libraries for test fixtures and example helpers * Remove fixtures.mod artifact * Use library names from flang, not gfortran * Run ctest from source directory * Simplify build/install instructions with CMake
1 parent 98b4e33 commit f964dfe

File tree

6 files changed

+54
-73
lines changed

6 files changed

+54
-73
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ name: Build/Test
22

33
on: [push, pull_request]
44

5+
env:
6+
BUILD_DIR: _build
7+
58
jobs:
69
build-test-unix:
710
if:
8-
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
9-
github.repository
11+
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
1012

1113
runs-on: ${{ matrix.os }}
1214

@@ -25,7 +27,7 @@ jobs:
2527
steps:
2628
- uses: actions/checkout@v4
2729

28-
- uses: mamba-org/setup-micromamba@v1
30+
- uses: mamba-org/setup-micromamba@v2
2931
with:
3032
micromamba-version: latest
3133
environment-name: testing
@@ -35,19 +37,14 @@ jobs:
3537
fortran-compiler
3638
bmi-fortran
3739
38-
- name: Make CMake build directory
39-
run: cmake -E make_directory build
40-
41-
- name: Configure CMake
42-
working-directory: ${{ github.workspace }}/build
40+
- name: Configure project
4341
run: |
44-
cmake $GITHUB_WORKSPACE \
42+
cmake $GITHUB_WORKSPACE -B ${{ env.BUILD_DIR }} \
4543
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
4644
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
4745
48-
- name: Build
49-
working-directory: ${{ github.workspace }}/build
50-
run: cmake --build . --target install --config ${{ matrix.build-type }}
46+
- name: Build and install project
47+
run: cmake --build ${{ env.BUILD_DIR }} --target install --config ${{ matrix.build-type }}
5148

5249
- name: Test for installed files
5350
run: |
@@ -58,9 +55,8 @@ jobs:
5855
test -f $CONDA_PREFIX/include/bmiheatf.mod
5956
test -f $CONDA_PREFIX/lib/pkgconfig/bmiheatf.pc
6057
61-
- name: Run CTest
62-
working-directory: ${{ github.workspace }}/build
63-
run: ctest -C ${{ matrix.build-type }} --output-on-failure
58+
- name: Run project tests
59+
run: ctest --test-dir ${{ env.BUILD_DIR }} -C ${{ matrix.build-type }} --output-on-failure
6460

6561
- name: Memcheck
6662
if: matrix.os == 'ubuntu-latest'
@@ -78,8 +74,7 @@ jobs:
7874
7975
build-test-windows:
8076
if:
81-
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
82-
github.repository
77+
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
8378

8479
runs-on: windows-latest
8580

@@ -89,52 +84,42 @@ jobs:
8984
steps:
9085
- uses: actions/checkout@v4
9186
- uses: ilammy/msvc-dev-cmd@v1
92-
- uses: mamba-org/setup-micromamba@v1
87+
- uses: mamba-org/setup-micromamba@v2
9388
with:
9489
micromamba-version: latest
9590
environment-name: testing
9691
create-args: >-
9792
cmake
9893
pkg-config
9994
cxx-compiler
95+
fortran-compiler
96+
bmi-fortran
10097
init-shell: >-
10198
powershell
10299
103-
# The Fortran conda compiler doesn't seem to work on Windows in Actions.
104-
# Instead, use the gfortran installed by chocolately. However, we then
105-
# can't use the bmi-fortran package from conda-forge because it's not
106-
# ABI-compatible. So, build bmi-fortran locally, This is a hack
107-
# workaround.
108-
- name: Build the bmi-fortran specification locally
100+
- name: Set the FC environment variable to the Fortran conda compiler
101+
run: |
102+
echo "FC=$env:CONDA_PREFIX\Library\bin\flang-new.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
103+
104+
- name: List current environment variables
109105
run: |
110-
curl -o bmi-fortran.zip -L https://github.com/csdms/bmi-fortran/archive/refs/heads/master.zip
111-
unzip bmi-fortran.zip
112-
cd bmi-fortran-master
113-
mkdir build && cd build
114-
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
115-
cmake --build . --target install --config Release
116-
cd ${{ github.workspace }}
117-
118-
- name: Make cmake build directory
119-
run: cmake -E make_directory build
120-
121-
- name: Configure, build, and install
122-
working-directory: ${{ github.workspace }}/build
106+
ls env:
107+
108+
- name: Configure, build, and install project
123109
run: |
124-
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
125-
cmake --build . --target install --config Release
110+
cmake -B ${{ env.BUILD_DIR }} -LA -G Ninja -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
111+
cmake --build ${{ env.BUILD_DIR }} --target install --config Release
126112
127113
- name: Test for installed files
128114
run: |
129-
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libheatf.a ) ){ exit 1 }
115+
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\heatf.lib ) ){ exit 1 }
130116
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_heatf.exe ) ){ exit 1 }
131117
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\heatf.mod ) ){ exit 1 }
132118
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\heatf.pc ) ){ exit 1 }
133119
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_bmiheatf.exe ) ){ exit 1 }
134-
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmiheatf.a ) ){ exit 1 }
120+
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmiheatf.lib ) ){ exit 1 }
135121
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmiheatf.mod ) ){ exit 1 }
136122
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\bmiheatf.pc ) ){ exit 1 }
137123
138124
- name: Run CTest
139-
working-directory: ${{ github.workspace }}/build
140-
run: ctest -C Release -VV --output-on-failure
125+
run: ctest --test-dir ${{ env.BUILD_DIR }} -C Release -VV --output-on-failure

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ set(bmi_name bmi${model_name})
1515
find_package(PkgConfig REQUIRED)
1616
pkg_check_modules(BMIF REQUIRED IMPORTED_TARGET bmif)
1717
string(REPLACE "." "_" bmif_module_version ${BMIF_VERSION})
18-
message("-- bmif module version - ${bmif_module_version}")
19-
message("-- bmif library path - ${BMIF_LINK_LIBRARIES}")
20-
message("-- bmif include dir - ${BMIF_INCLUDE_DIRS}")
18+
message(STATUS " bmif module version - ${bmif_module_version}")
19+
message(STATUS " bmif library path - ${BMIF_LINK_LIBRARIES}")
20+
message(STATUS " bmif include dir - ${BMIF_INCLUDE_DIRS}")
2121
include_directories(${BMIF_INCLUDE_DIRS})
2222

2323
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)

README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
An example of implementing the
77
[Fortran bindings](https://github.com/csdms/bmi-fortran)
8-
for the CSDMS
9-
[Basic Model Interface](https://bmi-spec.readthedocs.io) (BMI).
10-
8+
for the CSDMS [Basic Model Interface](https://bmi.csdms.io) (BMI).
119

1210
## Overview
1311

@@ -50,22 +48,21 @@ This example can be built on Linux, macOS, and Windows.
5048

5149
### CMake - Linux and macOS
5250

53-
To build this example from source with CMake,
51+
To configure and build this example from source with CMake,
5452
using the current Fortran BMI version, run
5553

56-
mkdir _build && cd _build
57-
cmake .. -DCMAKE_INSTALL_PREFIX=<path-to-installation>
58-
make
54+
cmake -B _build -DCMAKE_INSTALL_PREFIX=<path-to-installation>
55+
cmake --build _build
5956

6057
where `<path-to-installation>` is the base directory
6158
in which the Fortran BMI bindings have been installed
6259
(`/usr/local` is the default).
6360
When installing into a conda environment,
6461
use the `$CONDA_PREFIX` environment variable.
6562

66-
Then, to install (on both Linux and macOS):
63+
Then, to install:
6764

68-
make install
65+
cmake --install _build
6966

7067
The installation will look like
7168
(on macOS, using v2.0 of the Fortran BMI specification):
@@ -81,8 +78,8 @@ The installation will look like
8178
| `-- heatf.mod
8279
`-- lib
8380
|-- libbmif.a
84-
|-- libbmif.2.0.2.dylib
85-
|-- libbmif.dylib -> libbmif.2.0.2.dylib
81+
|-- libbmif.2.1.4.dylib
82+
|-- libbmif.dylib -> libbmif.2.1.4.dylib
8683
|-- libbmiheatf.dylib
8784
|-- libheatf.dylib
8885
`-- pkgconfig
@@ -91,41 +88,36 @@ The installation will look like
9188
`-- heatf.pc
9289
```
9390

94-
From the build directory,
95-
run unit tests and examples of using the sample implementation with
91+
Run unit tests and examples of using the sample implementation with
9692

97-
ctest
93+
ctest --test-dir _build
9894

9995
### CMake - Windows
10096

10197
An additional prerequisite is needed for Windows:
10298

10399
* Microsoft Visual Studio 2017 or Microsoft Build Tools for Visual Studio 2017
104100

105-
To configure this example from source with cmake
101+
To configure and build this example from source with CMake
106102
using the current Fortran BMI version,
107103
run the following in a [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)
108104

109-
mkdir _build && cd _build
110-
cmake .. ^
111-
-G "NMake Makefiles" ^
112-
-DCMAKE_INSTALL_PREFIX=<path-to-installation> ^
113-
-DCMAKE_BUILD_TYPE=Release
105+
cmake -B _build -L -G Ninja -DCMAKE_INSTALL_PREFIX=<path-to-installation>
106+
cmake --build _build
114107

115108
where `<path-to-installation>` is the base directory
116109
in which the Fortran BMI bindings have been installed.
117110
The default is `"C:\Program Files (x86)"`.
118111
Note that quotes and an absolute path are needed.
119112
When using a conda environment, use `"%CONDA_PREFIX%\Library"`.
120113

121-
Then, to build and install:
114+
Then, to install:
122115

123-
cmake --build . --target install --config Release
116+
cmake --install _build
124117

125-
From the build directory,
126-
run unit tests and examples of using the sample implementation with
118+
Run unit tests and examples of using the sample implementation with
127119

128-
ctest
120+
ctest --test-dir _build
129121

130122

131123
### Fortran Package Manager (fpm)

example/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ include(CTest)
22

33
include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})
44

5+
add_library(helpers OBJECT testing_helpers.f90)
6+
57
function(make_example example_name)
68
add_test(NAME ${example_name} COMMAND ${example_name} ${CMAKE_CURRENT_SOURCE_DIR})
7-
add_executable(${example_name} ${example_name}.f90 testing_helpers.f90)
9+
add_executable(${example_name} ${example_name}.f90 $<TARGET_OBJECTS:helpers>)
810
target_link_libraries(${example_name} ${bmi_name})
911
endfunction(make_example)
1012

test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ include(CTest)
22

33
include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})
44

5+
add_library(fixtures OBJECT fixtures.f90)
6+
57
function(make_test test_name)
68
add_test(NAME ${test_name} COMMAND ${test_name} "${CMAKE_CURRENT_SOURCE_DIR}/sample.cfg")
7-
add_executable(${test_name} ${test_name}.f90 fixtures.f90)
9+
add_executable(${test_name} ${test_name}.f90 $<TARGET_OBJECTS:fixtures>)
810
target_link_libraries(${test_name} ${bmi_name})
911
endfunction(make_test)
1012

test/fixtures.mod

-618 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)