1 set(bindir ${CMAKE_CURRENT_BINARY_DIR})
4 # Test nonexistent REALPATH & ABSOLUTE resolution
6 get_filename_component(nonexistent1 ${bindir}/THIS_IS_A_NONEXISTENT_FILE REALPATH)
7 get_filename_component(nonexistent2 ${bindir}/THIS_IS_A_NONEXISTENT_FILE ABSOLUTE)
8 if(NOT nonexistent1 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
9 message(FATAL_ERROR "REALPATH is not preserving nonexistent files")
11 if(NOT nonexistent2 STREQUAL "${bindir}/THIS_IS_A_NONEXISTENT_FILE")
12 message(FATAL_ERROR "ABSOLUTE is not preserving nonexistent files")
16 # Test treatment of relative paths
18 foreach(c REALPATH ABSOLUTE)
19 get_filename_component(dir "subdir/THIS_IS_A_NONEXISTENT_FILE" ${c})
20 if(NOT "${dir}" STREQUAL "${bindir}/subdir/THIS_IS_A_NONEXISTENT_FILE")
22 "${c} does not handle relative paths. Expected:\n"
23 " ${bindir}/subdir/THIS_IS_A_NONEXISTENT_FILE\n"
31 # Test symbolic link resolution
34 # file1 => file2 => file3 (real)
35 file(WRITE ${bindir}/file3 "test file")
37 find_program(LN NAMES "ln")
39 # Create symlinks using "ln -s"
40 if(NOT EXISTS ${bindir}/file2)
41 execute_process(COMMAND ${LN} "-s" "${bindir}/file3" "${bindir}/file2")
43 if(NOT EXISTS ${bindir}/file1)
44 execute_process(COMMAND ${LN} "-s" "${bindir}/file2" "${bindir}/file1")
47 get_filename_component(file1 ${bindir}/file1 REALPATH)
48 get_filename_component(file2 ${bindir}/file2 REALPATH)
49 get_filename_component(file3 ${bindir}/file3 REALPATH)
51 if(NOT file3 STREQUAL "${bindir}/file3")
52 message(FATAL_ERROR "CMake fails resolving REALPATH file file3")
55 if(NOT file2 STREQUAL "${bindir}/file3")
56 message(FATAL_ERROR "CMake fails resolving simple symlink")
59 if(NOT file1 STREQUAL "${bindir}/file3")
60 message(FATAL_ERROR "CMake fails resolving double symlink")
64 file(REMOVE ${bindir}/file1)
65 file(REMOVE ${bindir}/file2)
66 if(EXISTS file1 OR EXISTS file2)
67 message(FATAL_ERROR "removal of file1 or file2 failed")
71 file(REMOVE ${bindir}/file3)