Move hipfort library to a compiler-specific subdirectory#265
Move hipfort library to a compiler-specific subdirectory#265cgmb wants to merge 1 commit intoROCm:developfrom
Conversation
There was a problem hiding this comment.
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.
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR} | ||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/${FORTRAN_LIBRARY_SUBDIR} |
There was a problem hiding this comment.
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).
| 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} |
| 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() |
There was a problem hiding this comment.
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.
| 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") |
There was a problem hiding this comment.
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.
| 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") |
| 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") |
There was a problem hiding this comment.
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).
| 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) |
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 ashipfort::hipcontinue to build and link correctly.Test Result
https://math-ci.amd.com/job/main/job/precheckin/job/hipfort/view/change-requests/job/PR-265/