solution_parsing.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if(key STREQUAL "SolutionGuid" AND value MATCHES "^{[0-9A-F-]+}$")
  46. set(value "{00000000-0000-0000-0000-000000000000}")
  47. endif()
  48. list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}")
  49. endif()
  50. endforeach()
  51. endmacro()
  52. macro(getProjectNames arg_out_projects)
  53. set(${arg_out_projects} "")
  54. set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln")
  55. if(NOT EXISTS "${sln}")
  56. error("Expected solution file ${sln} does not exist")
  57. endif()
  58. file(STRINGS "${sln}" project_lines REGEX "^Project\\(")
  59. foreach(project_line IN LISTS project_lines)
  60. string(REGEX REPLACE ".* = \"" "" project_line "${project_line}")
  61. string(REGEX REPLACE "\", .*" "" project_line "${project_line}")
  62. list(APPEND ${arg_out_projects} "${project_line}")
  63. endforeach()
  64. endmacro()
  65. macro(testGlobalSection prefix sectionName)
  66. if(NOT DEFINED ${prefix}_${sectionName})
  67. error("Section ${sectionName} does not exist")
  68. endif()
  69. if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}")
  70. error("Section ${sectionName} content mismatch\n expected: ${ARGN}\n actual: ${${prefix}_${sectionName}}")
  71. endif()
  72. endmacro()