Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: Get the complete representation of a path minus relative elements

Tags:

cmake

I want to take a variable that has been set to a combination of path elements (potentially both absolute and relative) and get the absolute path from it. Something like what boost::filesystem::system_complete() does in C++. For example, I have something like:

set(EXTERNAL_LIB_DIR "${CMAKE_SOURCE_DIR}/../external" CACHE PATH "Location of externals")

which works but in the UI it's a bit ugly, as it might end up looking like C:/dev/repo/tool/../external. I'm wondering if there's a CMake built-in command to turn that into C:/dev/repo/external before I go and script a macro to do it. find_path kind of does this, but it requires that the path already exist and something worth searching for be there. I want it to work whether the path exists or not (I might use it for an overridden CMAKE_INSTALL_PREFIX default, for example).

like image 530
Mike E Avatar asked Mar 21 '12 17:03

Mike E


1 Answers

You can use:

get_filename_component(NEW_VAR ${EXTERNAL_LIB_DIR} REALPATH)
like image 79
tibur Avatar answered Oct 31 '22 08:10

tibur