Skip to content

Add example CMake toolchain files and fix compiler-dependent line-length flag#347

Open
amontoison wants to merge 4 commits into
ROCm:developfrom
amontoison:feature/cmake-toolchains
Open

Add example CMake toolchain files and fix compiler-dependent line-length flag#347
amontoison wants to merge 4 commits into
ROCm:developfrom
amontoison:feature/cmake-toolchains

Conversation

@amontoison

@amontoison amontoison commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Addresses #81 (move architecture/compiler-dependent CMake variables into toolchain files).

Toolchain files

Adds cmake/toolchains/ with ready-to-use, commented toolchain files, selectable via -DCMAKE_TOOLCHAIN_FILE:

Toolchain file Compiler Backend
amdflang.cmake amdflang (ROCm LLVM Flang) AMD ROCm (recommended default)
gnu.cmake gfortran AMD ROCm
intel.cmake ifx (Intel LLVM) AMD ROCm
intel-classic.cmake ifort (EOL) AMD ROCm
cray.cmake Cray ftn AMD ROCm
nvhpc.cmake nvfortran NVIDIA/CUDA

They only set the compiler (plus optional ROCM_PATH/HIP_PLATFORM hints). Pure CMake toolchain files, no dependency on hipfc (compatible with its removal in #334).

Fix: line-length flag applied for every build type

-ffree-line-length-none was only added in the RELEASE flag set, so a default-build-type configure produced Line truncated errors with GNU (the generated bindings have code lines up to 399 columns). Moved it to the general flags. It is applied via SET_COMPILE_FLAG, which compile-tests the flag, so:

  • GNU gets -ffree-line-length-none.
  • amdflang / ifx impose no free-form line limit and reject the flag, so it is silently skipped (they build unmodified).
  • Cray is excluded by the existing guard (no limit).

Verified

  • amdflang.cmake (default) and gnu.cmake both configure and fully build without -DCMAKE_BUILD_TYPE=RELEASE (all modules, both install trees, 84 .mod files).
  • ifx/ifort/ftn/nvfortran not available in the test environment, so those toolchains are provided as documented examples.

Known limitation (classic ifort)

Classic ifort is EOL and caps free-form source lines at 132 columns with no extension option, so it cannot compile the current bindings as-is; intel-classic.cmake documents this and points users to ifx. Full ifort support would require the generator to wrap long lines, a larger and separate change.

Documentation

Documented the toolchain files in the Sphinx install guide (docs/install/install.rst): a new Toolchain files section with the same table, cross-referenced from the compiler prerequisites and the quick-start guide, so the published docs match the README.

@amontoison
amontoison requested review from a team and cgmb as code owners July 24, 2026 02:36
@amontoison
amontoison force-pushed the feature/cmake-toolchains branch from c1b6004 to 156ff81 Compare July 24, 2026 02:46
@amontoison amontoison changed the title Add example CMake toolchain files (GNU, Cray, NVHPC) Add example CMake toolchain files and fix compiler-dependent line-length flag Jul 24, 2026
@amontoison amontoison added discussion testing Issue describing testing needs or current testing infrastructure deficiencies labels Jul 24, 2026
@amontoison
amontoison force-pushed the feature/cmake-toolchains branch from 156ff81 to 2b2d9e0 Compare July 24, 2026 23:30
Add a "Toolchain files" section to the Sphinx install guide describing
cmake/toolchains/ (amdflang, gnu, intel, intel-classic, cray, nvhpc) and
how to select one with -DCMAKE_TOOLCHAIN_FILE, mirroring the README.
Cross-reference it from the compiler prerequisites and the quick-start guide.
Clarify in each toolchain file that free-form parsing and C preprocessing
are enabled centrally by hipfort (CMAKE_Fortran_FORMAT and
CMAKE_Fortran_PREPROCESS), and that CMake selects the per-compiler flag
automatically (-cpp, -fpp, -Mpreprocess, -eZ), so users should not add
these flags by hand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion testing Issue describing testing needs or current testing infrastructure deficiencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant