Skip to content

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

Merged
sloriot merged 2 commits into
CGAL:mainfrom
RajdeepKushwaha5:fix/cgalconfig-symlink-realpath-v2
Jun 17, 2026
Merged

CGALConfig.cmake: resolve symlinks before computing CGAL_CONFIG_DIR (fix #8521)#9390
sloriot merged 2 commits into
CGAL:mainfrom
RajdeepKushwaha5:fix/cgalconfig-symlink-realpath-v2

Conversation

@RajdeepKushwaha5

@RajdeepKushwaha5 RajdeepKushwaha5 commented Mar 20, 2026

Copy link
Copy Markdown
Member

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

@MaelRL
MaelRL requested a review from lrineau May 21, 2026 15:27
@MaelRL MaelRL added this to the 6.3-beta milestone Jun 3, 2026

@lrineau lrineau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sloriot I approve the patch. This PR is ready for testing.

@sloriot

sloriot commented Jun 17, 2026

Copy link
Copy Markdown
Member

Successfully tested in CGAL-6.3-Ic-11

@sloriot
sloriot merged commit cabec72 into CGAL:main Jun 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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)

5 participants