Skip to content

Commit

Permalink
Merge pull request #13 from permamodel/mdpiper/fix-windows-ci
Browse files Browse the repository at this point in the history
Fix build and CI on Windows
  • Loading branch information
mdpiper authored Dec 12, 2024
2 parents bb6828f + 1b288f8 commit 10ea008
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
44 changes: 20 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on: [push, pull_request]

env:
BMI_VERSION: 1_2
BUILD_DIR: _build

jobs:
build-on-unix:

if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: ${{ matrix.os }}

Expand All @@ -35,30 +35,24 @@ jobs:
create-args: >-
make
cmake
pkg-config
fortran-compiler
- name: Make build directory
run: cmake -E make_directory build

- name: Configure
working-directory: ${{ github.workspace }}/build
run: cmake .. -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release
- name: Configure project
run: cmake -B ${{ env.BUILD_DIR }} -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX -DCMAKE_BUILD_TYPE=Release

- name: Build and install
working-directory: ${{ github.workspace }}/build
run: cmake --build . --target install --config Release
run: cmake --build ${{ env.BUILD_DIR }} --target install --config Release

- name: Test
working-directory: ${{ github.workspace }}/build
run: |
test -h $CONDA_PREFIX/lib/libbmigiplf${{ env.SHLIB_EXT }}
ctest
ctest --test-dir ${{ env.BUILD_DIR }}
build-on-windows:

if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: windows-latest

Expand All @@ -74,22 +68,24 @@ jobs:
environment-name: testing
create-args: >-
cmake
pkg-config
cxx-compiler
fortran-compiler
init-shell: >-
powershell
- name: Make cmake build directory
run: cmake -E make_directory build
- name: Set the FC environment variable to the Fortran conda compiler
run: |
echo "FC=$CONDA_PREFIX/Library/bin/flang-new.exe" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Configure, build, and install
working-directory: ${{ github.workspace }}/build
- name: Configure, build, and install project
run: |
cmake .. -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build . --target install --config Release
cmake -B ${{ env.BUILD_DIR }} -G Ninja -DCMAKE_INSTALL_PREFIX="${{ env.LIBRARY_PREFIX }}" -DCMAKE_BUILD_TYPE=Release
cmake --build ${{ env.BUILD_DIR }} --target install --config Release
- name: Test
working-directory: ${{ github.workspace }}/build
run: |
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\libbmigiplf.dll.a ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\libbmigiplf.dll ) ){ exit 1 }
ctest
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\bin\run_bmigipl_model.exe ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\lib\bmigiplf.lib ) ){ exit 1 }
if ( -not ( Test-Path -Path ${{ env.LIBRARY_PREFIX }}\include\bmigiplf.mod ) ){ exit 1 }
ctest --test-dir ${{ env.BUILD_DIR }}
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ project(bmigipl Fortran)

include(GNUInstallDirs)

set(bmi_version 1.0)
set(bmigipl_lib bmigiplf)
set(data_dir ${CMAKE_SOURCE_DIR}/data)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)
Expand Down
15 changes: 8 additions & 7 deletions GIPL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
set(pkg_name gipl_model)
set(mod_name ${pkg_name})
set(src_${pkg_name} gipl.f90 main.f90)
set(src_bmi${pkg_name} gipl.f90 bmigiplf.f90 bmi.f90)

add_library(${bmigipl_lib} SHARED ${src_bmi${pkg_name}})

add_executable(run_${pkg_name} ${src_${pkg_name}})
add_library(gipl OBJECT gipl.f90)
if(WIN32)
add_library(${bmigipl_lib} STATIC bmigiplf.f90 bmi.f90 $<TARGET_OBJECTS:gipl>)
else()
add_library(${bmigipl_lib} SHARED bmigiplf.f90 bmi.f90 $<TARGET_OBJECTS:gipl>)
endif()

add_executable(run_${pkg_name} main.f90 $<TARGET_OBJECTS:gipl>)
add_executable(run_bmi${pkg_name} bmi_main.f90)
target_link_libraries(run_bmi${pkg_name} ${bmigipl_lib})

Expand All @@ -25,7 +26,7 @@ install(
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/${mod_name}.mod
FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/${pkg_name}.mod
${CMAKE_Fortran_MODULE_DIRECTORY}/${bmigipl_lib}.mod
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
7 changes: 4 additions & 3 deletions GIPL/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ include(CTest)

include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})

add_library(helpers OBJECT testing_helpers.f90)

function(make_example example_name)
add_test(NAME ${example_name} COMMAND ${example_name})
set(src_${example_name} ${example_name}.f90 testing_helpers.f90)
add_executable(${example_name} ${src_${example_name}})
target_link_libraries(${example_name} ${bmi_lib} ${bmigipl_lib})
add_executable(${example_name} ${example_name}.f90 $<TARGET_OBJECTS:helpers>)
target_link_libraries(${example_name} ${bmigipl_lib})
endfunction(make_example)

make_example(info_ex)
Expand Down
7 changes: 4 additions & 3 deletions GIPL/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ include(CTest)

include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})

add_library(fixtures OBJECT fixtures.f90)

function(make_test test_name)
add_test(NAME ${test_name} COMMAND ${test_name})
set(src_${test_name} ${test_name}.f90 fixtures.f90)
add_executable(${test_name} ${src_${test_name}})
target_link_libraries(${test_name} ${bmi_lib} ${bmigipl_lib})
add_executable(${test_name} ${test_name}.f90 $<TARGET_OBJECTS:fixtures>)
target_link_libraries(${test_name} ${bmigipl_lib})
endfunction(make_test)

make_test(test_get_component_name)
Expand Down

0 comments on commit 10ea008

Please sign in to comment.