# Incorrect module flag set in Intel Fortran compiler

**URL:** https://discourse.cmake.org/t/incorrect-module-flag-set-in-intel-fortran-compiler/11707
**Category:** Code
**Created:** [September 17, 2024, 10:16am UTC](https://discourse.cmake.org/t/incorrect-module-flag-set-in-intel-fortran-compiler/11707 "2024-09-17T10:16:04Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)
#### Post date: [September 17, 2024, 10:16am UTC](https://discourse.cmake.org/t/incorrect-module-flag-set-in-intel-fortran-compiler/11707/1 "2024-09-17T10:16:05Z")

</div>

Hi, in a Fortran project I need to place generated binary module files (`.mod`) in a given directory `modules`. I have used the command  
`set(CMAKE_Fortran_MODULE_DIRECTORY modules)`  
This configuration works using the gnu compiler gfortran since it adds the flag  
`-Jmodules`. But, when an Intel compiler is invoked ( by the command `set(CMAKE_Fortran_COMPILER_ID "Intel")` the compilation fails since CMake uses always the GNU flag `-Jmodules` instead of the right Intel one `-module modules`. How could one fix this error? Thanks!

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 17, 2024, 10:28am UTC](https://discourse.cmake.org/t/incorrect-module-flag-set-in-intel-fortran-compiler/11707/2 "2024-09-17T10:28:11Z")

</div>

The compiler selection is not done using `CMAKE_Fortran_COMPILER_ID` variable (this one is initialized by CMake, so should be read-only for the user).  
To specify the compiler, you can use the [FC](https://cmake.org/cmake/help/latest/envvar/FC.html) environment variable or the [CMAKE\_Fortran\_COMPILER](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER.html#variable:CMAKE_%3CLANG%3E_COMPILER) variable.
