Exercise2.cmake 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. cmake_minimum_required(VERSION 3.23)
  2. function(FilterFoo OutVar)
  3. # TODO3: Search all the variables in the argument list passed to FilterFoo,
  4. # and place those containing "Foo" into the list named by "OutVar"
  5. set(${OutVar} ${${OutVar}} PARENT_SCOPE)
  6. endfunction()
  7. # Testing for the above
  8. function(check_contains var)
  9. if(NOT var IN_LIST OutList)
  10. message(WARNING "OutList does not contain: ${var}")
  11. set(Failed True PARENT_SCOPE)
  12. endif()
  13. endfunction()
  14. function(check_nonfoo)
  15. list(FILTER ARGN EXCLUDE REGEX Foo)
  16. if(NOT ARGN STREQUAL "")
  17. message(WARNING "OutList contains extra item(s): ${ARGN}")
  18. set(Failed True PARENT_SCOPE)
  19. endif()
  20. endfunction()
  21. if(SKIP_TESTS)
  22. return()
  23. endif()
  24. set(InList FooBar BarBaz FooBaz BazBar QuxFoo BazQux)
  25. FilterFoo(OutList ${InList})
  26. if(NOT DEFINED OutList)
  27. message("FilterFoo unimplemented or does nothing")
  28. return()
  29. endif()
  30. set(Failed False)
  31. check_contains(FooBar)
  32. check_contains(FooBaz)
  33. check_contains(QuxFoo)
  34. check_nonfoo(${OutList})
  35. if(NOT Failed)
  36. message("Success!")
  37. endif()