1
0

RelAndAbsPath.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. file(MAKE_DIRECTORY "tmp${srcdir}")
  11. configure_file(testCWD "tmp${srcdir}/testNoSuchFile" COPYONLY)
  12. find_program(PROG_ABS
  13. NAMES "${srcdir}/testNoSuchFile"
  14. PATHS "${CMAKE_CURRENT_BINARY_DIR}/tmp"
  15. NO_DEFAULT_PATH
  16. )
  17. message(STATUS "PROG_ABS='${PROG_ABS}'")
  18. find_program(PROG_ABS_NPD
  19. NAMES "${srcdir}/testNoSuchFile"
  20. PATHS "${CMAKE_CURRENT_BINARY_DIR}/tmp"
  21. NAMES_PER_DIR
  22. NO_DEFAULT_PATH
  23. )
  24. message(STATUS "PROG_ABS_NPD='${PROG_ABS_NPD}'")
  25. # ./testCWD should not be found without '.' being in the path list.
  26. configure_file(testCWD testCWD COPYONLY)
  27. find_program(PROG_CWD
  28. NAMES testCWD
  29. NO_DEFAULT_PATH
  30. )
  31. message(STATUS "PROG_CWD='${PROG_CWD}'")
  32. find_program(PROG_CWD_NPD
  33. NAMES testCWD
  34. NAMES_PER_DIR
  35. NO_DEFAULT_PATH
  36. )
  37. message(STATUS "PROG_CWD_NPD='${PROG_CWD_NPD}'")
  38. # Confirm that adding '.' to path does locate ./testCWD.
  39. find_program(PROG_CWD_DOT
  40. NAMES testCWD
  41. PATHS .
  42. NO_DEFAULT_PATH
  43. )
  44. message(STATUS "PROG_CWD_DOT='${PROG_CWD_DOT}'")
  45. find_program(PROG_CWD_DOT_NPD
  46. NAMES testCWD
  47. PATHS .
  48. NAMES_PER_DIR
  49. NO_DEFAULT_PATH
  50. )
  51. message(STATUS "PROG_CWD_DOT_NPD='${PROG_CWD_DOT_NPD}'")