Skip to content

Commit

Permalink
Merge pull request #10 from jchristopherson/fpm
Browse files Browse the repository at this point in the history
Add FPM support
  • Loading branch information
jchristopherson authored Sep 13, 2023
2 parents f2af68c + 6e15098 commit 65b0b37
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 62 deletions.
61 changes: 30 additions & 31 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,47 @@ name: CMake

on:
push:
branches: [ "master" ]
branches: [ "main" ]
pull_request:
branches: [ "master" ]
branches: [ "main" ]

env:
BUILD_TYPE: Release

jobs:
build:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
fortran_compiler: [gfortran, ifort]
os: [ubuntu-latest, macos-latest] # issue with windows-latest & CMake with CMake not recognizing defined compilers
os: [ubuntu-latest, macos-latest]
toolchain:
- {compiler: gcc, version: 11}
- {compiler: intel-classic, version: '2021.9'}
include:
- os: ubuntu-latest
toolchain: {compiler: intel, version: '2023.2'}

steps:

- name: Setup IFORT
if: contains( matrix.fortran_compiler, 'ifort' )
uses: modflowpy/install-intelfortran-action@v1

- name: Setup GFORTRAN
if: contains( matrix.fortran_compiler, 'gfortran')
uses: awvwgk/setup-fortran@main
id: setup-fortran
with:
compiler: gcc
version: 12

env:
FC: ${{ steps.setup-fortran.outputs.fc }}
CC: ${{ steps.setup-fortran.outputs.cc }}

- uses: actions/checkout@v3

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=${{ env.CC }} -DCMAKE_Fortran_COMPILER=${{ env.FC }} -DBUILD_TESTING=TRUE -DBUILD_C_API=TRUE
- uses: awvwgk/setup-fortran@v1
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}

- run: ${{ env.FC }} --version
env:
FC: ${{ steps.setup-fortran.outputs.fc }}
CC: ${{ steps.setup-fortran.outputs.cc }}

- uses: actions/checkout@v3

- name: Build with CMake
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_Fortran_COMPILER=${{ env.FC }} -DBUILD_TESTING=TRUE

- name: Build with CMake
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test with CMake
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
- name: Test with CMake
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
127 changes: 127 additions & 0 deletions .github/workflows/fpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: fpm

on: [push, pull_request]

jobs:
gcc-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-11]
gcc_v: [10] # Version of GFortran we want to use.
include:
- os: ubuntu-latest
os-arch: linux-x86_64

- os: macos-11
os-arch: macos-x86_64

env:
FC: gfortran
GCC_V: ${{ matrix.gcc_v }}

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install GFortran macOS
if: contains(matrix.os, 'macos')
run: |
ln -s /usr/local/bin/gfortran-${GCC_V} /usr/local/bin/gfortran
which gfortran-${GCC_V}
which gfortran
- name: Install GFortran Linux
if: contains(matrix.os, 'ubuntu')
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_V}
- name: Install fpm
uses: fortran-lang/setup-fpm@v3
with:
fpm-version: 'v0.8.2'

- name: Build FERROR
run: |
gfortran --version
fpm build
- name: Run tests
run: |
gfortran --version
fpm test
msys2-build:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v2
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
path-type: inherit
install: |
mingw-w64-x86_64-gcc-fortran
mingw-w64-x86_64-fpm
- name: fpm build
run: |
gfortran --version
fpm --version
fpm build
- name: fpm test
run: |
fpm test
intel-build:
runs-on: ubuntu-latest
strategy:
fail-fast: false

env:
FPM_FC: ifort
FC: ifort

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Add Intel repository (Linux)
run: |
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt-get update
- name: Install Intel oneAPI compiler (Linux)
run: |
sudo apt-get install intel-oneapi-compiler-fortran
- name: Setup Intel oneAPI environment
run: |
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV
- name: Install fpm
uses: fortran-lang/setup-fpm@v3
with:
fpm-version: 'v0.8.2'

