Include an fpm based library within a pre-existing/mixed language CMake project

Hi, there might already be an answer to this but haven’t really found any explicit tutorial/examples:

So I’m working on a huge project base containing Fortran/C/C++ libraries. The project(s) contain several external dependencies, it builds intermediate libraries in either of the languages and at the end builds several packages. All of this is using CMake as the build system.

Now I’m wondering if I could (smoothly) introduce fpm to manage just one of the fortran projects having in mind that:

  • This library project has upstream external dependencies
  • It is a dependency for other libraries/executable downstream
  • The same source code is used to build static libs (for compiling with the executable) and dynamic link libraries for creating a Python API (using ctypes)
  • Local development is done on windows, using MVS2019 + Intel19 and WSL2+Intel for debugging linux. For deployment, everything is ran in a server that compiles the Windows and Linux distributions.

… So at the end of the day I have to be careful not to break out the house just to introduce a new package manager.

When looking at some of the tutorials/videos, I saw how to declare external dependencies using urls from github, but what about local dependencies that are not an fpm project

Q1: is there a way to at least declare the location of the upstream static/dynamic link libraries as dependencies? (is it safe to do so in fpm?)

Q2: Is there a way to include the build process within the pre-existing CMake build chain?

Thanks for any guidance on this

I haven’t tried this, but I’ve been thinking about doing this as well. For just a single fpm project it should be possible to:

  1. Use FetchContent to download the source
  2. Create a custom target that runs fpm and build that project
  3. Create an imported library that points at the static library that fpm built

This should work fine for a single dependency, but might get problematic for multiple projects: Say that you want to depend on fpm project lib_a and fpm project lib_b and both lib_a and lib_b depend on another fpm project lib_c. If you add both with the procedure that I outlined above then fpm will build lib_c once for both lib_a and lib_b. This will most likely lead to problems with the fact that you now have duplicate versions of lib_c’s .mod files and its compiled functions.