1macro(error text) 2 set(RunCMake_TEST_FAILED "${text}") 3 return() 4endmacro() 5 6 7macro(parseGlobalSections arg_out_pre arg_out_post testName) 8 set(out_pre ${arg_out_pre}) 9 set(out_post ${arg_out_post}) 10 set(sln "${RunCMake_TEST_BINARY_DIR}/${testName}.sln") 11 if(NOT EXISTS "${sln}") 12 error("Expected solution file ${sln} does not exist") 13 endif() 14 file(STRINGS "${sln}" lines) 15 set(sectionLines "") 16 set(store FALSE) 17 foreach(line IN LISTS lines) 18 if(line MATCHES "^\t*Global\n?$") 19 set(store TRUE) 20 elseif(line MATCHES "^\t*EndGlobal\n?$") 21 set(store FALSE) 22 elseif(store) 23 list(APPEND sectionLines "${line}") 24 endif() 25 endforeach() 26 set(sectionName "") 27 set(sectionType "") 28 foreach(line IN LISTS sectionLines) 29 if(line MATCHES "^\t*GlobalSection\\((.*)\\) *= *(pre|post)Solution\n?$") 30 set(sectionName "${CMAKE_MATCH_1}") 31 set(sectionType ${CMAKE_MATCH_2}) 32 list(APPEND ${out_${sectionType}} "${sectionName}") 33 if(DEFINED ${out_${sectionType}}_${sectionName}) 34 error("Section ${sectionName} defined twice") 35 endif() 36 set(${out_${sectionType}}_${sectionName} "") 37 elseif(line MATCHES "\t*EndGlobalSection\n?$") 38 set(sectionName "") 39 set(sectionType "") 40 elseif(sectionName) 41 string(REGEX MATCH "^\t*([^=]*)=([^\n]*)\n?$" matches "${line}") 42 if(NOT matches) 43 error("Bad syntax in solution file: '${line}'") 44 endif() 45 string(STRIP "${CMAKE_MATCH_1}" key) 46 string(STRIP "${CMAKE_MATCH_2}" value) 47 if(key STREQUAL "SolutionGuid" AND value MATCHES "^{[0-9A-F-]+}$") 48 set(value "{00000000-0000-0000-0000-000000000000}") 49 endif() 50 list(APPEND ${out_${sectionType}}_${sectionName} "${key}=${value}") 51 endif() 52 endforeach() 53endmacro() 54 55 56macro(getProjectNames arg_out_projects) 57 set(${arg_out_projects} "") 58 set(sln "${RunCMake_TEST_BINARY_DIR}/${test}.sln") 59 if(NOT EXISTS "${sln}") 60 error("Expected solution file ${sln} does not exist") 61 endif() 62 file(STRINGS "${sln}" project_lines REGEX "^Project\\(") 63 foreach(project_line IN LISTS project_lines) 64 string(REGEX REPLACE ".* = \"" "" project_line "${project_line}") 65 string(REGEX REPLACE "\", .*" "" project_line "${project_line}") 66 list(APPEND ${arg_out_projects} "${project_line}") 67 endforeach() 68endmacro() 69 70 71macro(testGlobalSection prefix sectionName) 72 if(NOT DEFINED ${prefix}_${sectionName}) 73 error("Section ${sectionName} does not exist") 74 endif() 75 if(NOT "${${prefix}_${sectionName}}" STREQUAL "${ARGN}") 76 error("Section ${sectionName} content mismatch\n expected: ${ARGN}\n actual: ${${prefix}_${sectionName}}") 77 endif() 78endmacro() 79