solution_parsing.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. macro(error text)
  2. set(RunCMake_TEST_FAILED "${text}")
  3. return()
  4. endmacro()
  5. macro(parseGlobalSections arg_out_pre arg_out_post testName)
  6. set(out_pre ${arg_out_pre})
  7. set(out_post ${arg_out_post})
  8. set(sln "${RunCMake_TEST_BINARY_DIR}/${testName}.sln")
  9. if(NOT EXISTS "${sln}")
  10. error("Expected solution file ${sln} does not exist")
  11. endif()
  12. file(STRINGS "${sln}" lines)
  13. set(sectionLines "")
  14. set(store FALSE)
  15. foreach(line IN LISTS lines)
  16. if(line MATCHES "^\t*Global\n?$")
  17. set(store TRUE)
  18. elseif(line MATCHES "^\t*EndGlobal\n?$")
  19. set(store FALSE)
  20. elseif(store)
  21. list(APPEND sectionLines "${line}")
  22. endif()
  23. endforeach()
  24. set(sectionName "")
  25. set(sectionType "")
  26. foreach(line IN LISTS sectionLines)
  27. if(line MATCHES "^\t*GlobalSection\\((.*)\\) *= *(pre|post)Solution\n?$")
  28. set(sectionName "${CMAKE_MATCH_1}")
  29. set(sectionType ${CMAKE_MATCH_2})
  30. list(APPEND ${out_${sectionType}} "${sectionName}")
  31. if(DEFINED ${out_${sectionType}}_${sectionName})
  32. error("Section ${sectionName} defined twice")
  33. endif()
  34. set(${out_${sectionType}}_${sectionName} "")
  35. elseif(line MATCHES "\t*EndGlobalSection\n?$")
  36. set(sectionName "")
  37. set(sectionType "")
  38. elseif(sectionName)
  39. string(REGEX MATCH "^\t*([^=]*)=([^\n]*)\n?$" matches "${line}")
  40. if(NOT matches)
  41. error("Bad syntax in solution file: '${line}'")
  42. endif()
  43. string(STRIP "${CMAKE_MATCH_1}" key)
  44. string(STRIP "${CMAKE_MATCH_2}" value)
  45. list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}")
  46. endif()
  47. endforeach()
  48. endmacro()
  49. macro(testGlobalSection prefix sectionName)
  50. if(NOT DEFINED ${prefix}_${sectionName})
  51. error("Section ${sectionName} does not exist")
  52. endif()
  53. if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}")
  54. error("Section ${sectionName} content mismatch\n expected: ${ARGN}\n actual: ${${prefix}_${sectionName}}")
  55. endif()
  56. endmacro()