Add a mechanism to build libraries for built-in solvers

Open Owen Parry requested to merge oparry/nektar:feature/solver-lib-builds into master

Issue/feature addressed

User-authored solvers often need to reuse functionality implemented in Nektar's built-in solvers. At the moment this usually entails copy-pasting the source.

Proposed solution

This PR adds a CMake macro and an associated config option that allow separate libraries to be generated for each built-in solver.


  • Adds two new optional arguments to ADD_NEKTAR_LIBRARY
    • TARGET_SUFFIX which can be used to set a target name that differs from the library's output name (defaults to "")
    • LINK_MODE ("public"/"private"/"interface"; defaults to "public")
  • Defines ADD_SOLVER_LIBRARY - a wrapper around ADD_NEKTAR_LIBRARY that
    • Reuses objects generated when building the solver executable, where possible
    • Passes a suffix to ADD_SOLVER_LIBRARY that changes the target name, avoiding a clash with the solver executable
  • Adds NEKTAR_BUILD_SOLVER_LIBS as a config option
    • Turning this on triggers a library build for all enabled solvers
    • For now, a build is only set up for CompressibleFlowSolver, other solvers just give a "library build not set up" message
    • Adding a new solver library is just a matter of collecting a list of headers and passing them to ADD_SOLVER_LIBRARY


I also needed to set POSITION_INDEPENDENT_CODE=ON when building the object libraries for each executable.




  • Functions and classes, or changes to them, are documented.
  • Changelog is updated.
  • Contributed code is correctly formatted. (See the contributing guidelines).
  • No extraneous files have been added (e.g. compiler output or test data files).
Edited by Owen Parry

Merge request reports