solution_parsing.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(getProjectNames arg_out_projects)
  50. set(${arg_out_projects} "")
  51. set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln")
  52. if(NOT EXISTS "${sln}")
  53. error("Expected solution file ${sln} does not exist")
  54. endif()
  55. file(STRINGS "${sln}" project_lines REGEX "^Project\\(")
  56. foreach(project_line IN LISTS project_lines)
  57. string(REGEX REPLACE ".* = \"" "" project_line "${project_line}")
  58. string(REGEX REPLACE "\", .*" "" project_line "${project_line}")
  59. list(APPEND ${arg_out_projects} "${project_line}")
  60. endforeach()
  61. endmacro()
  62. macro(testGlobalSection prefix sectionName)
  63. if(NOT DEFINED ${prefix}_${sectionName})
  64. error("Section ${sectionName} does not exist")
  65. endif()
  66. if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}")
  67. error("Section ${sectionName} content mismatch\n expected: ${ARGN}\n actual: ${${prefix}_${sectionName}}")
  68. endif()
  69. endmacro()