# Why should I use CMake?

**URL:** <https://fortran-lang.discourse.group/t/why-should-i-use-cmake/953>\
**Category:** Help\
**Created:** [April 5, 2021, 9:40am UTC](https://fortran-lang.discourse.group/t/why-should-i-use-cmake/953 "2021-04-05T09:40:54Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [April 5, 2021, 10:13am UTC](https://fortran-lang.discourse.group/t/why-should-i-use-cmake/953/2 "2021-04-05T10:13:25Z")

</div>

CMake is interesting if you want to distribute your projects on various systems. It will for example detect if there is a Fortran compiler installed. It’s a very powerful tool.

If you don’t want to use the default compiler (f95 link on a Linux system), you can easily tell CMake which compiler you want, for example:

```bash
$ cmake -D CMAKE_Fortran_COMPILER:FILEPATH="/opt/intel/bin/ifort" ..
$ cmake -D CMAKE_Fortran_COMPILER:FILEPATH=$(which gfortran-9) ..

```

As you can see, a default of CMake, in my opinion, is that it is quite verbose…

Default build type is release, but you can override it:

```bash
$ cmake -D CMAKE_BUILD_TYPE=debug ..

```

In that file, you will find how to use some other variables, like `CMAKE_Fortran_FLAGS_DEBUG`:  
[https://github.com/vmagnin/gtk-fortran/blob/gtk4/CMakeLists.txt](https://github.com/vmagnin/gtk-fortran/blob/gtk4/CMakeLists.txt)

Meson is easier to use, but does not yet manage correctly the installation of Fortran mod files:

> <https://github.com/mesonbuild/meson/issues/5374>
>
> I can't seem to figure out how to install the Fortran module files that are generated during the build.
> Not sure if...

And of course, there is now fpm…

---

_[View the full topic](https://fortran-lang.discourse.group/t/why-should-i-use-cmake/953)._
