Skip to content

Commit

Permalink
Merge branch 'master' into feature/GRIDEDIT-432_sign_dlls
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottWillcox authored Oct 17, 2023
2 parents 90d8640 + 5f22543 commit 20fad45
Show file tree
Hide file tree
Showing 200 changed files with 23,124 additions and 10,158 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Build and test on macos

on:
push:
branches:
- master
- "release/v[0-9].[0-9].[0-9]"
pull_request:
types:
- opened # triggers build when opened
- synchronize # triggers build when commits are pushed to HEAD
branches:
- master
- "release/v[0-9].[0-9].[0-9]"
- "feature/**"
# Manual trigger
workflow_dispatch:

jobs:

build:

# Build strategy
strategy:
fail-fast: false
matrix:
platform:
#- 'ubuntu-latest'
- 'macos-latest'
build_type:
- 'Release'
#- 'Debug'
#- 'DebugWithRelInfo '

# Build platform
runs-on: ${{ matrix.platform }}

name: ${{ matrix.platform }}-${{ matrix.build_type }}

# default compiler on macos is clang, switch to gcc 11. Specifying the version is necessary.
# It seems like gcc and g++ are symbolic links to the default clang and clang++ compilers, respectively.
# CMAKE_CXX_COMPILER_ID will evaluate to AppleClang rather than GNU on macos.
env:
CC: gcc-11
CXX: g++-11

# Build steps
steps:

# Step: Checkout
- name: Checkout
uses: actions/checkout@v3
# Workaround for getting "git describe --tags" to work in cmake/get_version_from_git.cmake (Build step)
with:
fetch-depth: 0

# Step: Set paths
- name: Set paths
id: paths
run : |
echo "build_dir=${{ github.workspace }}/build" >> $GITHUB_OUTPUT
echo "ext_deps_dir=${{ github.workspace }}/external_dependencies" >> $GITHUB_OUTPUT
echo "install_dir=${{ github.workspace }}/install" >> $GITHUB_OUTPUT
# Step: Install system-provided dependencies
# macOS
- if: runner.os == 'macOS'
name: Install system-provided dependencies
run: | # brew update
brew install boost
brew install doxygen
# Linux
- if: runner.os == 'Linux'
name: Install system-provided dependencies
run: | # sudo apt-get update && sudo apt upgrade
sudo apt-get install libboost-all-dev
sudo apt-get install doxygen
# Step: Restore cached user-provided dependencies
- name: Restore cached user-provided dependencies
uses: actions/cache/restore@v3
id: restore-cached-external-dependencies
with:
key: ${{ runner.os }}-cache-key
restore-keys: ${{ runner.os }}-cache-key
path: ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c

