How to detect symbolic links?

Does CMake provide the ability to detect if paths or portions of paths/files contain symbolic links?

You can use command if(IS_SYMLINK).


“True if the given name is a symbolic link. Behavior is well-defined only for full paths.”

I’m a bit unclear based off the docs if IS_SYMLINK triggers when only portions of the providing argument are symlinks. Does the whole argument need to be a symlink to evaluate to true?

if(IS_SYMLINK) checks if the full path specified is a symbolic link or not.

If you want to check if some part of the path is a symbolic link, you can expand the path, using file(REAL_PATH), and test for equality with the initial path.

1 Like