foreach-var-scope-CMP0124-OLD.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. cmake_policy(SET CMP0124 OLD)
  2. foreach(VAR a b c)
  3. endforeach()
  4. if (NOT DEFINED VAR OR NOT VAR STREQUAL "")
  5. message(SEND_ERROR "Variable 'VAR' not defined or wrong value.")
  6. endif()
  7. set(LIST1 a b c)
  8. set(LIST2 x y z)
  9. foreach(VAR1_1 VAR1_2 IN ZIP_LISTS LIST1 LIST2)
  10. endforeach()
  11. if (NOT DEFINED VAR1_1 OR NOT VAR1_1 STREQUAL ""
  12. OR NOT DEFINED VAR1_2 OR NOT VAR1_2 STREQUAL "")
  13. message(SEND_ERROR "Variables 'VAR1_1' or 'VAR1_2' not defined or wrong value.")
  14. endif()
  15. set (VAR2 OLD)
  16. foreach(VAR2 a b c)
  17. endforeach()
  18. if (NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "OLD")
  19. message(SEND_ERROR "Variable 'VAR2' not defined or wrong value.")
  20. endif()
  21. set (VAR2_2 OLD)
  22. foreach(VAR2_1 VAR2_2 IN ZIP_LISTS LIST1 LIST2)
  23. endforeach()
  24. if (NOT DEFINED VAR2_1 OR NOT VAR2_1 STREQUAL ""
  25. OR NOT DEFINED VAR2_2 OR NOT VAR2_2 STREQUAL "OLD")
  26. message(SEND_ERROR "Variables 'VAR2_1' or 'VAR2_2' not defined or wrong value.")
  27. endif()
  28. set (VAR3 OLD CACHE STRING "")
  29. foreach(VAR3 a b c)
  30. endforeach()
  31. # a normal variable is defined, holding cache variable value
  32. unset(VAR3 CACHE)
  33. if (NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "OLD")
  34. message(SEND_ERROR "Variable 'VAR3' not defined or wrong value.")
  35. endif()
  36. set (VAR3_2 OLD CACHE STRING "")
  37. foreach(VAR3_1 VAR3_2 IN ZIP_LISTS LIST1 LIST2)
  38. endforeach()
  39. # a normal variable is defined, holding cache variable value
  40. unset(VAR3_2 CACHE)
  41. if (NOT DEFINED VAR3_1 OR NOT VAR3_1 STREQUAL ""
  42. OR NOT DEFINED VAR3_2 OR NOT VAR3_2 STREQUAL "OLD")
  43. message(SEND_ERROR "Variables 'VAR3_1' or 'VAR3_2' not defined or wrong value.")
  44. endif()