Bad option -fPIE for NAG Fortran
With set(CMAKE_POSITION_INDEPENDENT_CODE True) the flag -fPIE is being passed to the NAG Fortran compiler for source files that get linked into an executable. The compiler doesn't recognize this flag and exits with an error.
The NAG compiler doesn't have any notion of "PIE". its flag for PIC is -PIC. If that is an adequate substitute (I don't understand what the practical difference is), then adding
to the bottom of NAG-Fortran.cmake appears to work fine. Alternatively, because the compiler actually generates C code that it then compiles using the underlying system C compiler, it is possible on Linux, where it uses gcc, to use -fPIE by instead adding
But this will probably not be the same on other platforms that the NAG compiler is available for, so probably not a good choice.