NO_CACHE.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. find_program(PROG_A
  2. NAMES testA
  3. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  4. NO_CACHE
  5. NO_DEFAULT_PATH
  6. )
  7. if (DEFINED CACHE{PROG_A})
  8. message(SEND_ERROR "Cache variable defined: PROG_A")
  9. endif()
  10. message(STATUS "PROG_A='${PROG_A}'")
  11. find_program(PROG_AandB
  12. NAMES testAandB
  13. NO_CACHE
  14. )
  15. if (DEFINED CACHE{PROG_AandB})
  16. message(SEND_ERROR "Cache variable defined: PROG_AandN")
  17. endif()
  18. message(STATUS "PROG_AandB='${PROG_AandB}'")
  19. cmake_policy(SET CMP0125 OLD)
  20. message(STATUS "")
  21. message(STATUS "Policy CMP0125 = OLD")
  22. file(REMOVE "${CMAKE_BINARY_DIR}/testA")
  23. set(PROG_cache "unknown" CACHE FILEPATH "")
  24. find_program(PROG_cache
  25. NAMES testA
  26. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  27. NO_CACHE
  28. NO_DEFAULT_PATH
  29. )
  30. if (NOT DEFINED CACHE{PROG_cache})
  31. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  32. endif()
  33. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  34. unset(PROG_cache CACHE)
  35. message(STATUS "PROG_cache='${PROG_cache}'")
  36. set(PROG_cache "testA" CACHE FILEPATH "")
  37. unset(PROG_cache)
  38. find_program(PROG_cache
  39. NAMES testA
  40. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  41. NO_CACHE
  42. NO_DEFAULT_PATH
  43. )
  44. if (NOT DEFINED CACHE{PROG_cache})
  45. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  46. endif()
  47. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  48. unset(PROG_cache CACHE)
  49. message(STATUS "PROG_cache='${PROG_cache}'")
  50. set(PROG_cache "testA" CACHE FILEPATH "")
  51. unset(PROG_cache)
  52. # simulate cache variable defined in command line
  53. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/A/testA" DESTINATION "${CMAKE_BINARY_DIR}")
  54. set_property(CACHE PROG_cache PROPERTY TYPE UNINITIALIZED)
  55. find_program(PROG_cache
  56. NAMES testA
  57. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  58. NO_CACHE
  59. NO_DEFAULT_PATH
  60. )
  61. if (NOT DEFINED CACHE{PROG_cache})
  62. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  63. endif()
  64. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  65. unset(PROG_cache CACHE)
  66. message(STATUS "PROG_cache='${PROG_cache}'")
  67. cmake_policy(SET CMP0125 NEW)
  68. message(STATUS "")
  69. message(STATUS "Policy CMP0125 = NEW")
  70. file(REMOVE "${CMAKE_BINARY_DIR}/testA")
  71. set(PROG_cache "unknown" CACHE FILEPATH "")
  72. find_program(PROG_cache
  73. NAMES testA
  74. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  75. NO_CACHE
  76. NO_DEFAULT_PATH
  77. )
  78. if (NOT DEFINED CACHE{PROG_cache})
  79. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  80. endif()
  81. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  82. unset(PROG_cache CACHE)
  83. message(STATUS "PROG_cache='${PROG_cache}'")
  84. set(PROG_cache "testA" CACHE FILEPATH "")
  85. unset(PROG_cache)
  86. find_program(PROG_cache
  87. NAMES testA
  88. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  89. NO_CACHE
  90. NO_DEFAULT_PATH
  91. )
  92. if (NOT DEFINED CACHE{PROG_cache})
  93. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  94. endif()
  95. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  96. unset(PROG_cache CACHE)
  97. message(STATUS "PROG_cache='${PROG_cache}'")
  98. set(PROG_cache "testA" CACHE FILEPATH "")
  99. unset(PROG_cache)
  100. # simulate cache variable defined in command line
  101. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/A/testA" DESTINATION "${CMAKE_BINARY_DIR}")
  102. set_property(CACHE PROG_cache PROPERTY TYPE UNINITIALIZED)
  103. find_program(PROG_cache
  104. NAMES testA
  105. PATHS ${CMAKE_CURRENT_SOURCE_DIR}/A
  106. NO_CACHE
  107. NO_DEFAULT_PATH
  108. )
  109. if (NOT DEFINED CACHE{PROG_cache})
  110. message(SEND_ERROR "Cache variable not defined: PROG_cache")
  111. endif()
  112. message(STATUS "CACHED PROG_cache='$CACHE{PROG_cache}'")
  113. unset(PROG_cache CACHE)
  114. message(STATUS "PROG_cache='${PROG_cache}'")