diff --git a/.github/workflows/conda-and-cmake.yml b/.github/workflows/conda-and-cmake.yml deleted file mode 100644 index 9f70a50..0000000 --- a/.github/workflows/conda-and-cmake.yml +++ /dev/null @@ -1,96 +0,0 @@ -name: Build/Test CI - -on: [push, pull_request] - -jobs: - build-linux-and-macos: - runs-on: ${{ matrix.os }} - - defaults: - run: - shell: bash -l {0} - - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - python-version: ["3.8"] - build-type: [Release] - - steps: - - uses: actions/checkout@v2 - - - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - python-version: ${{ matrix.python-version }} - channels: conda-forge - channel-priority: true - - - name: Show conda installation info - run: conda info - - - name: Install build tools and dependencies into env - run: | - conda install cxx-compiler cmake pkg-config bmi-cxx - conda list - - - name: Make cmake build directory - run: cmake -E make_directory build - - - name: Configure cmake - working-directory: ${{ github.workspace }}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - - - name: Build - working-directory: ${{ github.workspace }}/build - run: cmake --build . --config ${{ matrix.build-type }} - - - name: Test - working-directory: ${{ github.workspace }}/build - run: ctest -C ${{ matrix.build-type }} --output-on-failure - - build-windows: - runs-on: windows-latest - - env: - build-type: Release - - steps: - - uses: actions/checkout@v2 - - - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - python-version: 3.8 - channels: conda-forge - channel-priority: true - - - name: Show conda installation info - run: conda info - - - name: Install build tools and dependencies into env - run: | - conda install cxx-compiler cmake pkg-config bmi-cxx - conda list - - - name: Make cmake build directory - run: cmake -E make_directory build - - - name: Configure, build, and test - shell: cmd /C CALL {0} - working-directory: ${{ github.workspace }}\build - run: | - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.16 10.0.19041.0 - - :: Configure - cmake ^ - -LAH -G "NMake Makefiles" ^ - -DPKG_CONFIG_EXECUTABLE:FILEPATH=C:/Miniconda/envs/test/Library/bin/pkg-config.exe ^ - -DCMAKE_BUILD_TYPE=${{ env.build-type }} ^ - .. - - :: Build and install - cmake --build . --target install --config ${{ env.build-type }} - - :: Test - ctest --output-on-failure -C ${{ env.build-type }} -V diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6349161 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d104c..4771450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 26f6917..b162aad 100644 --- a/README.md +++ b/README.md @@ -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 @@ -56,7 +56,7 @@ where `` 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): @@ -100,11 +100,10 @@ run the following in a [Developer Command Prompt](https://docs.microsoft.com/en- -DCMAKE_BUILD_TYPE=Release where `` 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: diff --git a/heat/CMakeLists.txt b/heat/CMakeLists.txt index ef4bc5a..e7754b6 100644 --- a/heat/CMakeLists.txt +++ b/heat/CMakeLists.txt @@ -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 ) diff --git a/heat/heatcxx.pc.cmake b/heat/heatcxx.pc.cmake index 94cc938..f10c55f 100644 --- a/heat/heatcxx.pc.cmake +++ b/heat/heatcxx.pc.cmake @@ -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} diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 6a4f88d..2ad7339 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -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)