Fix CMake package config generation with CMAKE_INSTALL_MODE=SYMLINK#283
Fix CMake package config generation with CMAKE_INSTALL_MODE=SYMLINK#283PeterCDMcLean wants to merge 4 commits intodevelopfrom
Conversation
When CMAKE_INSTALL_MODE=SYMLINK is used, CMake creates symlinks instead of copying files during install. The package config file generation was using REALPATH which follows symlinks to the actual file, breaking the relative path computation. Changed from REALPATH to ABSOLUTE so that symlink paths are preserved, allowing the relative path calculation to work correctly with both copy and symlink install modes. This fixes build failures for packages like hipBLASLt and rocRoller when using CMAKE_INSTALL_MODE=SYMLINK. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b4593c9 to
517b8b8
Compare
|
REALPATH vs ABSOLUTE Explanation The issue is in how CMake resolves file paths when dealing with symlinks: REALPATH
REALPATH returns: /workspace/build/math-libs/BLAS/hipBLAS-common/build/hipblas-common-config.cmake ABSOLUTE
ABSOLUTE returns: /workspace/build/math-libs/BLAS/hipBLAS-common/dist/lib/cmake/hipblas-common/hipblas-common-config.cmake The Problem When CMAKE_INSTALL_MODE=SYMLINK, CMake creates symlinks instead of copying files during install:
The config file code tries to compute PACKAGE_PREFIX_DIR by going up 3 directories: With REALPATH (BROKEN):
get_filename_component(_ROCM_CMAKE_CURRENT_LIST_DIR_REAL "${_ROCM_CMAKE_CURRENT_LIST_FILE_REAL}" DIRECTORY)
get_filename_component(PACKAGE_PREFIX_DIR "${_ROCM_CMAKE_CURRENT_LIST_DIR_REAL}/../../../" ABSOLUTE)
With ABSOLUTE (CORRECT):
get_filename_component(_ROCM_CMAKE_CURRENT_LIST_DIR_ABS "${_ROCM_CMAKE_CURRENT_LIST_FILE_ABS}" DIRECTORY)
get_filename_component(PACKAGE_PREFIX_DIR "${_ROCM_CMAKE_CURRENT_LIST_DIR_ABS}/../../../" ABSOLUTE)
The fix changes line 73 in ROCMPackageConfigHelpers.cmake from REALPATH to ABSOLUTE so it respects symlink install mode. This makes package config files work correctly whether files are copied or symlinked. |
|
I'm very happy that there are tests that caught this. Trying to understand the context of the failure. Looks like my change doesn't work with PREFIX: Root Cause Analysis The ABSOLUTE fix (changing from REALPATH to ABSOLUTE on line 73) works correctly for standard installations and CMAKE_INSTALL_MODE=SYMLINK, but breaks when using ROCM_PREFIX with rocm_install_symlink_subdir(). Here's why: Path Depth Mismatch When PREFIX=simple is set, the installation structure is: Real files:
Symlinks created by rocm_install_symlink_subdir():
The PACKAGE_RELATIVE_PATH Calculation In rocm_export_targets() with PREFIX: In rocm_configure_package_config_file(): This is correct for the real file location. What Happens with REALPATH (original code) What Happens with ABSOLUTE (the fix) The error message confirms this: Why This Happens The PACKAGE_RELATIVE_PATH is always computed based on the real installation depth (4 levels when PREFIX adds an extra component), but with ABSOLUTE:
Going up 4 levels from a 3-level-deep symlink overshoots by one directory level. Solution Approaches The fix would need to handle this mismatch. Possible approaches:
The ABSOLUTE fix is correct for the use case it was designed for (CMAKE_INSTALL_MODE=SYMLINK without PREFIX), but inadvertently breaks the PREFIX+symlink combination because of this path depth assumption mismatch. |
When CMAKE_INSTALL_MODE=SYMLINK is used, config files are symlinks from the install tree (e.g., lib/cmake/foo/) to the build directory (e.g., build/). The build directory does not preserve the install tree structure, so using REALPATH breaks PACKAGE_PREFIX_DIR calculation. This commit adds a structure check: if navigating from the real path via relative paths returns to the original location, the structure is preserved (PREFIX case) and REALPATH works. Otherwise, fall back to ABSOLUTE to handle CMAKE_INSTALL_MODE=SYMLINK correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
420ccf6 to
b60597e
Compare
…symlink combination CMAKE_INSTALL_MODE with symlink modes (SYMLINK, SYMLINK_OR_COPY, ABS_SYMLINK, ABS_SYMLINK_OR_COPY) cannot be used with the PREFIX argument because the symlink structure created by rocm_install_symlink_subdir() is incompatible with how PACKAGE_PREFIX_DIR is calculated in the generated config files. Changes: - Add error check in ROCMPackageConfigHelpers.cmake to prevent this unsupported combination with a clear error message - Add fail test that verifies the error is properly triggered Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When CMAKE_INSTALL_MODE=SYMLINK is used, CMake creates symlinks instead of copying files during install. The package config file generation was using REALPATH which follows symlinks to the actual file, breaking the relative path computation.
Changed from REALPATH to ABSOLUTE so that symlink paths are preserved, allowing the relative path calculation to work correctly with both copy and symlink install modes.
This fixes build failures for packages like hipBLASLt and rocRoller when using CMAKE_INSTALL_MODE=SYMLINK.
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist