From e45f5ccd354b4c4a3530c1202f4a97e9b8e4e969 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 11 Mar 2024 14:55:48 -0600 Subject: [PATCH 01/11] Use pkg-config to find installed bmi-fortran spec --- CMakeLists.txt | 24 +++++++----------------- bmi_heat/CMakeLists.txt | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cffe4c..af7d232 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,26 +12,16 @@ include(GNUInstallDirs) set(model_name heatf) set(bmi_name bmi${model_name}) -# Determine the Fortran BMI version. -if(DEFINED ENV{BMIF_VERSION}) - set(bmif_version $ENV{BMIF_VERSION}) -else() - set(bmif_version "2.0") -endif() -string(REPLACE "." "_" bmif_module_version ${bmif_version}) -message("-- BMIF version - ${bmif_version}") -message("-- BMIF module version - ${bmif_module_version}") +find_package(PkgConfig REQUIRED) +pkg_check_modules(BMIF REQUIRED IMPORTED_TARGET bmif) +string(REPLACE "." "_" bmif_module_version ${BMIF_VERSION}) +message("-- bmif module version - ${bmif_module_version}") +message("-- bmif library path - ${BMIF_LINK_LIBRARIES}") +message("-- bmif include dir - ${BMIF_INCLUDE_DIRS}") +include_directories(${BMIF_INCLUDE_DIRS}) set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod) -# Locate the installed Fortran BMI bindings (bmif library and module file) -# through CMAKE_PREFIX_PATH. -find_library(bmif_lib bmif) -find_path(bmif_inc bmif_${bmif_module_version}.mod) -include_directories(${bmif_inc}) -message("-- bmif_lib - ${bmif_lib}") -message("-- bmif_inc - ${bmif_inc}") - add_subdirectory(heat) add_subdirectory(bmi_heat) add_subdirectory(test) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 8f86d3b..178e226 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -6,7 +6,7 @@ if(WIN32) else() add_library(${bmi_name} SHARED bmi_heat.f90) endif() -target_link_libraries(${bmi_name} ${model_name} ${bmif_lib}) +target_link_libraries(${bmi_name} ${model_name} ${BMIF_LINK_LIBRARIES}) add_executable(run_${bmi_name} bmi_main.f90) target_link_libraries(run_${bmi_name} ${bmi_name}) From 113fcc9eafbd49931525b967fb38dcf7f6c59557 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 11 Mar 2024 15:38:30 -0600 Subject: [PATCH 02/11] Add pkg-config files for heatf model and its BMI --- bmi_heat/CMakeLists.txt | 10 ++++++++++ bmi_heat/bmiheatf.pc.cmake | 11 +++++++++++ heat/CMakeLists.txt | 10 ++++++++++ heat/heatf.pc.cmake | 10 ++++++++++ 4 files changed, 41 insertions(+) create mode 100644 bmi_heat/bmiheatf.pc.cmake create mode 100644 heat/heatf.pc.cmake diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index 178e226..da3b90b 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -1,5 +1,11 @@ # bmi-heat +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/${bmi_name}.pc.cmake + ${CMAKE_BINARY_DIR}/bmi_heat/${bmi_name}.pc + @ONLY +) + # Create shared library, except on Windows. if(WIN32) add_library(${bmi_name} bmi_heat.f90) @@ -25,3 +31,7 @@ install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/${bmi_name}.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${bmi_name}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig +) diff --git a/bmi_heat/bmiheatf.pc.cmake b/bmi_heat/bmiheatf.pc.cmake new file mode 100644 index 0000000..78a0235 --- /dev/null +++ b/bmi_heat/bmiheatf.pc.cmake @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @bmi_name@ +Description: BMI for the heatf model +Version: @CMAKE_PROJECT_VERSION@ +Requires: @model_name@ +Libs: -L${libdir} -l@bmi_name@ +Cflags: -I${includedir} diff --git a/heat/CMakeLists.txt b/heat/CMakeLists.txt index 98f0781..c69b415 100644 --- a/heat/CMakeLists.txt +++ b/heat/CMakeLists.txt @@ -1,5 +1,11 @@ # heat +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/${model_name}.pc.cmake + ${CMAKE_BINARY_DIR}/heat/${model_name}.pc + @ONLY +) + # Create shared library, except on Windows. if(WIN32) add_library(${model_name} heat.f90) @@ -24,3 +30,7 @@ install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/${model_name}.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) +install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${model_name}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig +) diff --git a/heat/heatf.pc.cmake b/heat/heatf.pc.cmake new file mode 100644 index 0000000..3e305de --- /dev/null +++ b/heat/heatf.pc.cmake @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: @model_name@ +Description: The two-dimensional heat equation in Fortran +Version: @CMAKE_PROJECT_VERSION@ +Libs: -L${libdir} -l@model_name@ +Cflags: -I${includedir} From 1f75d0a134565b3afb3f64a1d9a987e869a19427 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 11 Mar 2024 16:09:18 -0600 Subject: [PATCH 03/11] Use CMAKE_CURRENT_BINARY_DIR instead of CMAKE_BINARY_DIR --- bmi_heat/CMakeLists.txt | 2 +- heat/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bmi_heat/CMakeLists.txt b/bmi_heat/CMakeLists.txt index da3b90b..862cc21 100644 --- a/bmi_heat/CMakeLists.txt +++ b/bmi_heat/CMakeLists.txt @@ -2,7 +2,7 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${bmi_name}.pc.cmake - ${CMAKE_BINARY_DIR}/bmi_heat/${bmi_name}.pc + ${CMAKE_CURRENT_BINARY_DIR}/${bmi_name}.pc @ONLY ) diff --git a/heat/CMakeLists.txt b/heat/CMakeLists.txt index c69b415..710f352 100644 --- a/heat/CMakeLists.txt +++ b/heat/CMakeLists.txt @@ -2,7 +2,7 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${model_name}.pc.cmake - ${CMAKE_BINARY_DIR}/heat/${model_name}.pc + ${CMAKE_CURRENT_BINARY_DIR}/${model_name}.pc @ONLY ) From fd1d3725c57eabd8903c75ee00ec0f177707874a Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 11 Mar 2024 16:13:03 -0600 Subject: [PATCH 04/11] Require bmif library --- bmi_heat/bmiheatf.pc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bmi_heat/bmiheatf.pc.cmake b/bmi_heat/bmiheatf.pc.cmake index 78a0235..000cde1 100644 --- a/bmi_heat/bmiheatf.pc.cmake +++ b/bmi_heat/bmiheatf.pc.cmake @@ -6,6 +6,6 @@ includedir=${prefix}/include Name: @bmi_name@ Description: BMI for the heatf model Version: @CMAKE_PROJECT_VERSION@ -Requires: @model_name@ +Requires: @model_name@, @BMIF_LIBRARIES@ Libs: -L${libdir} -l@bmi_name@ Cflags: -I${includedir} From a1b1b8e6fa49f994657eb3e59e1b183449d6b396 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 11:53:49 -0600 Subject: [PATCH 05/11] Add pkg-config dependency to test environment --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 853467b..b22e55a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,7 @@ jobs: environment-name: testing create-args: >- cmake + pkg-config fortran-compiler bmi-fortran @@ -79,6 +80,7 @@ jobs: environment-name: testing create-args: >- cmake + pkg-config cxx-compiler init-shell: >- powershell From d230d8bac63b5f5e542d80ecb818b02a29050dad Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 12:02:31 -0600 Subject: [PATCH 06/11] Use LIBRARY_PREFIX env variable on Windows --- .github/workflows/test.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b22e55a..773f04f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,6 +71,9 @@ jobs: runs-on: windows-latest + env: + LIBRARY_PREFIX: $env:CONDA_PREFIX\Library + steps: - uses: actions/checkout@v4 - uses: ilammy/msvc-dev-cmd@v1 @@ -96,7 +99,7 @@ jobs: unzip bmi-fortran.zip cd bmi-fortran-master mkdir build && cd build - cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="$env:CONDA_PREFIX" -DCMAKE_BUILD_TYPE=Release + cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release cmake --build . --target install --config Release cd ${{ github.workspace }} @@ -106,17 +109,17 @@ jobs: - name: Configure, build, and install working-directory: ${{ github.workspace }}/build run: | - cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="$env:CONDA_PREFIX" -DCMAKE_BUILD_TYPE=Release + cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release cmake --build . --target install --config Release - name: Test installed files run: | - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\lib\libheatf.a ) ){ exit 1 } - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\bin\run_heatf.exe ) ){ exit 1 } - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\include\heatf.mod ) ){ exit 1 } - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\bin\run_bmiheatf.exe ) ){ exit 1 } - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\lib\libbmiheatf.a ) ){ exit 1 } - if ( -not ( Test-Path -Path $env:CONDA_PREFIX\include\bmiheatf.mod ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libheatf.a ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_heatf.exe ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\heatf.mod ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_bmiheatf.exe ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmiheatf.a ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmiheatf.mod ) ){ exit 1 } # - name: Unit test with CTest # working-directory: ${{ github.workspace }}/build From c56b264123dad1da33dce88097dfdb220cfaf8e0 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 12:08:22 -0600 Subject: [PATCH 07/11] Test for pkg-config files; run ctest --- .github/workflows/test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 773f04f..83229f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -117,10 +117,12 @@ jobs: if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libheatf.a ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_heatf.exe ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\heatf.mod ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\heatf.pc ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_bmiheatf.exe ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmiheatf.a ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmiheatf.mod ) ){ exit 1 } + if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\bmiheatf.pc ) ){ exit 1 } - # - name: Unit test with CTest - # working-directory: ${{ github.workspace }}/build - # run: ctest -C Release -VV --output-on-failure + - name: Unit test with CTest + working-directory: ${{ github.workspace }}/build + run: ctest -C Release -VV --output-on-failure From 270c3e1f9389468c31331deb11fd981aba4bd9c6 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 13:02:51 -0600 Subject: [PATCH 08/11] Make SHLIB_EXT env variable for unix-based systems --- .github/workflows/test.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83229f3..65b6cd8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,9 @@ jobs: run: shell: bash -l {0} + env: + SHLIB_EXT: ${{ matrix.os == 'ubuntu-latest' && '.so' || '.dylib' }} + strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -46,7 +49,13 @@ jobs: working-directory: ${{ github.workspace }}/build run: cmake --build . --target install --config ${{ matrix.build-type }} - - name: Test + - name: Test for installed files + run: | + test -h $CONDA_PREFIX/lib/libheatf${{ env.SHLIB_EXT }} + test -f $CONDA_PREFIX/include/heatf.mod + test -f $CONDA_PREFIX/lib/pkgconfig/heatf.pc + + - name: Run CTest working-directory: ${{ github.workspace }}/build run: ctest -C ${{ matrix.build-type }} --output-on-failure @@ -112,7 +121,7 @@ jobs: cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release cmake --build . --target install --config Release - - name: Test installed files + - name: Test for installed files run: | if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libheatf.a ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_heatf.exe ) ){ exit 1 } @@ -123,6 +132,6 @@ jobs: if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmiheatf.mod ) ){ exit 1 } if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\pkgconfig\bmiheatf.pc ) ){ exit 1 } - - name: Unit test with CTest + - name: Run CTest working-directory: ${{ github.workspace }}/build run: ctest -C Release -VV --output-on-failure From b6327baae945154c958a9c0c94f49259a5cd16f2 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 13:08:58 -0600 Subject: [PATCH 09/11] Test for installed files --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65b6cd8..e2e0bb1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,9 @@ jobs: test -h $CONDA_PREFIX/lib/libheatf${{ env.SHLIB_EXT }} test -f $CONDA_PREFIX/include/heatf.mod test -f $CONDA_PREFIX/lib/pkgconfig/heatf.pc + test -h $CONDA_PREFIX/lib/libbmiheatf${{ env.SHLIB_EXT }} + test -f $CONDA_PREFIX/include/bmiheatf.mod + test -f $CONDA_PREFIX/lib/pkgconfig/bmiheatf.pc - name: Run CTest working-directory: ${{ github.workspace }}/build From e9c3c3f3ea9d501fd24f8c2fe34f53bfb070b49c Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 13:19:42 -0600 Subject: [PATCH 10/11] Remove duplicate sample configuration file --- sample.cfg | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 sample.cfg diff --git a/sample.cfg b/sample.cfg deleted file mode 100644 index e69de29..0000000 From 613740d1fc16a62a380930948f0e5f284a8dca25 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Wed, 13 Mar 2024 13:21:25 -0600 Subject: [PATCH 11/11] List pkg-config requirement --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 24e6372..46731f0 100644 --- a/README.md +++ b/README.md @@ -46,13 +46,13 @@ This example can be built on Linux, macOS, and Windows. in that repository. You can choose to build them from source or install them through a conda binary. If using fpm, the binding will be automatically downloaded and built for you. +* pkg-config ### CMake - Linux and macOS To build this example from source with CMake, using the current Fortran BMI version, run - export BMIF_VERSION=2.0 mkdir _build && cd _build cmake .. -DCMAKE_INSTALL_PREFIX= make @@ -80,12 +80,15 @@ The installation will look like | |-- bmiheatf.mod | `-- heatf.mod `-- lib - |-- libbmif.2.0.dylib - |-- libbmif.dylib -> libbmif.2.0.dylib + |-- libbmif.a + |-- libbmif.2.0.2.dylib + |-- libbmif.dylib -> libbmif.2.0.2.dylib |-- libbmiheatf.dylib - `-- libheatf.dylib - -3 directories, 9 files + |-- libheatf.dylib + `-- pkgconfig + |-- bmif.pc + |-- bmiheatf.pc + `-- heatf.pc ``` From the build directory, @@ -103,7 +106,6 @@ To configure this example from source with cmake using the current Fortran BMI version, run the following in a [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) - set "BMIF_VERSION=2.0" mkdir _build && cd _build cmake .. ^ -G "NMake Makefiles" ^