Skip to content

Commit

Permalink
Fix CI and update build configuration on Windows (#57)
Browse files Browse the repository at this point in the history
* Join expression into one line

* Let CMake make a build directory

* Use an environment variable for OS library file extension

* Set the FC environment variable to the Fortran conda compiler

* Use Ninja build backend instead of NMake

* Use an object library as the base for shared and static libraries

* Use new location for BMI docs

* Test against files created by flang, not gfortran

* Use an environment variable for the CMake build directory
  • Loading branch information
mdpiper authored Dec 17, 2024
1 parent 99a8678 commit 94df491
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 50 deletions.
57 changes: 23 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ on: [push, pull_request]

env:
BMI_VERSION: 2_0
BUILD_DIR: _build

jobs:
build-test-unix:

if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

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

defaults:
run:
shell: bash -l {0}

env:
SHLIB_EXT: ${{ matrix.os == 'ubuntu-latest' && '.so' || '.dylib' }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
Expand All @@ -35,36 +38,23 @@ jobs:
pkg-config
fortran-compiler
- name: Make cmake build directory
run: cmake -E make_directory build

- name: Configure cmake
working-directory: ${{ github.workspace }}/build
- name: Configure project
run: |
cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release
cmake -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release
- name: Build and install
working-directory: ${{ github.workspace }}/build
run: cmake --build . --target install --config Release
run: cmake --build ${{ env.BUILD_DIR }} --target install --config Release

- name: Test
run: |
test -f $CONDA_PREFIX/include/bmif_$BMI_VERSION.mod
test -s $CONDA_PREFIX/lib/libbmif.a
test -h $CONDA_PREFIX/lib/libbmif${{ env.SHLIB_EXT }}
pkg-config --exists --print-errors bmif
- name: Test (Linux)
if: matrix.os == 'ubuntu-latest'
run: test -h $CONDA_PREFIX/lib/libbmif.so

- name: Test (macOS)
if: matrix.os == 'macos-latest'
run: test -h $CONDA_PREFIX/lib/libbmif.dylib

build-test-windows:
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: windows-latest

Expand All @@ -82,32 +72,31 @@ jobs:
cmake
pkg-config
cxx-compiler
fortran-compiler
init-shell: >-
powershell
- name: Make cmake build directory
run: cmake -E make_directory build
- name: Set the FC environment variable to the Fortran conda compiler
run: |
echo "FC=$CONDA_PREFIX/Library/bin/flang-new.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Configure, build, and install
working-directory: ${{ github.workspace }}/build
- name: Configure, build, and install project
run: |
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build . --target install --config Release
cmake -B ${{ env.BUILD_DIR }} -G Ninja -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build ${{ env.BUILD_DIR }} --target install --config Release
- name: Check (for humans)
working-directory: ${{ github.workspace }}/build
run: |
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmif.a
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmif_win.dll.a
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\libbmif_win.dll
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmif.lib
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\bmif.dll
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmif_${{ env.BMI_VERSION }}.mod
Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmif_static.lib
pkg-config --exists --print-errors bmif
- name: Test (for machines)
working-directory: ${{ github.workspace }}/build
run: |
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmif.a ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmif_win.dll.a ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\libbmif_win.dll ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmif.lib ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\bmif.dll ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmif_${{ env.BMI_VERSION }}.mod ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmif_static.lib ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\bmif.pc ) ){ exit 1 }
30 changes: 15 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ configure_file(
# Create static and shared libraries.
set(static_lib ${CMAKE_PROJECT_NAME}_static)
set(shared_lib ${CMAKE_PROJECT_NAME}_shared)
add_library(${static_lib} bmi.f90)
add_library(${shared_lib} SHARED bmi.f90)
add_library(obj_lib OBJECT bmi.f90)
add_library(${static_lib} STATIC $<TARGET_OBJECTS:obj_lib>)
add_library(${shared_lib} SHARED $<TARGET_OBJECTS:obj_lib>)

# Change the output names of the libraries. On Windows, they can't
# have the same name, so change the shared library name.
set_target_properties(${static_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME})
set_target_properties(${static_lib}
PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME}
VERSION ${CMAKE_PROJECT_VERSION}
)
if(WIN32)
set_target_properties(${shared_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME}_win)
else()
set_target_properties(${shared_lib} PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME})
set_target_properties(${static_lib}
PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME}_static
)
endif()

set_target_properties(${static_lib} PROPERTIES
VERSION ${CMAKE_PROJECT_VERSION}
)
set_target_properties(${shared_lib} PROPERTIES
set_target_properties(${shared_lib}
PROPERTIES
OUTPUT_NAME ${CMAKE_PROJECT_NAME}
VERSION ${CMAKE_PROJECT_VERSION}
PUBLIC_HEADER ${CMAKE_BINARY_DIR}/${mod_name}.mod
)
Expand Down
2 changes: 1 addition & 1 deletion bmif.pc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ includedir=${prefix}/include

Name: bmi-fortran
Description: The Basic Model Interface for Fortran
URL: https://bmi.readthedocs.io
URL: https://bmi.csdms.io
Version: @CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@
Libs: -L${libdir} -l@CMAKE_PROJECT_NAME@
Cflags: -I${includedir}

0 comments on commit 94df491

Please sign in to comment.