REPLACE_ITEM.cmake.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. cmake_policy(SET CMP0140 NEW)
  2. include ("${RunCMake_SOURCE_DIR}/check_errors.cmake")
  3. unset (errors)
  4. set (reference "a/b/c.e.f")
  5. cmake_path (REPLACE_FILENAME reference "x.y")
  6. set(output "$<PATH:REPLACE_FILENAME,a/b/c.e.f,x.y>")
  7. if (NOT output STREQUAL reference)
  8. list (APPEND errors "FILENAME: '${output}' instead of '${reference}'")
  9. endif()
  10. set (reference "a/b/")
  11. cmake_path (REPLACE_FILENAME reference "x.y")
  12. set(output "$<PATH:REPLACE_FILENAME,a/b/,x.y>")
  13. if (NOT output STREQUAL reference)
  14. list (APPEND errors "FILENAME: '${output}' instead of '${reference}'")
  15. endif()
  16. set (reference "a/b/c.e.f")
  17. cmake_path (REPLACE_EXTENSION reference ".x")
  18. set(output "$<PATH:REPLACE_EXTENSION,a/b/c.e.f,.x>")
  19. if (NOT output STREQUAL reference)
  20. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  21. endif()
  22. cmake_path (REPLACE_EXTENSION reference ".y")
  23. set(output "$<PATH:REPLACE_EXTENSION,a/b/c.x,.y>")
  24. if (NOT output STREQUAL reference)
  25. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  26. endif()
  27. cmake_path (REPLACE_EXTENSION reference "")
  28. set(output "$<PATH:REPLACE_EXTENSION,a/b/c.y,>")
  29. if (NOT output STREQUAL reference)
  30. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  31. endif()
  32. set (reference "a/b/c.e.f")
  33. cmake_path (REPLACE_EXTENSION reference ".x" LAST_ONLY)
  34. set(output "$<PATH:REPLACE_EXTENSION,LAST_ONLY,a/b/c.e.f,.x>")
  35. if (NOT output STREQUAL reference)
  36. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  37. endif()
  38. cmake_path (REPLACE_EXTENSION reference ".y" LAST_ONLY)
  39. set(output "$<PATH:REPLACE_EXTENSION,LAST_ONLY,a/b/c.e.x,.y>")
  40. if (NOT output STREQUAL reference)
  41. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  42. endif()
  43. cmake_path (REPLACE_EXTENSION reference "" LAST_ONLY)
  44. set(output "$<PATH:REPLACE_EXTENSION,LAST_ONLY,a/b/c.e.y,>")
  45. if (NOT output STREQUAL reference)
  46. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  47. endif()
  48. set (reference "/a/.b")
  49. cmake_path (REPLACE_EXTENSION reference ".x")
  50. set(output "$<PATH:REPLACE_EXTENSION,/a/.b,.x>")
  51. if (NOT output STREQUAL reference)
  52. list (APPEND errors "EXTENSION: '${output}' instead of '/${reference}'")
  53. endif()
  54. cmake_path (REPLACE_EXTENSION reference ".x" LAST_ONLY)
  55. set(output "$<PATH:REPLACE_EXTENSION,LAST_ONLY,/a/.b.x,.x>")
  56. if (NOT output STREQUAL reference)
  57. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  58. endif()
  59. set (reference "/a/b")
  60. cmake_path (REPLACE_EXTENSION reference ".x")
  61. set(output "$<PATH:REPLACE_EXTENSION,/a/b,.x>")
  62. if (NOT output STREQUAL reference)
  63. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  64. endif()
  65. ######################################
  66. ## tests with list of paths
  67. ######################################
  68. function (compute_reference action new_value)
  69. unset(reference)
  70. foreach (path IN LISTS paths)
  71. cmake_path(${action} path "${new_value}" ${ARGN})
  72. list(APPEND reference "${path}")
  73. endforeach()
  74. return(PROPAGATE reference)
  75. endfunction()
  76. set (paths "a/b/c.e.f" "g/h/i.j.k")
  77. compute_reference(REPLACE_FILENAME "x.y")
  78. set(output "$<PATH:REPLACE_FILENAME,a/b/c.e.f;g/h/i.j.k,x.y>")
  79. if (NOT output STREQUAL reference)
  80. list (APPEND errors "FILENAME: '${output}' instead of '${reference}'")
  81. endif()
  82. set (paths "a/b/c.e.f" "g/h/i.j.k")
  83. compute_reference(REPLACE_EXTENSION ".x")
  84. set(output "$<PATH:REPLACE_EXTENSION,a/b/c.e.f;g/h/i.j.k,.x>")
  85. if (NOT output STREQUAL reference)
  86. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  87. endif()
  88. set (paths "a/b/c.e.f" "g/h/i.j.k")
  89. compute_reference(REPLACE_EXTENSION ".x" LAST_ONLY)
  90. set(output "$<PATH:REPLACE_EXTENSION,LAST_ONLY,a/b/c.e.f;g/h/i.j.k,.x>")
  91. if (NOT output STREQUAL reference)
  92. list (APPEND errors "EXTENSION: '${output}' instead of '${reference}'")
  93. endif()
  94. check_errors("PATH:REPLACE..." ${errors})