RemoveEmptyCommands-check.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/exe.vcxproj")
  2. if(NOT EXISTS "${vcProjectFile}")
  3. set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
  4. return()
  5. endif()
  6. set(inGroup FALSE)
  7. set(inCommand FALSE)
  8. set(expected_Debug
  9. "cmd_1 cmd_1_arg"
  10. "cmd_1_dbg cmd_1_dbg_arg"
  11. "cmd_2_dbg cmd_2_dbg_arg"
  12. "cmd_3_dbg cmd_3_dbg_arg")
  13. set(expected_Release
  14. "cmd_1 cmd_1_arg"
  15. "cmd_3_rel cmd_3_rel_arg")
  16. # extract build events
  17. file(STRINGS "${vcProjectFile}" lines)
  18. foreach(line IN LISTS lines)
  19. if(line MATCHES "^ *<ItemDefinitionGroup Condition=.*Configuration.*Platform.*>$")
  20. set(inGroup TRUE)
  21. string(REGEX MATCH "=='(.*)\\|(.*)'" out ${line})
  22. set(config ${CMAKE_MATCH_1})
  23. elseif(line MATCHES "^ *</ItemDefinitionGroup>$")
  24. set(inGroup FALSE)
  25. elseif(inGroup)
  26. if(line MATCHES "^ *<Command>.*$")
  27. set(inCommand TRUE)
  28. string(REGEX MATCH "<Command>(.*)" cmd ${line})
  29. set(currentCommand ${CMAKE_MATCH_1})
  30. elseif(line MATCHES "^(.*)</Command>$")
  31. string(REGEX MATCH "(.*)</Command>" cmd ${line})
  32. list(APPEND currentCommand ${CMAKE_MATCH_1})
  33. set(command_${config} ${currentCommand})
  34. set(inCommand FALSE)
  35. elseif(inCommand)
  36. list(APPEND currentCommand ${line})
  37. endif()
  38. endif()
  39. endforeach()
  40. foreach(config "Debug" "Release")
  41. set(currentName command_${config})
  42. set(expectedName expected_${config})
  43. set(strippedCommand "")
  44. if(DEFINED ${currentName})
  45. foreach(v ${${currentName}})
  46. if(${v} MATCHES "cmd_")
  47. list(APPEND strippedCommand ${v})
  48. endif()
  49. endforeach()
  50. if(NOT "${strippedCommand}" STREQUAL
  51. "${${expectedName}}")
  52. message(" - ${strippedCommand}")
  53. message(" + ${${expectedName}}")
  54. set(RunCMake_TEST_FAILED "build event command does not match")
  55. return()
  56. endif()
  57. endif()
  58. endforeach()