File: solution_parsing.cmake

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (78 lines) | stat: -rw-r--r-- 2,673 bytes parent folder | download | duplicates (7)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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)
      if(key STREQUAL "SolutionGuid" AND value MATCHES "^{[0-9A-F-]+}$")
        set(value "{00000000-0000-0000-0000-000000000000}")
      endif()
      list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}")
    endif()
  endforeach()
endmacro()


macro(getProjectNames arg_out_projects)
  set(${arg_out_projects} "")
  set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln")
  if(NOT EXISTS "${sln}")
    error("Expected solution file ${sln} does not exist")
  endif()
  file(STRINGS "${sln}" project_lines REGEX "^Project\\(")
  foreach(project_line IN LISTS project_lines)
    string(REGEX REPLACE ".* = \"" "" project_line "${project_line}")
    string(REGEX REPLACE "\", .*"  "" project_line "${project_line}")
    list(APPEND ${arg_out_projects} "${project_line}")
  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()