CMake: get a complete view of the path minus relative elements

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 user interface it is a little ugly, as it might look like C:/dev/repo/tool/../external. I am wondering if there is a built-in CMake command to turn this into C:/dev/repo/externalbefore I go, and a script macro for that. find_pathit does this, but requires that the path already exists and something worth looking for there. I want it to work whether the path exists or not (I could use it for a CMAKE_INSTALL_PREFIXdefault override , for example).

+5
source share
1 answer

You can use:

get_filename_component(NEW_VAR ${EXTERNAL_LIB_DIR} REALPATH)
+14
source

All Articles