Building MPICH as an external project results in an odd fortran error - FCMODOUTFLAG not detected.

I’m building several packages of scientific software, for use in my program, and for the life of me, I can’t figure out the behavior I’m seeing. I am unsure that it’s a bug, per se, but something is awry, and I’m not sure where to pin the problem.

One of the packages I’m building is MPICH. I’m using the externalproject_add functionality, and this has typically worked, until recently. I’m building a host of other libraries with it - zstd, zlib, cgal, lib3ds, etc… some before, some after. I’ve used add_dependencies to manage the order in which they should be built, as opposed to using DEPENDS directly inside the externalproject_add function, as some of these may or may not be compiled, depending on what is found on a system.

If I build MPICH first, everything goes smooth. IE
$ make -j MPICH && make

however, if I just use
$make -j

I get an odd Fortran error in MPICH’s configure log - FCMODOUTPUTDIR not detected.

It seems that either MPICH’s configure script can’t figure out the -J flag from gcc when the build order is changed.

Any thoughts on how to track this down?

System: CentOS 7 x64
Compilers: Developer Toolset {6,7,8,9} (gcc 6.X, 7.X, 8.X 9.X)
CMake: 3.13 - 3.17
MPICH: 3.2.1
Make: 4.2.1

Edit: The relevant MPICH section

ExternalProject_Add(MPICH
        URL ${CMAKE_CURRENT_SOURCE_DIR}/@canonical_name@
        URL_MD5 @package_md5@
        PREFIX ${CMAKE_CURRENT_BINARY_DIR}/MPICH
        INSTALL_DIR ${CMAKE_INSTALL_PREFIX}
        UPDATE_COMMAND
            #./autogen.sh
        CONFIGURE_COMMAND 
                ./configure 
                --prefix=<INSTALL_DIR>
                --enable-fast=all
                --enable-fortran=yes
                --enable-cxx=yes
                --enable-threads=multiple
                --enable-static=no 
                --enable-shared=yes
                --enable-strict
                --enable-versioning
                --with-pm=hydra
                --with-sysroot=<INSTALL_DIR>
        BUILD_IN_SOURCE 1
        LOG_CONFIGURE 1
        LOG_BUILD 1
        LOG_INSTALL 1
        TEST_COMMAND ""
        TEST_BEFORE_INSTALL 0
        TEST_EXCLUDE_FROM_MAIN 1
)

Maybe this question is too specific. Generally, I think my question boils down to this -

Is there any reason CMake would modify the detected Fortran compiler during a configure / build, or, is there anything that would modify the internal dependencies?

Clearly, the ordering here matters, as the build succeeds when the build order is handled “manually”.

Thanks,

Kyle