- name: fpm build
run: |
ifort --version
fpm --version
fpm build --profile debug --flag "-warn nointerfaces"
- name: fpm test
run: |
fpm test --profile debug --flag "-warn nointerfaces"
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(
LANGUAGES
C
Fortran
VERSION "1.4.1"
VERSION "1.4.2"
)

# Get the macros and functions we'll need
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ A library to assist with error handling in Fortran projects.

## Status
![Build Status](https://github.com/jchristopherson/ferror/actions/workflows/cmake.yml/badge.svg)
[![Actions Status](https://github.com/jchristopherson/ferror/workflows/fpm/badge.svg)](https://github.com/jchristopherson/ferror/actions)

## Usage

Expand Down
11 changes: 9 additions & 2 deletions cmake/helper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function(install_library lib_name lib_install_dir bin_install_dir mod_dir instal
RUNTIME DESTINATION ${bin_install_dir}
LIBRARY DESTINATION ${lib_install_dir}
ARCHIVE DESTINATION ${lib_install_dir}
INCLUDES DESTINATION ${install_dir}/include
)
install(
DIRECTORY ${mod_dir}
Expand All @@ -56,13 +57,19 @@ function(install_documentation doc_dir install_dir)
)
endfunction()

# Links the supplied library
function(link_library targ lib include_dir)
target_link_libraries(${targ} ${lib})
target_include_directories(${targ} PUBLIC $<BUILD_INTERFACE:${include_dir}>)
endfunction()

# ------------------------------------------------------------------------------
# Helpful Macros
macro(print_all_variables)
message(STATUS "---------- CURRENTLY DEFIND VARIABLES -----------")
message(STATUS "---------- CURRENTLY DEFINED VARIABLES -----------")
get_cmake_property(varNames VARIABLES)
foreach(varName ${varNames})
message(STATUS ${varName} = ${${varName}})
endforeach()
message(STATUS "---------- END ----------")
endmacro()
endmacro()
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROJECT_NAME = ferror
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.4.1
PROJECT_NUMBER = 1.4.2

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
27 changes: 27 additions & 0 deletions fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name = "ferror"
version = "1.4.2"
license = "GPL-3.0"
author = "Jason Christopherson"
maintainer = "Jason Christopherson"
copyright = "Copyright 2017-2023, Jason Christopherson"
description = "A library to assist with error handling in Fortran projects."
homepage = "https://github.com/jchristopherson/ferror"

[library]
source-dir = "src"

[[test]]
name = "ferror_test"
source-dir = "test"
main = "ferror_test.f90"

[install]
library = true

[build]
auto-executables = false
auto-examples = false
auto-tests = false

[preprocess]
[preprocess.cpp]
File renamed without changes.
46 changes: 19 additions & 27 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
macro(create_test testname codename)
add_executable(${testname} ${codename})
target_link_libraries(${testname} ferror)
target_include_directories(${testname} PUBLIC ${PROJECT_BINARY_DIR}/include)
add_test(
NAME ${testname}
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:${testname}>
)
endmacro()

macro(create_c_test testname codename)
add_executable(${testname} ${codename})
target_link_libraries(${testname} ferror)
add_test(
NAME ${testname}
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:${testname}>
)
endmacro()
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
add_executable(ferror_test ferror_test.f90)
link_library(ferror_test ${PROJECT_NAME} ${PROJECT_INCLUDE_DIR})
add_test(
NAME ferror_test
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:ferror_test>
)

create_test(ferror_test ferror_test.f90)

if (${BUILD_C_API})
create_test(ferror_test_c ferror_test_c.c)
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
)
add_executable(ferror_test_c C/ferror_test_c.c)
link_library(ferror_test_c ${PROJECT_NAME} ${PROJECT_INCLUDE_DIR})
add_test(
NAME ferror_test_c
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
COMMAND $<TARGET_FILE:ferror_test_c>
)
endif()

0 comments on commit 65b0b37

Please sign in to comment.