# Advice on CMake code (total newbie here)

**URL:** <https://discourse.cmake.org/t/advice-on-cmake-code-total-newbie-here/5575>\
**Category:** Code\
**Created:** [April 29, 2022, 4:47pm UTC](https://discourse.cmake.org/t/advice-on-cmake-code-total-newbie-here/5575 "2022-04-29T16:47:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelv](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angelv/32/2382_2.png) [@angelv](https://discourse.cmake.org/u/angelv)\
**Post date:** [April 29, 2022, 4:47pm UTC](https://discourse.cmake.org/t/advice-on-cmake-code-total-newbie-here/5575/1 "2022-04-29T16:47:18Z")

</div>

Hello,

I just wrote my first CMake code today, after reading part of the CMake tutorial yesterday and while it does work so far, I was hoping to get some advice from more experienced CMakes users, since I’m sure the code is not very elegant and could be improved.

All the source code is in the project’s `src` directory, it is hybrid `MPI+OpenMP` code written in `Fortran+C` and it uses `HDF5`. By default I want a `RELEASE` build and the code installed in the build directory itself. I have two user options to select whether `OpenMP` (`-DOpenMP`) and the `C` code (`-DGAUSS_C`) should be used.

My main concern is that the code will be installed in different environments, with different compilers and compiler versions, so I need to take care of that in a clean and robust way. So far I have tried with different compilers: `gnu`, `intel` and `cray`.

I just have two `CMakeLists.txt` files, and I would be really grateful if you could give me some advice/suggestions on how to improve them. Since I cannot upload files here, I link them with `transfer.sh`. The file in the root directory: [https://transfer.sh/XGpanD/CMakeLists.txt](https://transfer.sh/XGpanD/CMakeLists.txt) and the one in the `src` directory: [https://transfer.sh/LYpTQ5/src\_CMakeLists.txt](https://transfer.sh/LYpTQ5/src_CMakeLists.txt)

Many thanks,  
AdV
