summaryrefslogtreecommitdiff
path: root/Tests/RunCMake/SolutionGlobalSections/solution_parsing.cmake
blob: dd158efe97f7526bab7b8222ab90927c4fc5591a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
macro(error text)
  set(RunCMake_TEST_FAILED "${text}")
  return()
endmacro()


macro(parseGlobalSections arg_out_pre arg_out_post testName)
  set(out_pre ${arg_out_pre})
  set(out_post ${arg_out_post})
  set(sln "${RunCMake_TEST_BINARY_DIR}/${testName}.sln")
  if(NOT EXISTS "${sln}")
    error("Expected solution file ${sln} does not exist")
  endif()
  file(STRINGS "${sln}" lines)
  set(sectionLines "")
  set(store FALSE)
  foreach(line IN LISTS lines)
    if(line MATCHES "^\t*Global\n?$")
      set(store TRUE)
    elseif(line MATCHES "^\t*EndGlobal\n?$")
      set(store FALSE)
    elseif(store)
      list(APPEND sectionLines "${line}")
    endif()
  endforeach()
  set(sectionName "")
  set(sectionType "")
  foreach(line IN LISTS sectionLines)
    if(line MATCHES "^\t*GlobalSection\\((.*)\\) *= *(pre|post)Solution\n?$")
      set(sectionName "${CMAKE_MATCH_1}")
      set(sectionType ${CMAKE_MATCH_2})
      list(APPEND ${out_${sectionType}} "${sectionName}")
      if(DEFINED ${out_${sectionType}}_${sectionName})
        error("Section ${sectionName} defined twice")
      endif()
      set(${out_${sectionType}}_${sectionName} "")
    elseif(line MATCHES "\t*EndGlobalSection\n?$")
      set(sectionName "")
      set(sectionType "")
    elseif(sectionName)
      string(REGEX MATCH "^\t*([^=]*)=([^\n]*)\n?$" matches "${line}")
      if(NOT matches)
        error("Bad syntax in solution file: '${line}'")
      endif()
      string(STRIP "${CMAKE_MATCH_1}" key)
      string(STRIP "${CMAKE_MATCH_2}" value)
      list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}")
    endif()
  endforeach()
endmacro()


macro(testGlobalSection prefix sectionName)
  if(NOT DEFINED ${prefix}_${sectionName})
    error("Section ${sectionName} does not exist")
  endif()
  if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}")
    error("Section ${sectionName} content mismatch\n  expected: ${ARGN}\n  actual: ${${prefix}_${sectionName}}")
  endif()
endmacro()