diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 88ec640..12f654b 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -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}} \ No newline at end of file diff --git a/.github/workflows/fpm.yml b/.github/workflows/fpm.yml new file mode 100644 index 0000000..4e76797 --- /dev/null +++ b/.github/workflows/fpm.yml @@ -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" \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ac6ef5..7f7628f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project( LANGUAGES C Fortran - VERSION "1.4.1" + VERSION "1.4.2" ) # Get the macros and functions we'll need diff --git a/README.md b/README.md index c4f227a..f2154e2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -116,5 +117,15 @@ The error code is: 200 [Meson](https://mesonbuild.com/index.html) can also be used to build this library. See [this](https://mesonbuild.com/Quick-guide.html) quick start guid on how to use Meson. +[FPM](https://github.com/fortran-lang/fpm) can also be used to build this library using the provided fpm.toml. +```txt +fpm build +``` +The FERROR library can be used within your FPM project by adding the following to your fpm.toml file. +``` +[dependencies] +ferror = { git = "https://github.com/jchristopherson/ferror" } +``` + ## Documentation The documentation can be found [here](https://jchristopherson.github.io/ferror/). diff --git a/cmake/helper.cmake b/cmake/helper.cmake index 4711ee5..a21692c 100644 --- a/cmake/helper.cmake +++ b/cmake/helper.cmake @@ -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} @@ -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 $) +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() \ No newline at end of file +endmacro() diff --git a/docs/Doxyfile b/docs/Doxyfile index 5aaa537..3e7b121 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -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 diff --git a/fpm.toml b/fpm.toml new file mode 100644 index 0000000..1601b72 --- /dev/null +++ b/fpm.toml @@ -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] diff --git a/test/ferror_test_c.c b/test/C/ferror_test_c.c similarity index 100% rename from test/ferror_test_c.c rename to test/C/ferror_test_c.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 13461cb..083e676 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 $ - ) -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 $ - ) -endmacro() +include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake") -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - $ +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 $ ) -create_test(ferror_test ferror_test.f90) - if (${BUILD_C_API}) - create_test(ferror_test_c ferror_test_c.c) -endif() \ No newline at end of file + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + $ + ) + 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 $ + ) +endif()