Skip to content

Commit

Permalink
Merge pull request #12 from csdms/mdpiper/update-build-and-ci
Browse files Browse the repository at this point in the history
Update build system and CI
  • Loading branch information
mdpiper committed Oct 24, 2023
2 parents 2ede037 + 25d4a54 commit 93820b5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 132 deletions.
96 changes: 0 additions & 96 deletions .github/workflows/conda-and-cmake.yml

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build/Test

on: [push, pull_request]

jobs:
build-and-test:

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

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

defaults:
run:
shell: bash -l {0}

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build-type: [Release]

steps:
- uses: actions/checkout@v4

- uses: mamba-org/setup-micromamba@v1
with:
micromamba-version: latest
environment-name: testing
init-shell: >-
bash
powershell
create-args: >-
make
cmake
cxx-compiler
pkg-config
bmi-cxx
- name: Make CMake build directory
run: cmake -E make_directory build

- name: Configure CMake (Unix)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
working-directory: ${{ github.workspace }}/build
run: |
cmake ${{ github.workspace }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
- name: Configure CMake (Windows)
if: matrix.os == 'windows-latest'
working-directory: ${{ github.workspace }}\build
shell: pwsh
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" x86
cmake ${{ github.workspace }} `
-DCMAKE_INSTALL_PREFIX:PATH=$env:CONDA_PREFIX\Library `
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
- name: Build and install
working-directory: ${{ github.workspace }}/build
run: cmake --build . --target install --config ${{ matrix.build-type }}

- name: Test
working-directory: ${{ github.workspace }}/build
run: ctest -C ${{ matrix.build-type }} --output-on-failure -VV
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
cmake_minimum_required(VERSION 3.0)
# bmi-example-cxx

project (bmi-example-cxx CXX)
cmake_minimum_required(VERSION 3.12)
project(bmi-example-cxx
VERSION 2.1
LANGUAGES CXX
)

include(GNUInstallDirs)

set(model_name heatcxx)
set(bmi_name bmi${model_name})

find_package(PkgConfig REQUIRED)
pkg_check_modules(BMICXX REQUIRED IMPORTED_TARGET bmicxx)
message("-- bmicxx include - ${BMICXX_INCLUDE_DIRS}")
message("-- bmicxx include dir - ${BMICXX_INCLUDE_DIRS}")
include_directories(${BMICXX_INCLUDE_DIRS})

add_subdirectory (heat)
add_subdirectory (testing)
add_subdirectory(heat)
add_subdirectory(testing)

include (CTest)
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[![Basic Model Interface](https://img.shields.io/badge/CSDMS-Basic%20Model%20Interface-green.svg)](https://bmi.readthedocs.io/)
[![Build/Test CI](https://github.com/csdms/bmi-example-cxx/workflows/Build/Test%20CI/badge.svg)](https://github.com/csdms/bmi-example-cxx/actions?query=workflow%3A%22Build%2FTest+CI%22)
[![Build/Test](https://github.com/csdms/bmi-example-cxx/actions/workflows/test.yml/badge.svg)](https://github.com/csdms/bmi-example-cxx/actions/workflows/test.yml)

# bmi-example-cxx

An example of implementing the
[C++ bindings](https://github.com/csdms/bmi-cxx)
for the CSDMS
[Basic Model Interface](https://bmi-spec.readthedocs.io) (BMI).
[Basic Model Interface](https://bmi.readthedocs.io) (BMI).


## Overview
Expand Down Expand Up @@ -56,7 +56,7 @@ where `<path-to-installation>` is the base directory
in which the C++ BMI bindings have been installed
(`/usr/local` is the default).
When installing into a conda environment,
use the `CONDA_PREFIX` environment variable.
use the `$CONDA_PREFIX` environment variable.

The installation will look like
(on macOS, using v2.0 of the BMI specification):
Expand Down Expand Up @@ -100,11 +100,10 @@ run the following in a [Developer Command Prompt](https://docs.microsoft.com/en-
-DCMAKE_BUILD_TYPE=Release

where `<path-to-installation>` is the base directory
in which the C BMI bindings have been installed
(`"C:\Program Files (x86)"` is the default;
note that quotes and an absolute path are needed).
When installing into a conda environment,
use the `%CONDA_PREFIX%` environment variable.
in which the C++ BMI bindings have been installed.
The default is `"C:\Program Files (x86)"`.
Note that quotes and an absolute path are needed.
When using a conda environment, use `"%CONDA_PREFIX%\Library"`.

Then, to build and install:

Expand Down
34 changes: 17 additions & 17 deletions heat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
cmake_minimum_required(VERSION 3.0)
# heatcxx

set (HEAT_VERSION 0.2)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/heatcxx.pc.cmake
${CMAKE_BINARY_DIR}/heatcxx.pc)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${model_name}.pc.cmake
${CMAKE_BINARY_DIR}/heat/${model_name}.pc
)

set(bmi_heat_lib_SRCS bmi_heat.cxx heat.cxx)
if(WIN32)
add_library(bmiheatcxx ${bmi_heat_lib_SRCS})
add_library(${bmi_name} bmi_heat.cxx heat.cxx)
else()
add_library(bmiheatcxx SHARED ${bmi_heat_lib_SRCS})
add_library(${bmi_name} SHARED bmi_heat.cxx heat.cxx)
endif()

add_executable(run_bmiheatcxx bmi_main.cxx bmi_heat.cxx heat.cxx)
add_executable(run_${bmi_name} bmi_main.cxx bmi_heat.cxx heat.cxx)

install(
TARGETS run_bmiheatcxx
RUNTIME DESTINATION bin
TARGETS run_${bmi_name}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
TARGETS bmiheatcxx
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
TARGETS ${bmi_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
FILES bmi_heat.hxx heat.hxx
DESTINATION include
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES ${CMAKE_BINARY_DIR}/heatcxx.pc
DESTINATION lib/pkgconfig
FILES ${CMAKE_CURRENT_BINARY_DIR}/${model_name}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
6 changes: 3 additions & 3 deletions heat/heatcxx.pc.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: HeatCXX
Description: 2D Heat Equation
Version: ${HEAT_VERSION}
Libs: -L${CMAKE_INSTALL_PREFIX}/lib -lbmiheatcxx
Cflags: -I${CMAKE_INSTALL_PREFIX}/include
Version: ${CMAKE_PROJECT_VERSION}
Libs: -L${CMAKE_INSTALL_LIBDIR} -l${bmi_name}
Cflags: -I${CMAKE_INSTALL_INCLUDEDIR}
8 changes: 5 additions & 3 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
include (CTest)
# test (heatcxx)

include_directories( ${CMAKE_SOURCE_DIR}/heat )
include(CTest)

include_directories(${CMAKE_SOURCE_DIR}/heat)

function(make_test test_name)
add_test(NAME ${test_name} COMMAND ${test_name})
add_executable(${test_name} ${test_name}.cxx)
target_link_libraries(${test_name} bmiheatcxx)
target_link_libraries(${test_name} ${bmi_name})
endfunction(make_test)

make_test(test_irf)
Expand Down

0 comments on commit 93820b5

Please sign in to comment.