Feature request/bug report: Crazy dark magic preference for ifort over GFortran and very curious choice of Fortran compiler
Can the compiler finding logic for Fortran be improved? It would be really nice if CMake looked at the compilers available on the PATH and, if only one Fortran compiler is on the PATH, CMake gave preference to that compiler. My experimentation seems to indicate that this is not the case. On my work iMac running High Sierra and the latest CMake with virtually all packages installed via the homebrew package manager CMake will use ifort over gfortran EVEN WHEN GFortran IS ON THE PATH DURING THE BUILD AND IFORT IS NOT.
I install ifort (Intel parallel studio beta edition) into /usr/local/Cellar/intel-parallel-studio/2019.0.0
and then I use brew link intel-parallel-studio
when I want the binaries, includes, libs etc. to be on my default path.
However, Homebrew completely sanitizes the PATH and build environment before installing software so that only the package's dependencies (and their dependencies) are in the build environment--i.e., the PATH and other environment variables are sanitized, and reduced to a minimal set with the explicitly enumerated dependencies and some Xcode/system stuff. So when packages that are managed by homebrew are installed, then /usr/local/bin
will NOT be on the $PATH
and ifort
results in a command not found error.
Yest, somehow, when Homebrew installs a package from source that uses CMake as the build system and has a dependency on Fortran /usr/local/bin/ifort
is still getting picked up and used by CMake even though homebrew completely sanitizes the build environment. In this case, both gfortran
and gfortran-8
are in the build environments PATH
and ifort
is not. Nevertheless, CMake still picks up ifort
and uses this as the Fortran compiler. For some additional context and discussion please see: https://github.com/Homebrew/brew/issues/4293
This caused me a great deal of confusion and lost time, because a package was accidentally installed using Homebrew and ifort
. Some time later I was compiling different code with GFortran and started to get error messages about the .mod
files not being compatible. It took quite some time to figure out that the package in question had actually been compiled with ifort
rather than GFortran.
Yes, I know that you can explicitly set FC=/path/to/compiler
or -DCMAKE_Fortran_COMPILER=/path/to/compiler
but it is crazy that CMake doesn't use the only Fortran compiler on the PATH. (GFortran strikes me as a saner choice to be at the front of the search list for Fortran compilers, given its ubiquity and that it is the most popular and widely available free and open source compiler, but I do understand Kitware's desire to support the Scientific/HPC community who often prefer commercial Fortran compilers. But if you put GFortran at the front of the list then no one could accuse you of playing favorites with the commercial compiler vendors...)
CC: @rouson