From e16d501129c701127efdd20da8d80c6ecdd081d4 Mon Sep 17 00:00:00 2001 From: Devin Kees <6895754+djkees@users.noreply.github.com> Date: Wed, 2 Sep 2026 10:39:08 -0600 Subject: [PATCH] Define _WIN32 for gfortran when building vendored GFE/pFUnit on Windows (#167) gfortran's -cpp preprocessing doesn't predefine _WIN32 the way a C/C++ compiler does, so FUnit.F90's #ifndef _WIN32 guard around `use pf_RegexFilter` picks the wrong branch on Windows even though CMake's own WIN32 check already excluded that module from the build. See djkees/cea#163. (cherry picked from commit 2fff96d7dfd91a9c554616d0c4c5abcd55343a6d) --- scripts/develop.sh | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/develop.sh b/scripts/develop.sh index 6c7cf8b..9ee8fa0 100755 --- a/scripts/develop.sh +++ b/scripts/develop.sh @@ -108,16 +108,30 @@ if [ "$BUILD_GFE" = true ]; then git clone https://github.com/Goddard-Fortran-Ecosystem/GFE "${GFE}" (cd "${GFE}" && git submodule update --init) fi - cmake -S "${GFE}" -B "${GFE_BUILD}" -G "${GENERATOR}" \ - -DCMAKE_CXX_COMPILER="${CXX}" \ - -DCMAKE_Fortran_COMPILER="${FC}" \ - -DCMAKE_INSTALL_PREFIX="${INSTALL}" \ - -DCMAKE_BUILD_TYPE=Release \ - -DSKIP_MPI=YES \ - -DSKIP_OPENMP=YES \ - -DSKIP_FHAMCREST=YES \ - -DSKIP_ESMF=YES \ + GFE_CMAKE_ARGS=( + -DCMAKE_CXX_COMPILER="${CXX}" + -DCMAKE_Fortran_COMPILER="${FC}" + -DCMAKE_INSTALL_PREFIX="${INSTALL}" + -DCMAKE_BUILD_TYPE=Release + -DSKIP_MPI=YES + -DSKIP_OPENMP=YES + -DSKIP_FHAMCREST=YES + -DSKIP_ESMF=YES -DSKIP_ROBUST=YES + ) + case "$(uname -s)" in + MINGW*|MSYS*|CYGWIN*) + # gfortran's -cpp preprocessor does not predefine _WIN32 the way a + # C/C++ compiler does, but pFUnit's FUnit.F90 guards its + # `use pf_RegexFilter` on `#ifndef _WIN32` while pFUnit's own + # CMakeLists excludes RegexFilter.F90 from the build via CMake's + # own (always-correct) WIN32 variable. Without this define, + # FUnit.F90 fails to compile: it tries to use a module that was + # never built. + GFE_CMAKE_ARGS+=(-DCMAKE_Fortran_FLAGS=-D_WIN32) + ;; + esac + cmake -S "${GFE}" -B "${GFE_BUILD}" -G "${GENERATOR}" "${GFE_CMAKE_ARGS[@]}" cmake --build ${GFE_BUILD} --target install -j ${JOBS} fi