Skip to content

Commit

Permalink
improve install and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Feb 11, 2021
1 parent b28f769 commit 8e63a01
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 34 deletions.
71 changes: 58 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: ci
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
CMAKE_GENERATOR: Ninja

on:
push:
Expand All @@ -9,33 +10,54 @@ on:
- "**.cmake"
- "**.f90"
- ".github/workflows/ci.yml"
release:
types: published


jobs:

linux:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- run: |
sudo apt update -yq
sudo apt install -yq --no-install-recommends gfortran libnetcdff-dev
sudo apt install -yq --no-install-recommends ninja-build gfortran libnetcdff-dev
- run: cmake -B build
- run: cmake -B build -DCMAKE_INSTALL_PREFIX=~/hdf5
- run: cmake --build build --parallel

- run: cmake --install build
- run: ctest --parallel 2 --output-on-failure
working-directory: build

- name: build examples
run: |
cmake -B Examples/build -S Examples
cmake --build Examples/build
- name: test examples
run: ctest -V
- name: configure examples
run: cmake -S Examples -B Examples/build -Dnc4fortran_ROOT=~/hdf5
- name: build exmaples
run: cmake --build Examples/build --parallel
- name: Test examples
run: ctest --parallel 2 --output-on-failure
working-directory: Examples/build

- name: create package
run: cpack --config build/CPackConfig.cmake

- name: get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Upload release asset
if: github.event.action == 'published'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./nc4fortran-${{ steps.get_version.outputs.VERSION }}-Linux.zip
asset_name: nc4fortran-${{ steps.get_version.outputs.VERSION }}-Linux.zip
asset_content_type: application/zip



mac:
needs: linux
Expand All @@ -45,8 +67,31 @@ jobs:

- run: brew install gcc netcdf ninja

- run: cmake -B build
- run: cmake -B build -DCMAKE_INSTALL_PREFIX=~/hdf5
- run: cmake --build build --parallel

- run: cmake --install build
- run: ctest --parallel 2 --output-on-failure
working-directory: build

- run: cmake -S Examples -B Examples/build -Dnc4fortran_ROOT=~/hdf5
- run: cmake --build Examples/build --parallel
- run: ctest --parallel 2 --output-on-failure
working-directory: Examples/build

- name: create package
run: cpack --config build/CPackConfig.cmake

- name: get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Upload release asset
if: github.event.action == 'published'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./nc4fortran-${{ steps.get_version.outputs.VERSION }}-Darwin.zip
asset_name: nc4fortran-${{ steps.get_version.outputs.VERSION }}-Darwin.zip
asset_content_type: application/zip
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ include(cmake/install.cmake)

include(FeatureSummary)
set_package_properties(NetCDF PROPERTIES URL "https://www.unidata.ucar.edu/software/netcdf/" DESCRIPTION "fast, versatile file I/O format")
feature_summary(WHAT ENABLED_FEATURES PACKAGES_FOUND)
feature_summary(WHAT ENABLED_FEATURES)
15 changes: 7 additions & 8 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ find_c_fortran()

project(nc4fortranExample
LANGUAGES Fortran)
enable_testing()

include(CTest)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/Modules)

# see if ncfortran is installed; build if not found
find_package(nc4fortran CONFIG)

if(nc4fortran_FOUND)
include(${nc4fortran_DIR}/nc4fortranTargets.cmake)
else()
include(FetchContent)
FetchContent_Declare(nc4fortran_proj
GIT_REPOSITORY https://github.com/geospace-code/nc4fortran.git
GIT_TAG v1.1.2)
FetchContent_MakeAvailable(nc4fortran_proj)
endif()

if(NOT TARGET nc4fortran::nc4fortran)
message(FATAL_ERROR "NetCDF4 is not working on your system, so nc4fortran cannot work.")
message(FATAL_ERROR "nc4fortran not found.")
endif()

find_package(NetCDF COMPONENTS Fortran REQUIRED)

# --- Fortran interface for examples
add_library(fortran_interface fortran_interface.f90)
target_link_libraries(fortran_interface PRIVATE nc4fortran::nc4fortran)
Expand Down
20 changes: 11 additions & 9 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ install(FILES

# --- CPack

if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CPACK_GENERATOR ZIP)
set(CPACK_PACKAGE_VENDOR "Michael Hirsch")
set(CPACK_PACKAGE_CONTACT "Michael Hirsch")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libnetcdff-dev")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
include(CPack)
endif()
set(CPACK_GENERATOR ZIP)
set(CPACK_PACKAGE_VENDOR "Michael Hirsch")
set(CPACK_PACKAGE_CONTACT "Michael Hirsch")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libnetcdff-dev")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE}
DESTINATION share/docs/${PROJECT_NAME})

include(CPack)
3 changes: 0 additions & 3 deletions cmake/nc4fortranConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@PACKAGE_INIT@

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
include(${CMAKE_CURRENT_LIST_DIR}/netcdf.cmake)

check_required_components(h5fortran)

0 comments on commit 8e63a01

Please sign in to comment.