Debian Codegraph @

Tests/RunCMake/find_program/RelAndAbsPath.cmake

raw
1 # testNoSuchFile should only be found if the file absolute path is
2 # incorrectly prepended with the search path.
3
4 function(strip_windows_path_prefix p outvar)
5 if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
6 string(REGEX REPLACE "^.:" "" p "${p}")
7 endif()
8 set(${outvar} "${p}" PARENT_SCOPE)
9 endfunction()
10
11 strip_windows_path_prefix("${CMAKE_CURRENT_SOURCE_DIR}" srcdir)
12
13 configure_file(testCWD "tmp${srcdir}/testNoSuchFile" COPYONLY)
14
15 find_program(PROG_ABS
16 NAMES "${srcdir}/testNoSuchFile"
17 PATHS "${CMAKE_CURRENT_BINARY_DIR}/tmp"
18 NO_DEFAULT_PATH
19 )
20 message(STATUS "PROG_ABS='${PROG_ABS}'")
21
22 find_program(PROG_ABS_NPD
23 NAMES "${srcdir}/testNoSuchFile"
24 PATHS "${CMAKE_CURRENT_BINARY_DIR}/tmp"
25 NAMES_PER_DIR
26 NO_DEFAULT_PATH
27 )
28 message(STATUS "PROG_ABS_NPD='${PROG_ABS_NPD}'")
29
30 # ./testCWD should not be found without '.' being in the path list.
31
32 configure_file(testCWD testCWD COPYONLY)
33
34 find_program(PROG_CWD
35 NAMES testCWD
36 NO_DEFAULT_PATH
37 )
38 message(STATUS "PROG_CWD='${PROG_CWD}'")
39
40
41 set(CMAKE_PREFIX_PATH ".")
42 # On some platforms / dashboards the current working
43 # directory can be in PATH or other search locations
44 # so disable all searching to make sure this fails
45 set(CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH OFF)
46 set(CMAKE_FIND_USE_CMAKE_PATH OFF)
47 set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH OFF)
48 set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH OFF)
49 set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH OFF)
50 find_program(PROG_CWD
51 NAMES testCWD
52 )
53 message(STATUS "PROG_CWD='${PROG_CWD}'")
54
55 set(CMAKE_PREFIX_PATH ".")
56 set(CMAKE_FIND_USE_CMAKE_PATH ON)
57 find_program(PROG_CWD
58 NAMES testCWD
59 )
60 message(STATUS "PROG_CWD='${PROG_CWD}'")
61
62 find_program(PROG_CWD_NPD
63 NAMES testCWD
64 NAMES_PER_DIR
65 NO_DEFAULT_PATH
66 )
67 message(STATUS "PROG_CWD_NPD='${PROG_CWD_NPD}'")
68
69 # Confirm that adding '.' to path does locate ./testCWD.
70
71 find_program(PROG_CWD_DOT
72 NAMES testCWD
73 PATHS .
74 NO_DEFAULT_PATH
75 )
76 message(STATUS "PROG_CWD_DOT='${PROG_CWD_DOT}'")
77
78 find_program(PROG_CWD_DOT_NPD
79 NAMES testCWD
80 PATHS .
81 NAMES_PER_DIR
82 NO_DEFAULT_PATH
83 )
84 message(STATUS "PROG_CWD_DOT_NPD='${PROG_CWD_DOT_NPD}'")