Skip to content

CGALConfig.cmake: resolve symlinks before computing CGAL_CONFIG_DIR (fix #8521)#9390

Open
RajdeepKushwaha5 wants to merge 1 commit intoCGAL:mainfrom
RajdeepKushwaha5:fix/cgalconfig-symlink-realpath-v2
Open

CGALConfig.cmake: resolve symlinks before computing CGAL_CONFIG_DIR (fix #8521)#9390
RajdeepKushwaha5 wants to merge 1 commit intoCGAL:mainfrom
RajdeepKushwaha5:fix/cgalconfig-symlink-realpath-v2

Conversation

@RajdeepKushwaha5
Copy link
Contributor

@RajdeepKushwaha5 RajdeepKushwaha5 commented Mar 20, 2026

Summary of Changes

On distributions such as Arch Linux and Fedora where /lib is a symlink to /usr/lib, CMAKE_CURRENT_LIST_FILE may resolve to /lib/cmake/CGAL/CGALConfig.cmake. The subsequent chain of get_filename_component(... DIRECTORY) calls then walks up through the symlink path, producing CGAL_ROOT=/ instead of /usr, and the existence check for include/CGAL/config.h fails — even though CGAL is properly installed.

Fix: resolve the real path of CMAKE_CURRENT_LIST_FILE before extracting the directory. Uses file(REAL_PATH) when available (CMake >= 3.19), with a get_filename_component(... REALPATH) fallback for CMake 3.15–3.18.

Reproducer (from @lrineau's comment):

CGAL_DIR=/lib/cmake/CGAL cmake . -B build
# → CGAL_FOUND=FALSE, even though CGAL is installed

Release Management

 CGAL#8521)

On distributions such as Arch Linux and Fedora where /lib is a symlink to
/usr/lib, CMAKE_CURRENT_LIST_FILE may be reported as
/lib/cmake/CGAL/CGALConfig.cmake.  The subsequent chain of
get_filename_component(... DIRECTORY) calls then walks up through the
symlink path, producing CGAL_ROOT=/ instead of /usr, and the existence
check for include/CGAL/config.h fails, even when CGAL is properly
installed.

Fix: resolve the real path of CMAKE_CURRENT_LIST_FILE before extracting
the directory.  Use file(REAL_PATH) when available (CMake >= 3.19), with
a get_filename_component(... REALPATH) fallback for CMake 3.15-3.18.
Copilot AI review requested due to automatic review settings March 20, 2026 20:16
Copy link
Contributor

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

This PR fixes CGAL’s installed CMake package configuration on systems where /lib is a symlink to /usr/lib (e.g., Arch/Fedora), ensuring CGAL_ROOT is computed from the resolved (real) path of CMAKE_CURRENT_LIST_FILE so CGAL_FOUND is set correctly.

Changes:

  • Resolve symlinks for CMAKE_CURRENT_LIST_FILE before deriving CGAL_CONFIG_DIR.
  • Use file(REAL_PATH) on CMake ≥ 3.19, with a get_filename_component(... REALPATH) fallback for older supported CMake versions.

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

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.

CGALConfig.cmake does not correctly handle /lib -> /usr/lib symlink (solution: use file(REAL_PATH) from CMake 3.19)

2 participants