Set Fortran/C compiler from CIME Macros.cmake before project() - #33
Merged
Conversation
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.
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
approved these changes
Aug 3, 2026
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 -mwhen 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.