Skip to content

Move hipfort library to a compiler-specific subdirectory#265

Open
cgmb wants to merge 1 commit intoROCm:developfrom
cgmb:multi-compiler-layout
Open

Move hipfort library to a compiler-specific subdirectory#265
cgmb wants to merge 1 commit intoROCm:developfrom
cgmb:multi-compiler-layout

Conversation

@cgmb
Copy link
Collaborator

@cgmb cgmb commented Sep 26, 2025

Motivation

Change the hipfort install directory layout to prevent fortran compilers from linking against a copy of the hipfort library that has been built with a different compiler. This adopts the convention proposed by Alistair McKinstry for the Debian project for supporting multiple fortran toolchains side-by-side in the same FHS root. The scope of this PR, however, is limited to the archive file. To fully adopt the Debian convention, the mod files would also have to move.

Technical Details

This change updates the default installation LIBDIR to include the compiler name.

Test Plan

It should be verified that the hipfort library is found in "/opt/rocm-7.0.1/lib/fortran/amdflang/libhipfort-amdgcn.a" after installing the hipfort package, and that libraries using find_package(hipfort) and linking against targets such as hipfort::hip continue to build and link correctly.

Test Result

https://math-ci.amd.com/job/main/job/precheckin/job/hipfort/view/change-requests/job/PR-265/

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates hipfort’s install layout to avoid cross-toolchain Fortran linking issues by placing the static library archive under a compiler-specific subdirectory.

Changes:

  • Adds a multi-toolchain install layout option and derives the compiler name from CMAKE_Fortran_COMPILER.
  • Updates library/archive installation destinations to include a compiler-specific subdirectory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
CMakeLists.txt Introduces compiler-name detection and changes default CMAKE_INSTALL_LIBDIR based on a new multi-toolchain layout option.
lib/CMakeLists.txt Adjusts hipfort-amdgcn install destinations to append a compiler-specific library subdirectory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +51
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_INSTALL_LIBDIR is already being set to include ${FORTRAN_LIBRARY_SUBDIR} in the top-level CMakeLists when HIPFORT_MULTITOOLCHAIN_LAYOUT is ON. Appending /${FORTRAN_LIBRARY_SUBDIR} again here results in a duplicated install path like .../lib/fortran/<compiler>/fortran/<compiler>/libhipfort-amdgcn.a. Consider using ${CMAKE_INSTALL_LIBDIR} directly here (or alternatively keep CMAKE_INSTALL_LIBDIR as lib and only append the compiler subdir at this install site, but not both).

Suggested change
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +46
option(HIPFORT_MULTITOOLCHAIN_LAYOUT "Install library files to toolchain-specific subdirectories" ON)
if(HIPFORT_MULTITOOLCHAIN_LAYOUT)
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")
else()
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
endif()
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting CMAKE_INSTALL_LIBDIR to lib/${FORTRAN_LIBRARY_SUBDIR} changes all install destinations that rely on CMAKE_INSTALL_LIBDIR (e.g., the CMake package files currently installed under ${CMAKE_INSTALL_LIBDIR}/cmake/hipfort). This appears to move hipfort-config.cmake/export files into lib/fortran/<compiler>/cmake/hipfort, which will typically break find_package(hipfort) (and also goes beyond the PR description’s stated scope of only moving the archive). Consider keeping the package/config install location stable (e.g., lib/cmake/hipfort) and using a separate variable just for the Fortran archive destination.

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +43
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FORTRAN_LIBRARY_SUBDIR is introduced as a cache variable without a HIPFORT_ prefix. Since CMake cache variables are global, this name is easy to collide with other projects/toolchains; consider renaming it to something project-scoped (e.g., HIPFORT_FORTRAN_LIBRARY_SUBDIR) and updating references accordingly.

Suggested change
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")
set(HIPFORT_FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${HIPFORT_FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +45
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")
else()
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_INSTALL_LIBDIR and FORTRAN_LIBRARY_SUBDIR are being written to the cache with values that depend on HIPFORT_MULTITOOLCHAIN_LAYOUT and the detected compiler name. Because set(... CACHE ...) won’t update an existing cache entry, toggling HIPFORT_MULTITOOLCHAIN_LAYOUT (or reconfiguring with a different Fortran compiler in the same build dir) won’t actually update these paths unless the user manually clears the cache. Consider only initializing these cache entries when they’re not already defined (or explicitly managing updates when the option changes).

Suggested change
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory")
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory")
else()
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
set(FORTRAN_LIBRARY_SUBDIR "fortran/${FCNAME}" CACHE STRING "Compiler-specific library symlink subdirectory" FORCE)
set(CMAKE_INSTALL_LIBDIR "lib/${FORTRAN_LIBRARY_SUBDIR}" CACHE STRING "Library install directory" FORCE)
else()
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory" FORCE)

Copilot uses AI. Check for mistakes.
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