RegexClear.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. cmake_minimum_required (VERSION 3.0)
  2. project (RegexClear C)
  3. function (output_results msg)
  4. message("results from: ${msg}")
  5. message("CMAKE_MATCH_0: -->${CMAKE_MATCH_0}<--")
  6. message("CMAKE_MATCH_1: -->${CMAKE_MATCH_1}<--")
  7. message("CMAKE_MATCH_2: -->${CMAKE_MATCH_2}<--")
  8. message("CMAKE_MATCH_COUNT: -->${CMAKE_MATCH_COUNT}<--")
  9. endfunction ()
  10. function (check_for_success msg)
  11. if (CMAKE_MATCH_1 STREQUAL "0" AND
  12. CMAKE_MATCH_2 STREQUAL "1")
  13. message("Matched string properly")
  14. else ()
  15. message("Failed to match properly")
  16. endif ()
  17. output_results("${msg}")
  18. endfunction ()
  19. function (check_for_failure msg)
  20. if (CMAKE_MATCH_1 STREQUAL "" AND
  21. CMAKE_MATCH_2 STREQUAL "")
  22. message("Matched nothing properly")
  23. else ()
  24. message("Found a match where there should be none")
  25. endif ()
  26. output_results("${msg}")
  27. endfunction ()
  28. macro (do_regex_success msg)
  29. string(REGEX MATCH "(0)(1)" output "01")
  30. check_for_success("${msg}")
  31. endmacro ()
  32. macro (do_regex_failure msg)
  33. string(REGEX MATCH "(0)(1)" output "12")
  34. check_for_failure("${msg}")
  35. endmacro ()
  36. do_regex_success("setting up initial state")
  37. list(INSERT CMAKE_MODULE_PATH 0
  38. "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  39. find_package(dummy) # Ensure cmMakefile::PushScope/PopScope work.
  40. check_for_failure("checking after find_package")
  41. do_regex_failure("clearing out results with a failing match")
  42. do_regex_success("making a successful match before add_subdirectory")
  43. add_subdirectory(subdir)
  44. check_for_success("ensuring the subdirectory did not interfere with the parent") # Ensure that the subdir didn't mess with this scope.