Skip to content

Set Fortran/C compiler from CIME Macros.cmake before project() - #33

Merged
jgfouca merged 1 commit into
mainfrom
ndkeen/fix-cmake-compiler-detection
Aug 3, 2026
Merged

Set Fortran/C compiler from CIME Macros.cmake before project()#33
jgfouca merged 1 commit into
mainfrom
ndkeen/fix-cmake-compiler-detection

Conversation

@ndkeen

@ndkeen ndkeen commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

When cprnc is configured directly by CIME (see
CIME/build_scripts/buildlib.cprnc), a Macros.cmake defining SFC/MPIFC (among other things) is dropped into CMAKE_BINARY_DIR before this CMakeLists.txt is processed. CMAKE_Fortran_COMPILER and CMAKE_C_COMPILER must be set from those variables before the project() call, otherwise CMake falls back to its own default Fortran compiler search (which tries the bare name "f95" first), potentially picking up an unrelated system Fortran compiler instead of the one CIME configured for this machine/compiler (e.g. a stray /usr/bin/f95 built against a different netcdf.mod ABI than the intended toolchain).

Also pre-populate CMAKE_SYSTEM_PROCESSOR from uname -m when not already set, since CIME_initial_setup includes the machine's compiler-specific *.cmake file (e.g. gnu.cmake) before project() has run, and some of those files key off CMAKE_SYSTEM_PROCESSOR (e.g. to select -mcmodel on aarch64), which CMake only populates once project() has detected the toolchain.

When cprnc is configured directly by CIME (see
CIME/build_scripts/buildlib.cprnc), a Macros.cmake defining SFC/MPIFC
(among other things) is dropped into CMAKE_BINARY_DIR before this
CMakeLists.txt is processed. CMAKE_Fortran_COMPILER and
CMAKE_C_COMPILER must be set from those variables before the
project() call, otherwise CMake falls back to its own default
Fortran compiler search (which tries the bare name "f95" first),
potentially picking up an unrelated system Fortran compiler instead
of the one CIME configured for this machine/compiler (e.g. a stray
/usr/bin/f95 built against a different netcdf.mod ABI than the
intended toolchain).

Also pre-populate CMAKE_SYSTEM_PROCESSOR from `uname -m` when not
already set, since CIME_initial_setup includes the machine's
compiler-specific *.cmake file (e.g. gnu.cmake) before project() has
run, and some of those files key off CMAKE_SYSTEM_PROCESSOR (e.g. to
select -mcmodel on aarch64), which CMake only populates once
project() has detected the toolchain.
@ndkeen
ndkeen requested a review from jgfouca July 31, 2026 21:47
@ndkeen

ndkeen commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Had some issues on vista when building a test (ie when cprnc is needed) and found this worked by stuffing changes into cprnc as opposed to other places. It initially looks innocent, but have not tested on other machines.

@jgfouca
jgfouca merged commit 8aa01c2 into main Aug 3, 2026
1 check passed
@jgfouca
jgfouca deleted the ndkeen/fix-cmake-compiler-detection branch August 3, 2026 17:13
ndkeen added a commit to E3SM-Project/E3SM that referenced this pull request Aug 4, 2026
Adding vista-gh and vista-gg machine configs for testing on the vista machine at TACC.
vista-gh are grace-hopper nodes (1 grace CPU, 1 nvidia hopper GPU).
vista-gg are grace-grace nodes (2 grace CPU's)
Primary purpose is to save the machine configs for future testing when/if needed.
Only minor testing was done, including ne30 eamxx/eam cases.
The change in cime_config/machines/cmake_macros/gnugpu.cmake mimics change in cime_config/machines/cmake_macros/gnu.cmake for different CPU archs.
Testing with nvidia also revealed an improvement in components/cmake/build_model.cmake
They have gcc v15 installed and I made one minor fix here to share/timing/private.h to allow building.

There are also some minor changes in ekat/cprnc (already in PR's) required for the testing I did.
E3SM-Project/EKAT#459
ESMCI/cprnc#33

[bfb]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants