Exercise1.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. cmake_minimum_required(VERSION 3.23)
  2. # TODO1: Implement MacroAppend
  3. macro(MacroAppend ListVar Value)
  4. endmacro()
  5. # TODO2: Call MacroAppend, then return the value from FuncAppend
  6. function(FuncAppend ListVar Value)
  7. endfunction()
  8. # Testing for the above, final expected value is "Alpha;Beta;Gamma;Delta"
  9. if(SKIP_TESTS)
  10. return()
  11. endif()
  12. set(Original "Beta;Gamma")
  13. set(Expected "Alpha;Beta;Gamma;Delta")
  14. set(BeginList ${Original})
  15. set(EndList "Alpha")
  16. MacroAppend(BeginList "Delta")
  17. foreach(value IN LISTS BeginList)
  18. MacroAppend(EndList ${value})
  19. endforeach()
  20. if(BeginList STREQUAL Original)
  21. message("MacroAppend unimplemented or did nothing")
  22. elseif(NOT EndList STREQUAL Expected)
  23. message(WARNING "MacroAppend error, final value: ${EndList}")
  24. else()
  25. message("MacroAppend correct")
  26. endif()
  27. set(BeginList ${Original})
  28. set(EndList "Alpha")
  29. FuncAppend(BeginList "Delta")
  30. foreach(value IN LISTS BeginList)
  31. FuncAppend(EndList ${value})
  32. endforeach()
  33. if(BeginList STREQUAL Original)
  34. message("FuncAppend unimplemented or did nothing")
  35. elseif(NOT EndList STREQUAL Expected)
  36. message(WARNING "FuncAppend error, final value: ${EndList}")
  37. else()
  38. message("FuncAppend correct")
  39. endif()
  40. # Bonus Tests
  41. FuncAppend(UndefinedList "Test")
  42. set(EmptyList "")
  43. FuncAppend(EmptyList "Test")
  44. set(FalseList "False")
  45. FuncAppend(FalseList "Test")
  46. if(
  47. (UndefinedList STREQUAL "Test") AND
  48. (EmptyList STREQUAL "Test") AND
  49. (FalseList STREQUAL "False;Test")
  50. )
  51. message("You implemented the empty list case, well done!")
  52. endif()