ParentPullingRecursive.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. cmake_minimum_required(VERSION 3.0)
  2. project(Minimal NONE)
  3. function(report where)
  4. message("----------")
  5. message("variable values at ${where}:")
  6. foreach(var IN ITEMS
  7. top_implicit_inner_set top_implicit_inner_unset
  8. top_explicit_inner_set top_explicit_inner_unset top_explicit_inner_tounset
  9. top_implicit_outer_set top_explicit_outer_unset
  10. top_explicit_outer_set top_explicit_outer_unset top_explicit_outer_tounset
  11. outer_implicit_inner_set outer_implicit_inner_unset
  12. outer_explicit_inner_set outer_explicit_inner_unset outer_explicit_inner_tounset)
  13. if(DEFINED ${var})
  14. message("${var}: -->${${var}}<--")
  15. else()
  16. message("${var}: <undefined>")
  17. endif()
  18. endforeach()
  19. message("----------")
  20. endfunction()
  21. macro(set_values upscope downscope value)
  22. # Pull the value in implicitly.
  23. set(dummy ${${upscope}_implicit_${downscope}_set})
  24. set(dummy ${${upscope}_implicit_${downscope}_unset})
  25. # Pull it down explicitly.
  26. set(${upscope}_explicit_${downscope}_set "${value}" PARENT_SCOPE)
  27. set(${upscope}_explicit_${downscope}_unset "${value}" PARENT_SCOPE)
  28. set(${upscope}_explicit_${downscope}_tounset PARENT_SCOPE)
  29. endmacro()
  30. function(inner)
  31. report("inner start")
  32. set_values(top inner inner)
  33. set_values(outer inner inner)
  34. report("inner end")
  35. endfunction()
  36. function(outer)
  37. report("outer start")
  38. set_values(top outer outer)
  39. # Set values for inner to manipulate.
  40. set(outer_implicit_inner_set outer)
  41. set(outer_implicit_inner_unset)
  42. set(outer_explicit_inner_set outer)
  43. set(outer_explicit_inner_unset)
  44. set(outer_explicit_inner_tounset outer)
  45. report("outer before inner")
  46. inner()
  47. report("outer after inner")
  48. # Do what inner does so that we can test the values that inner should have
  49. # pulled through to here.
  50. set_values(top inner outer)
  51. report("outer end")
  52. endfunction()
  53. # variable name is:
  54. #
  55. # <upscope>_<pulltype>_<downscope>_<settype>
  56. #
  57. # where the value is the name of the scope it was set in. The scopes available
  58. # are "top", "outer", and "inner". The pull type may either be "implicit" or
  59. # "explicit" based on whether the pull is due to a variable dereference or a
  60. # PARENT_SCOPE setting. The settype is "set" where both scopes set a value,
  61. # "unset" where upscope unsets it and downscope sets it, and "tounset" where
  62. # upscope sets it and downscope unsets it.
  63. #
  64. # We test the following combinations:
  65. #
  66. # - outer overriding top's values;
  67. # - inner overriding top's values;
  68. # - inner overriding outer's values; and
  69. # - outer overriding inner's values in top after inner has run.
  70. # Set values for inner to manipulate.
  71. set(top_implicit_inner_set top)
  72. set(top_implicit_inner_unset)
  73. set(top_explicit_inner_set top)
  74. set(top_explicit_inner_unset)
  75. set(top_explicit_inner_tounset top)
  76. # Set values for outer to manipulate.
  77. set(top_implicit_outer_set top)
  78. set(top_implicit_outer_unset)
  79. set(top_explicit_outer_set top)
  80. set(top_explicit_outer_unset)
  81. set(top_explicit_outer_tounset top)
  82. report("top before calls")
  83. outer()
  84. report("top after calls")