cmake_minimum_required(VERSION 2.8.12) project(relative_path_test) function(check_relative_path _src _dest _expected) file(RELATIVE_PATH _rel_path "${_src}" "${_dest}") if ("${_rel_path}" STREQUAL "${_expected}") message(STATUS "Test passed: relative path from ${_src} to ${_dst} is ${_rel_path}") else() message(WARNING "Test failed: relative path from ${_src} to ${_dst} returned ${_rel_path}, should be ${_expected}") endif() endfunction() check_relative_path("/usr/share" "/bin/bash" "../../bin/bash") check_relative_path("/usr/./share/" "/bin/bash" "../../bin/bash") check_relative_path("/usr/share/../bin/" "/bin/bash" "../../bin/bash")