# Step: Build and install user-provided dependencies, executes only if no cache restored
- name: Build and install user-provided dependencies
if: steps.restore-cached-external-dependencies.outputs.cache-hit != 'true'
# NetCDF Dependencies m4, curl, and openssl are provided by the build machine
run: >
pwsh ${{ github.workspace }}/scripts/install_netcdf_static.ps1
-WorkDir ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/work
-InstallDir ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install
-BuildType '${{ matrix.build_type }}'
-ParallelJobs 10
# Step: Cache user-provided dependencies, executes only if no cache restored
- name: Cache user-provided dependencies
uses: actions/cache/save@v3
if: steps.restore-cached-external-dependencies.outputs.cache-hit != 'true'
with:
key: ${{ runner.os }}-cache-key
path: ${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c

# Step: CMake configuration
- name: Configure
run: >
cmake
-S ${{ github.workspace }}
-B ${{ steps.paths.outputs.build_dir }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_PREFIX_PATH=${{ steps.paths.outputs.ext_deps_dir }}/netcdf-c/install/netcdf-c
-DCMAKE_INSTALL_PREFIX=${{ steps.paths.outputs.install_dir }}
# Step: CMake build
- name: Build
run: cmake --build ${{ steps.paths.outputs.build_dir }} --config ${{ matrix.build_type }} -j

# Step: Test
# Works if runner.os == 'Linux' or runner.os == 'macOS'
# if runner.os == 'Windows', /matrix.build_type needs to be inserted before /tests
- name: Test
run: |
echo -e "\n*************** MeshKernel Tests ***************\n"
${{ steps.paths.outputs.build_dir }}/libs/MeshKernel/tests/MeshKernelUnitTests
echo -e "\n*************** MeshKernel API Tests ***************\n"
${{ steps.paths.outputs.build_dir }}/libs/MeshKernelApi/tests/MeshKernelApiUnitTests
# Step: CMake install
- name: Install
run: cmake --install ${{ steps.paths.outputs.build_dir }}

# Step: Upload artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: meshkernel-${{ matrix.platform }}-${{ matrix.build_type }}
path: ${{ steps.paths.outputs.install_dir }}
if-no-files-found: error
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ build_*
.vs
.vscode

# Emacs
*~

# User specific
post_build.bat
tools/test_utils/include/TestUtils/Definitions.hpp
Expand Down
82 changes: 47 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# MeshKernel

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Deltares_Grid_Editor_back-end&metric=alert_status)](https://sonarcloud.io/dashboard?id=Deltares_Grid_Editor_back-end)

MeshKernel is a library for creating and editing meshes.
It supports 1D & 2D unstructured meshes as well as curvilinear meshes.

Wrappers for the following languages are available:

- [Python](https://github.com/Deltares/MeshKernelPy)
- [.NET](https://github.com/Deltares/MeshKernelNET)

The library is separated in an API namespace (MeshKernelApi) used for communication with the client and a backend namespace (MeshKernel) where the algorithms are implemented.
The API namespace contains several structures used as parameters for the API methods (see API usage section).
The library is separated in an API namespace (MeshKernelApi) used for communication with the client and a backend namespace (MeshKernel) where the algorithms are implemented.
The API namespace contains several structures used as parameters for the API methods (see API usage section).
These structures must be mirrored in the client application and filled with appropriate values.

## Examples
Expand All @@ -22,7 +24,7 @@ In this example a mesh is created by discretizing the polygon perimeter with the

2. Mesh orthogonalization

Finite volume staggered flow solvers require the mesh to be as much orthogonal as possible.
Finite volume staggered flow solvers require the mesh to be as much orthogonal as possible.
MeshKernel provides an algorithm to adapt the mesh and achieve a good balance between mesh orthogonality and smoothness.

![alt tag](docs/images/MeshOrthogonalization.jpg)
Expand All @@ -35,81 +37,98 @@ Curvilinear meshes for rivers can be generated using splines.

4. Mesh refinement

A mesh can be refined in areas based on samples or polygon selections.
A mesh can be refined in areas based on samples or polygon selections.

![alt tag](docs/images/GridRefinement.jpg)


## Shared library dependencies (Linux)

- libgomp

## Build Requirements

The requirements are:

- Git
- CMake 3.23 or higher
- A C++20 compatible compiler
- A C++20 compatible compiler. Currently the following compilers are supported:
- Windows: Microsoft Visual C++
- Linux: GCC
- macOS: GCC. Clang is not yet supported. Care must be taken if gcc and g++ are symbolic links to clang and clang++
- The Boost libraries
- NetCDF
- [NetCDF](#netcdf)
- Doxygen (optional)

## Dependencies

### Boost
- Under Windows, precompiled boost binaries (with MSVC compiler) can be downloaded [here](https://sourceforge.net/projects/boost/files/boost-binaries/). Alternatively, the source code is available [here](https://sourceforge.net/projects/boost/files/boost/) and the installation instructions can be found [here](https://www.boost.org/doc/libs/1_74_0/more/getting_started/windows.html).
- Under Linux, Boost can be either obtained from the package repository of the used Linux distribution or built from [source](https://sourceforge.net/projects/boost/files/boost/) following these [instructions](https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html).

Once installed, add the boost environmental variables accordingly. For example, if version 1.74.0 in installed in `C:\Apps`, set the environment variable:
```
BOOST_INCLUDEDIR=C:\Apps\boost_1_74_0
```
- Under Windows, precompiled boost binaries (with MSVC compiler) can be downloaded [here](https://sourceforge.net/projects/boost/files/boost-binaries/). Alternatively, the source code is available [here](https://sourceforge.net/projects/boost/files/boost/) and the installation instructions can be found [here](https://www.boost.org/doc/libs/1_74_0/more/getting_started/windows.html). Once installed, set the boost environment variable `BOOST_INCLUDEDIR` to the appropriate path. For example, if version 1.74.0 in installed in `C:\Apps`, set `BOOST_INCLUDEDIR=C:\Apps\boost_1_74_0`.
- Under Linux, Boost can be either obtained from the package repository of the used Linux distribution or built from [source](https://sourceforge.net/projects/boost/files/boost/) following these [instructions](https://www.boost.org/doc/libs/1_74_0/more/getting_started/unix-variants.html).
- Under macOS, Boost can be installed by following these [instructions](https://www.boost.org/doc/libs/1_74_0/doc/html/quickbook/install.html).

### NetCDF
The NetCDF static library is required for building MeshKernel. Optionally, a PowerShell [script](scripts/install_netcdf_static.ps1) is made available for cloning and building [NetCDF](https://github.com/Unidata/netcdf-c) and its dependencies ([HDF5](https://github.com/HDFGroup/hdf5), [ZLIB](https://github.com/madler/zlib), [Curl](https://github.com/curl/curl), and [m4](https://sourceforge.net/projects/gnuwin32/files/m4/)). It can be used under both Windows and Linux.

The NetCDF static library is required for building MeshKernel. Optionally, a PowerShell [script](scripts/install_netcdf_static.ps1) is made available for cloning and building [NetCDF](https://github.com/Unidata/netcdf-c) and its dependencies ([HDF5](https://github.com/HDFGroup/hdf5), [ZLIB](https://github.com/madler/zlib), [Curl](https://github.com/curl/curl), and [m4](https://sourceforge.net/projects/gnuwin32/files/m4/)). It can be used under Windows, Linux, and macOS. The script is compatible with Powershell version 7 and higher. If necessary, Windows users need to upgrade to from version 5 to 7. The procedure is described [here](https://learn.microsoft.com/en-us/powershell/scripting/whats-new/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7.3).

To run the script in a PowerShell session, use

```powershell
.\install_netcdf_static.ps1 -WorkDir '/path/to/work/directory' -InstallDir '/path/to/install/directory' -BuildType 'Release' -ParallelJobs 10 -GitTags @{zlib = 'v1.2.13'; curl = 'curl-7_88_1'; hdf5 = 'hdf5-1_14_0'; netcdf_c = 'v4.9.1'}
```

with `/path/to/work/directory` and `/path/to/install/directory` replaced with valid paths.

For more information regarding the script's options above, use

```powershell
Get-Help .\install_netcdf_static.ps1 -Detailed
```

Upon successful installation, to build MeshKernel successfully, it is important to either

- add the path to the install directory to the system path, or
- configure the MeshKernel build with `-DCMAKE_PREFIX_PATH=/path/to/install/directory`.

**Note:** Additional dependencies may be required depending on the system configuration:

- Windows: [Perl](https://strawberryperl.com/)
- Linux: m4, OpenSSL, Curl, and [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.3). All dependencies can be installed from the repository of the used Linux distribution.

- Linux and macOS:
- m4, OpenSSL, Curl (Provided by the used system)
- Powershell ([Linux instructions](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.3), [macOS instructions](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.3)).

## Configuring and Building MeshKernel

Follow the steps below to configure, build and install MeshKernel.

### Steps

1. To configure under Windows with Visual Studio, a solution is generated using

```powershell
cmake -S <path-to-source-dir> -B <path-to-build-dir> -G "Visual Studio 16 2019" --install-prefix <path-to-install-dir>
```
This example uses Visual Studio 16 2019. A different version can be specified. In the above
- `<path-to-source-dir>` is the path to the MeshKernel source tree (the top-level directory containing source files provided by the project).
- `<path-to-build-dir>` is the path to the directory where MeshKernel is to be built.
- `<path-to-install-dir>` is the path top the directory where MeshKernel is to be installed.
Under Linux, the generator option is omitted:
```powershell
cmake -S <path-to-source-dir> -B <path-to-build-dir> --install-prefix <path-to-install-dir>
Under Linux and macOS , the generator option can be omitted or the following can be used:
```powershell
cmake -S <path-to-source-dir> -B <path-to-build-dir> -G "Unix Makefiles" --install-prefix <path-to-install-dir>
```
2. To build the project's targets, use:
```powershell
cmake --build <path-to-build-dir> --config <cfg> --parallel <jobs>
```
where
- `<cfg>` is the build type (`Debug`, `Release`, `RelWithDebInfo` and `MinSizeRel`), see `CMAKE_BUILD_TYPE`.
- `<jobs>` is the maximum number of concurrent processes to use when building.
Expand All @@ -119,27 +138,20 @@ Follow the steps below to configure, build and install MeshKernel.
```powershell
cmake --install <path-to-build-dir>
```
or
or
```powershell
cmake --install <path-to-build-dir> --prefix [<path-to-install-dir>]
```
to override the installation path specified during configuration (step 1).
### Additional configuration options
MeshKernel can be configured with a set of options, which are summarized in the table below.
| Option | Description | Type | Default | Notes |
|:------ |:------------|:-----|:--------|:------|
| ENABLE_UNIT_TESTING | Enables building the unit test executables | Bool | ON | |
| ENABLE_BENCHMARKING | Enables building the benchmark executable | Bool | OFF | |
| ENABLE_BENCHMARKING_MEM_REPORT | Enables reporting memory usage statistics | Bool | OFF | Applicable only when ENABLE_BENCHMARKING is ON, ignored otherwise |
| ENABLE_CODE_COVERAGE | Generates code coverage report | Bool | OFF | Valid only under Linux when a GNU compiler is used (requires gcov), ignored otherwise |
MeshKernel can be configured with a set of options, which are summarized in the table below.
| Option | Description | Type | Default | Notes |
| :----------------------------- | :------------------------------------------------------------ | :--- | :------ | :---------------------------------------------------------------------------------------------- |
| ENABLE_UNIT_TESTING | Enables building the unit test executables | Bool | ON | |
| ENABLE_BENCHMARKING | Enables building the benchmark executable | Bool | OFF | |
| ENABLE_BENCHMARKING_MEM_REPORT | Enables reporting memory usage statistics | Bool | OFF | Applicable only when ENABLE_BENCHMARKING is ON, ignored otherwise |
| ENABLE_CODE_COVERAGE | Generates code coverage report | Bool | OFF | Valid only under Linux and macOS when a GNU compiler is used (requires gcov), ignored otherwise |
| HAVE_SRC_LOC_IN_ERR_MSGS | Includes the source location information in custom exceptions | Bool | OFF | |
8 changes: 6 additions & 2 deletions cmake/compiler_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ if (UNIX)
add_compile_options("$<$<CONFIG:RELEASE>:-O2>")
add_compile_options("$<$<CONFIG:DEBUG>:-g>")
else()
message(FATAL_ERROR "Unsupported compiler. Only GNU is supported under Linux.")
message(FATAL_ERROR "Unsupported compiler. Only GNU is supported under Linux. Found ${CMAKE_CXX_COMPILER_ID}.")
endif()
elseif(WIN32)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options("/EHsc;/MP;/W3;/WX")
add_compile_options("$<$<CONFIG:RELEASE>:/O2>")
add_compile_options("$<$<CONFIG:DEBUG>:/Od;/DEBUG>")
add_compile_definitions("_USE_MATH_DEFINES")
add_compile_definitions("_CRT_SECURE_NO_WARNINGS")
else()
message(FATAL_ERROR "Unsupported compiler. Only MSVC is supported under Windows.")
message(FATAL_ERROR "Unsupported compiler. Only MSVC is supported under Windows. Found ${CMAKE_CXX_COMPILER_ID}.")
endif()
else()
message(FATAL_ERROR "Unsupported platform. Only Linux and Windows are supported.")
Expand All @@ -33,6 +34,9 @@ endif()
# CMAKE_SOURCE_DIR is passed to the src in order to strip it out of the path of srcs where exceptions may occur
add_compile_definitions(CMAKE_SRC_DIR=${CMAKE_SOURCE_DIR})

# Show the source location in the exception message?
add_compile_definitions(HAVE_SRC_LOC_IN_ERR_MSGS=$<BOOL:${HAVE_SRC_LOC_IN_ERR_MSGS}>)

# format library: from the standard lib or third-party?
# When supported, std::format is preferred. Otherwise, fmtlib should be used.
set(USE_LIBFMT 0)
Expand Down
Loading

0 comments on commit 20fad45

Please sign in to comment.