CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cmake_minimum_required(VERSION 2.6)
  2. project(Unset C)
  3. # Local variable
  4. set(x 42)
  5. if(NOT x EQUAL 42)
  6. message(FATAL_ERROR "x!=42")
  7. endif()
  8. if(NOT DEFINED x)
  9. message(FATAL_ERROR "x should be defined!")
  10. endif()
  11. unset(x)
  12. if(DEFINED x)
  13. message(FATAL_ERROR "x should be undefined now!")
  14. endif()
  15. # Local variable test unset via set()
  16. set(x 43)
  17. if(NOT x EQUAL 43)
  18. message(FATAL_ERROR "x!=43")
  19. endif()
  20. set(x)
  21. if(DEFINED x)
  22. message(FATAL_ERROR "x should be undefined now!")
  23. endif()
  24. # Cache variable
  25. set(BAR "test" CACHE STRING "documentation")
  26. if(NOT DEFINED BAR)
  27. message(FATAL_ERROR "BAR not defined")
  28. endif()
  29. # Test interaction of cache entries with variables.
  30. set(BAR "test-var")
  31. if(NOT "$CACHE{BAR}" STREQUAL "test")
  32. message(FATAL_ERROR "\$CACHE{BAR} changed by variable BAR")
  33. endif()
  34. if(NOT "${BAR}" STREQUAL "test-var")
  35. message(FATAL_ERROR "\${BAR} not separate from \$CACHE{BAR}")
  36. endif()
  37. unset(BAR)
  38. if(NOT "${BAR}" STREQUAL "test")
  39. message(FATAL_ERROR "\${BAR} does not fall through to \$CACHE{BAR}")
  40. endif()
  41. # Test unsetting of CACHE entry.
  42. unset(BAR CACHE)
  43. if(DEFINED BAR)
  44. message(FATAL_ERROR "BAR still defined")
  45. endif()
  46. # Test unset(... PARENT_SCOPE)
  47. function(unset_zots)
  48. if(NOT DEFINED ZOT1)
  49. message(FATAL_ERROR "ZOT1 is not defined inside function")
  50. endif()
  51. if(NOT DEFINED ZOT2)
  52. message(FATAL_ERROR "ZOT2 is not defined inside function")
  53. endif()
  54. unset(ZOT1)
  55. unset(ZOT2 PARENT_SCOPE)
  56. if(DEFINED ZOT1)
  57. message(FATAL_ERROR "ZOT1 is defined inside function after unset")
  58. endif()
  59. if(NOT DEFINED ZOT2)
  60. message(FATAL_ERROR
  61. "ZOT2 is not defined inside function after unset(... PARENT_SCOPE)")
  62. endif()
  63. endfunction()
  64. set(ZOT1 1)
  65. set(ZOT2 2)
  66. unset_zots()
  67. if(NOT DEFINED ZOT1)
  68. message(FATAL_ERROR "ZOT1 is not still defined after function")
  69. endif()
  70. if(DEFINED ZOT2)
  71. message(FATAL_ERROR "ZOT2 is still defined after function unset PARENT_SCOPE")
  72. endif()
  73. add_executable(Unset unset.c)