From 762b1cdb1078292e70d493d36a66683b44ac9392 Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:04:02 -0500 Subject: [PATCH 1/7] Add FPM support --- .github/workflows/fpm.yml | 127 ++++++++++++++++++++++++++++++++++++++ fpm.toml | 24 +++++++ 2 files changed, 151 insertions(+) create mode 100644 .github/workflows/fpm.yml create mode 100644 fpm.toml 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/fpm.toml b/fpm.toml new file mode 100644 index 0000000..81967e2 --- /dev/null +++ b/fpm.toml @@ -0,0 +1,24 @@ +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 \ No newline at end of file From 11ea7962654d669c300ca7e862770f1c5310790b Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:16:08 -0500 Subject: [PATCH 2/7] Update cmake.yml --- .github/workflows/cmake.yml | 61 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 31 deletions(-) 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 From 98a1e49ad5c6baf5dcd227790bc9671de06031a9 Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:22:44 -0500 Subject: [PATCH 3/7] Add preprocessor support --- fpm.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fpm.toml b/fpm.toml index 81967e2..1601b72 100644 --- a/fpm.toml +++ b/fpm.toml @@ -21,4 +21,7 @@ library = true [build] auto-executables = false auto-examples = false -auto-tests = false \ No newline at end of file +auto-tests = false + +[preprocess] +[preprocess.cpp] From c437e465ff2c5c81cd33d3ade3fe119b7ef31164 Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:44:01 -0500 Subject: [PATCH 4/7] Clean up CMake --- cmake/helper.cmake | 11 +++++++-- test/{ => C}/ferror_test_c.c | 0 test/CMakeLists.txt | 46 +++++++++++++++--------------------- 3 files changed, 28 insertions(+), 29 deletions(-) rename test/{ => C}/ferror_test_c.c (100%) 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/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() From 596ddff4de03abac15bbb1b33bfbdc212cb5bda6 Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:48:42 -0500 Subject: [PATCH 5/7] Add FPM badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c4f227a..e755616 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 From 6e150981de83c6c2de2e8dc073111c7d9f0f2045 Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 10:49:20 -0500 Subject: [PATCH 6/7] Update version information --- CMakeLists.txt | 2 +- docs/Doxyfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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 From 79f8c22c446107460ba951d9f702320cffc14b4c Mon Sep 17 00:00:00 2001 From: jchristopherson Date: Wed, 13 Sep 2023 11:31:15 -0500 Subject: [PATCH 7/7] Update README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e755616..f2154e2 100644 --- a/README.md +++ b/README.md @@ -117,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/).