RelAndAbsPath.cmake 2.1 KB

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