From a306f433146abedb274aeeda1f553f296ac7630c Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Fri, 20 Oct 2023 16:23:06 -0600 Subject: [PATCH 1/6] Fix incorrect link to docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 26f6917..6ffd7c4 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ 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 From 681dd549c168aa84697860711dc0d78de7ad915f Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Fri, 20 Oct 2023 16:24:46 -0600 Subject: [PATCH 2/6] Rename workflow file to match other examples --- .github/workflows/{conda-and-cmake.yml => test.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{conda-and-cmake.yml => test.yml} (100%) diff --git a/.github/workflows/conda-and-cmake.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/conda-and-cmake.yml rename to .github/workflows/test.yml From d182784e886de4e5f0e0de48955efe18996ce00a Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Fri, 20 Oct 2023 16:29:05 -0600 Subject: [PATCH 3/6] Update workflow file to match bmi-example-c --- .github/workflows/test.yml | 110 ++++++++++++++----------------------- 1 file changed, 41 insertions(+), 69 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f70a50..6349161 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,14 @@ -name: Build/Test CI +name: Build/Test on: [push, pull_request] jobs: - build-linux-and-macos: + build-and-test: + + if: + github.event_name == 'push' || github.event.pull_request.head.repo.full_name != + github.repository + runs-on: ${{ matrix.os }} defaults: @@ -12,85 +17,52 @@ jobs: strategy: matrix: - os: [ubuntu-latest, macos-latest] - python-version: ["3.8"] + os: [ubuntu-latest, macos-latest, windows-latest] build-type: [Release] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: conda-incubator/setup-miniconda@v2 + - uses: mamba-org/setup-micromamba@v1 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 + 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 + - 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 }} - - - 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 + cmake ${{ github.workspace }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ + -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX - - name: Configure, build, and test - shell: cmd /C CALL {0} + - name: Configure CMake (Windows) + if: matrix.os == 'windows-latest' working-directory: ${{ github.workspace }}\build + shell: pwsh run: | - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.16 10.0.19041.0 + & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" x86 - :: 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 }} ^ - .. + cmake ${{ github.workspace }} ` + -DCMAKE_INSTALL_PREFIX:PATH=$env:CONDA_PREFIX\Library ` + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - :: Build and install - cmake --build . --target install --config ${{ env.build-type }} + - name: Build and install + working-directory: ${{ github.workspace }}/build + run: cmake --build . --target install --config ${{ matrix.build-type }} - :: Test - ctest --output-on-failure -C ${{ env.build-type }} -V + - name: Test + working-directory: ${{ github.workspace }}/build + run: ctest -C ${{ matrix.build-type }} --output-on-failure -VV From bfad9d50e87e257b608b15cd36fa0476c4de61c9 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 23 Oct 2023 14:24:29 -0600 Subject: [PATCH 4/6] Update CMake build steps --- CMakeLists.txt | 16 +++++++++++----- heat/CMakeLists.txt | 34 +++++++++++++++++----------------- heat/heatcxx.pc.cmake | 4 ++-- testing/CMakeLists.txt | 8 +++++--- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06d104c..016828f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,19 @@ -cmake_minimum_required(VERSION 3.0) +# bmi-example-cxx -project (bmi-example-cxx CXX) +cmake_minimum_required(VERSION 3.12) +project (bmi-example-cxx 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/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..08fa7ab 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 +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) From a2435791e67418a65b0b5fde111074c512a038c7 Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 23 Oct 2023 14:35:41 -0600 Subject: [PATCH 5/6] Use CMake project version with pkgconfig --- CMakeLists.txt | 5 ++++- heat/heatcxx.pc.cmake | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 016828f..4771450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,10 @@ # bmi-example-cxx cmake_minimum_required(VERSION 3.12) -project (bmi-example-cxx LANGUAGES CXX) +project(bmi-example-cxx + VERSION 2.1 + LANGUAGES CXX +) include(GNUInstallDirs) diff --git a/heat/heatcxx.pc.cmake b/heat/heatcxx.pc.cmake index 08fa7ab..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} +Version: ${CMAKE_PROJECT_VERSION} Libs: -L${CMAKE_INSTALL_LIBDIR} -l${bmi_name} Cflags: -I${CMAKE_INSTALL_INCLUDEDIR} From 25d4a5478431eb7fbbb65daa7ad8a3f22fae643e Mon Sep 17 00:00:00 2001 From: Mark Piper Date: Mon, 23 Oct 2023 14:44:23 -0600 Subject: [PATCH 6/6] Update build instructions for a conda environment --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6ffd7c4..b162aad 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![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 @@ -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: