CMake on windows with mingw compilers

The linked repository follows fpm’s structure to layout the project, you have three target:

  1. a library defined in the src/ directory, which is installed and usable by dependent projects
  2. an executable in the app/ directory, which is also installed
  3. a test driver in the test/ directory, for creating unit tests using the test-drive framework

You can simply copy / clone the whole project and adjust these lines to your project specification

If you don’t want stdlib, you can delete the lines here

Any sources you want to compile are added in the CMake file in src/CMakeLists.txt at, make sure to include them there otherwise they will not be built:

Finally there are build and installation instructions in the README at GitHub - fortran-lang/stdlib-cmake-example: Integration of the Fortran standard library in CMake projects, which should show you how to build your new CMake project, try the whole workflow. If you want to run tests, you can also use

ctest --test-dir _build --output-on-failure

The CMake files contain a lot of boilerplate, which I have learned over the years of using CMake. The are apparently important to have a well working CMake project which other people can also use, why we have to write all this stuff ourselves however is beyond me. Don’t worry too much about the target export and stuff like that for the moment.

Also, if you should be sick of CMake at some point, you can simply add a package manifest for the Fortran package manager (fpm.toml) and use the project should build directly with fpm due to the compatible layout. There happens to be a guide on using stdlib and test-drive as dependencies with fpm at Adding dependencies — Fortran Package Manager.

If you have any questions feel free to ask, we are always happy to help.