Tests/RunCMake: Factor out sln-format check scripts

This commit is contained in:
Brad King
2025-09-08 20:21:39 -04:00
parent d32b78f139
commit 95c2034b32
42 changed files with 530 additions and 514 deletions

View File

@@ -0,0 +1,29 @@
set(vcSlnFile "${RunCMake_TEST_BINARY_DIR}/AddPackageToDefault.sln")
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Project file ${vcSlnFile} does not exist.")
return()
endif()
set(packageGuidFound FALSE)
set(packageGuid "")
set(packageInBuild FALSE)
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
if(NOT packageGuidFound)
if(line MATCHES "^Project.*\"PACKAGE.vcx?proj\".*\"{([A-F0-9-]+)}\"$")
set(packageGuidFound TRUE)
set(packageGuid ${CMAKE_MATCH_1})
endif()
else()
if(line MATCHES ".*{${packageGuid}}.*")
if(line MATCHES "^[ \t]*{${packageGuid}}\\..*\\.Build.0 = .*$")
set(packageInBuild TRUE)
endif()
endif()
endif()
endforeach()
if(NOT packageInBuild)
set(RunCMake_TEST_FAILED "PACKAGE is not in default build")
return()
endif()

View File

@@ -1,29 +1 @@
set(vcSlnFile "${RunCMake_TEST_BINARY_DIR}/AddPackageToDefault.sln")
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Project file ${vcSlnFile} does not exist.")
return()
endif()
set(packageGuidFound FALSE)
set(packageGuid "")
set(packageInBuild FALSE)
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
if(NOT packageGuidFound)
if(line MATCHES "^Project.*\"PACKAGE.vcx?proj\".*\"{([A-F0-9-]+)}\"$")
set(packageGuidFound TRUE)
set(packageGuid ${CMAKE_MATCH_1})
endif()
else()
if(line MATCHES ".*{${packageGuid}}.*")
if(line MATCHES "^[ \t]*{${packageGuid}}\\..*\\.Build.0 = .*$")
set(packageInBuild TRUE)
endif()
endif()
endif()
endforeach()
if(NOT packageInBuild)
set(RunCMake_TEST_FAILED "PACKAGE is not in default build")
return()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/AddPackageToDefault-check-sln.cmake)

View File

@@ -0,0 +1,6 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(found EQUAL "-1")
error("CMakePredefinedTargets should be defined when CMP0143 is NEW!")
endif()

View File

@@ -1,6 +1 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(found EQUAL "-1")
error("CMakePredefinedTargets should be defined when CMP0143 is NEW!")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMP0143-NEW-check-sln.cmake)

View File

@@ -0,0 +1,6 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(NOT (found EQUAL "-1"))
error("CMakePredefinedTargets should not be defined when CMP0143 is OLD!")
endif()

View File

@@ -1,6 +1 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(NOT (found EQUAL "-1"))
error("CMakePredefinedTargets should not be defined when CMP0143 is OLD!")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMP0143-OLD-check-sln.cmake)

View File

@@ -0,0 +1,6 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(NOT (found EQUAL "-1"))
error("CMakePredefinedTargets should not be defined when CMP0143 is OLD!")
endif()

View File

@@ -1,6 +1 @@
getProjectNames(projects)
list(FIND projects "CMakePredefinedTargets" found)
if(NOT (found EQUAL "-1"))
error("CMakePredefinedTargets should not be defined when CMP0143 is OLD!")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/CMP0143-WARN-check-sln.cmake)

View File

@@ -0,0 +1,53 @@
#
# Test solution file for deployment.
#
set(vcSlnFile "${RunCMake_TEST_BINARY_DIR}/DeployEnabled.sln")
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Solution file ${vcSlnFile} does not exist.")
return()
endif()
set(FooProjGUID "")
set(FoundFooProj FALSE)
set(InFooProj FALSE)
set(FoundReleaseDeploy FALSE)
set(DeployConfigs Debug MinSizeRel RelWithDebInfo )
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
#message(STATUS "${line}")
if( (NOT InFooProj ) AND (line MATCHES "^[ \\t]*Project\\(\"{[A-F0-9-]+}\"\\) = \"foo\", \"foo.vcxproj\", \"({[A-F0-9-]+})\"[ \\t]*$"))
# First, identify the GUID for the foo project, and record it.
set(FoundFooProj TRUE)
set(InFooProj TRUE)
set(FooProjGUID ${CMAKE_MATCH_1})
elseif(InFooProj AND line MATCHES "EndProject")
set(InFooProj FALSE)
elseif((NOT InFooProj) AND line MATCHES "${FooProjGUID}\\.Release.*\\.Deploy\\.0")
# If foo's Release configuration is set to deploy, this is the error.
set(FoundReleaseDeploy TRUE)
endif()
if( line MATCHES "{[A-F0-9-]+}\\.([^\\|]+).*\\.Deploy\\.0" )
# Check that the other configurations ARE set to deploy.
list( REMOVE_ITEM DeployConfigs ${CMAKE_MATCH_1})
endif()
endforeach()
if(FoundReleaseDeploy)
set(RunCMake_TEST_FAILED "Release deployment enabled.")
return()
endif()
if(NOT FoundFooProj)
set(RunCMake_TEST_FAILED "Failed to find foo project in the solution.")
return()
endif()
list(LENGTH DeployConfigs length)
if( length GREATER 0 )
set(RunCMake_TEST_FAILED "Failed to find Deploy lines for non-Release configurations. (${length})")
return()
endif()

View File

@@ -1,58 +1 @@
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
return()
endif()
#
# Test solution file for deployment.
#
set(vcSlnFile "${RunCMake_TEST_BINARY_DIR}/DeployEnabled.sln")
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Solution file ${vcSlnFile} does not exist.")
return()
endif()
set(FooProjGUID "")
set(FoundFooProj FALSE)
set(InFooProj FALSE)
set(FoundReleaseDeploy FALSE)
set(DeployConfigs Debug MinSizeRel RelWithDebInfo )
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
#message(STATUS "${line}")
if( (NOT InFooProj ) AND (line MATCHES "^[ \\t]*Project\\(\"{[A-F0-9-]+}\"\\) = \"foo\", \"foo.vcxproj\", \"({[A-F0-9-]+})\"[ \\t]*$"))
# First, identify the GUID for the foo project, and record it.
set(FoundFooProj TRUE)
set(InFooProj TRUE)
set(FooProjGUID ${CMAKE_MATCH_1})
elseif(InFooProj AND line MATCHES "EndProject")
set(InFooProj FALSE)
elseif((NOT InFooProj) AND line MATCHES "${FooProjGUID}\\.Release.*\\.Deploy\\.0")
# If foo's Release configuration is set to deploy, this is the error.
set(FoundReleaseDeploy TRUE)
endif()
if( line MATCHES "{[A-F0-9-]+}\\.([^\\|]+).*\\.Deploy\\.0" )
# Check that the other configurations ARE set to deploy.
list( REMOVE_ITEM DeployConfigs ${CMAKE_MATCH_1})
endif()
endforeach()
if(FoundReleaseDeploy)
set(RunCMake_TEST_FAILED "Release deployment enabled.")
return()
endif()
if(NOT FoundFooProj)
set(RunCMake_TEST_FAILED "Failed to find foo project in the solution.")
return()
endif()
list(LENGTH DeployConfigs length)
if( length GREATER 0 )
set(RunCMake_TEST_FAILED "Failed to find Deploy lines for non-Release configurations. (${length})")
return()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/DeployEnabled-check-sln.cmake)

View File

@@ -0,0 +1,5 @@
parseGlobalSections(pre post MorePost)
testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post TestSec4 Key6=Value1 "Key7=Value with spaces" Key8=ValueWithoutSpaces)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,5 +1 @@
parseGlobalSections(pre post MorePost)
testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post TestSec4 Key6=Value1 "Key7=Value with spaces" Key8=ValueWithoutSpaces)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/MorePost-check-sln.cmake)

View File

@@ -0,0 +1,5 @@
parseGlobalSections(pre post MorePre)
testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(pre TestSec3 Key3=Value1 "Key4=Value with spaces" Key5=ValueWithoutSpaces)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,5 +1 @@
parseGlobalSections(pre post MorePre)
testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(pre TestSec3 Key3=Value1 "Key4=Value with spaces" Key5=ValueWithoutSpaces)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/MorePre-check-sln.cmake)

View File

@@ -0,0 +1,4 @@
parseGlobalSections(pre post OnePost)
testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,4 +1 @@
parseGlobalSections(pre post OnePost)
testGlobalSection(post TestSec2 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/OnePost-check-sln.cmake)

View File

@@ -0,0 +1,4 @@
parseGlobalSections(pre post OnePre)
testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,4 +1 @@
parseGlobalSections(pre post OnePre)
testGlobalSection(pre TestSec1 Key1=Value1 "Key2=Value with spaces")
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/OnePre-check-sln.cmake)

View File

@@ -0,0 +1,4 @@
parseGlobalSections(pre post Override1)
testGlobalSection(post TestSec Key2=Value2 Key3=Value3)
testGlobalSection(post ExtensibilityGlobals Key1=Value1 "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,4 +1 @@
parseGlobalSections(pre post Override1)
testGlobalSection(post TestSec Key2=Value2 Key3=Value3)
testGlobalSection(post ExtensibilityGlobals Key1=Value1 "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/Override1-check-sln.cmake)

View File

@@ -0,0 +1,4 @@
parseGlobalSections(pre post Override2)
testGlobalSection(pre TestSec Key2=Value2 Key3=Value3)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns Key1=Value1)

View File

@@ -1,4 +1 @@
parseGlobalSections(pre post Override2)
testGlobalSection(pre TestSec Key2=Value2 Key3=Value3)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns Key1=Value1)
include(${CMAKE_CURRENT_LIST_DIR}/Override2-check-sln.cmake)

View File

@@ -0,0 +1,3 @@
parseGlobalSections(pre post Override3)
testGlobalSection(post ExtensibilityGlobals Key1=Value1 "SolutionGuid={custom-guid}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,3 +1 @@
parseGlobalSections(pre post Override3)
testGlobalSection(post ExtensibilityGlobals Key1=Value1 "SolutionGuid={custom-guid}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/Override3-check-sln.cmake)

View File

@@ -0,0 +1,6 @@
parseGlobalSections(pre post PrePost)
testGlobalSection(post Postsec Key1=Value2)
testGlobalSection(pre Presec Key1=Value1 "Key2=Value with some spaces")
testGlobalSection(post Emptysec)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)

View File

@@ -1,6 +1 @@
parseGlobalSections(pre post PrePost)
testGlobalSection(post Postsec Key1=Value2)
testGlobalSection(pre Presec Key1=Value1 "Key2=Value with some spaces")
testGlobalSection(post Emptysec)
testGlobalSection(post ExtensibilityGlobals "SolutionGuid={00000000-0000-0000-0000-000000000000}")
testGlobalSection(post ExtensibilityAddIns)
include(${CMAKE_CURRENT_LIST_DIR}/PrePost-check-sln.cmake)

View File

@@ -0,0 +1,351 @@
function(MapAppend map key value)
list(APPEND "${map}_k" "${key}")
list(APPEND "${map}_v" "${value}")
set("${map}_k" "${${map}_k}" PARENT_SCOPE)
set("${map}_v" "${${map}_v}" PARENT_SCOPE)
endfunction()
function(MapLength map out_variable)
list(LENGTH "${map}_k" length)
set("${out_variable}" "${length}" PARENT_SCOPE)
endfunction()
function(MapFind map key out_variable)
list(FIND "${map}_k" "${key}" index)
if("${index}" LESS 0)
unset("${out_variable}" PARENT_SCOPE)
else()
list(GET "${map}_v" "${index}" value)
set("${out_variable}" "${value}" PARENT_SCOPE)
endif()
endfunction()
macro(MapPropagateToParentScope map)
set("${map}_k" "${${map}_k}" PARENT_SCOPE)
set("${map}_v" "${${map}_v}" PARENT_SCOPE)
endmacro()
function(ParseSln vcSlnFile)
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Solution file ${vcSlnFile} does not exist." PARENT_SCOPE)
return()
endif()
set(SCOPE "")
set(IN_SOLUTION_ITEMS FALSE)
set(IN_NESTED_PROJECTS FALSE)
set(REGUID "\\{[0-9A-F-]+\\}")
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
string(STRIP "${line}" line)
# Project(...)
if(line MATCHES "Project\\(\"(${REGUID})\"\\) = \"([^\"]+)\", \"([^\"]+)\", \"(${REGUID})\"")
if(NOT "${SCOPE}" STREQUAL "")
set(RunCMake_TEST_FAILED "Improper nesting of Project" PARENT_SCOPE)
return()
endif()
set(SCOPE "Project")
if("${CMAKE_MATCH_1}" STREQUAL "{2150E333-8FDC-42A3-9474-1A3956D46DE8}")
set(GROUP_NAME "${CMAKE_MATCH_2}")
MapFind(GROUP_PATHS "${GROUP_NAME}" existing_path)
if(DEFINED existing_path)
set(RunCMake_TEST_FAILED "Duplicate solution items project '${GROUP_NAME}'" PARENT_SCOPE)
return()
endif()
MapAppend(GROUP_PATHS "${GROUP_NAME}" "${CMAKE_MATCH_3}")
MapAppend(GROUP_GUIDS "${GROUP_NAME}" "${CMAKE_MATCH_4}")
endif()
# EndProject
elseif(line STREQUAL "EndProject")
if(NOT "${SCOPE}" STREQUAL "Project")
set(RunCMake_TEST_FAILED "Improper nesting of EndProject" PARENT_SCOPE)
return()
endif()
set(SCOPE "")
unset(GROUP_NAME)
# ProjectSection
elseif(line MATCHES "ProjectSection\\(([a-zA-Z]+)\\) = ([a-zA-Z]+)")
if(NOT "${SCOPE}" STREQUAL "Project")
set(RunCMake_TEST_FAILED "Improper nesting of ProjectSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "ProjectSection")
if("${CMAKE_MATCH_1}" STREQUAL "SolutionItems")
if(NOT "${CMAKE_MATCH_2}" STREQUAL "preProject")
set(RunCMake_TEST_FAILED "SolutionItems must be preProject" PARENT_SCOPE)
return()
endif()
set(IN_SOLUTION_ITEMS TRUE)
endif()
# EndProjectSection
elseif(line STREQUAL "EndProjectSection")
if(NOT "${SCOPE}" STREQUAL "ProjectSection")
set(RunCMake_TEST_FAILED "Improper nesting of EndProjectSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "Project")
set(IN_SOLUTION_ITEMS FALSE)
# Global
elseif(line STREQUAL "Global")
if(NOT "${SCOPE}" STREQUAL "")
set(RunCMake_TEST_FAILED "Improper nesting of Global" PARENT_SCOPE)
return()
endif()
set(SCOPE "Global")
# EndGlobal
elseif(line STREQUAL "EndGlobal")
if(NOT "${SCOPE}" STREQUAL "Global")
set(RunCMake_TEST_FAILED "Improper nesting of EndGlobal" PARENT_SCOPE)
return()
endif()
set(SCOPE "")
# GlobalSection
elseif(line MATCHES "GlobalSection\\(([a-zA-Z]+)\\) = ([a-zA-Z]+)")
if(NOT "${SCOPE}" STREQUAL "Global")
set(RunCMake_TEST_FAILED "Improper nesting of GlobalSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "GlobalSection")
if("${CMAKE_MATCH_1}" STREQUAL "NestedProjects")
if(NOT "${CMAKE_MATCH_2}" STREQUAL "preSolution")
set(RunCMake_TEST_FAILED "NestedProjects must be preSolution" PARENT_SCOPE)
return()
endif()
set(IN_NESTED_PROJECTS TRUE)
endif()
# EndGlobalSection
elseif(line STREQUAL "EndGlobalSection")
if(NOT "${SCOPE}" STREQUAL "GlobalSection")
set(RunCMake_TEST_FAILED "Improper nesting of EndGlobalSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "Global")
set(IN_NESTED_PROJECTS FALSE)
# .../solution-item-0-1.txt = .../solution-item-0-1.txt
elseif(${IN_SOLUTION_ITEMS})
if(NOT line MATCHES "([^=]+)=([^=]+)")
set(RunCMake_TEST_FAILED "Invalid solution item paths 1" PARENT_SCOPE)
return()
endif()
string(STRIP "${CMAKE_MATCH_1}" CMAKE_MATCH_1)
string(STRIP "${CMAKE_MATCH_2}" CMAKE_MATCH_2)
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CMAKE_MATCH_2}")
set(RunCMake_TEST_FAILED "Invalid solution item paths 2" PARENT_SCOPE)
return()
endif()
cmake_path(GET CMAKE_MATCH_1 FILENAME filename)
MapAppend(SOLUTION_ITEMS "${filename}" "${GROUP_NAME}")
# {1EB55F5E...} = {A11E84C6...}
elseif(${IN_NESTED_PROJECTS})
if(NOT line MATCHES "(${REGUID}) = (${REGUID})")
set(RunCMake_TEST_FAILED "Invalid nested project guids" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${CMAKE_MATCH_1}" existing_parent)
if(DEFINED existing_parent)
set(RunCMake_TEST_FAILED "Duplicate nested project: '${CMAKE_MATCH_1}'" PARENT_SCOPE)
return()
endif()
MapAppend(PROJECT_PARENTS "${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}")
endif()
MapPropagateToParentScope(GROUP_PATHS)
MapPropagateToParentScope(GROUP_GUIDS)
MapPropagateToParentScope(PROJECT_PARENTS)
MapPropagateToParentScope(SOLUTION_ITEMS)
endforeach()
endfunction()
# Check the root solution:
block()
ParseSln("${RunCMake_TEST_BINARY_DIR}/SolutionItems.sln")
if(DEFINED RunCMake_TEST_FAILED)
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return()
endif()
# Check group guids and nesting:
MapFind(GROUP_GUIDS "Solution Items" root_group_guid)
if(NOT DEFINED root_group_guid)
set(RunCMake_TEST_FAILED "Solution Items not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Solution Items" root_group_path)
if(NOT "${root_group_path}" STREQUAL "Solution Items")
set(RunCMake_TEST_FAILED "Invalid Solution Items path: '${root_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${root_group_guid}" root_group_parent_guid)
if(DEFINED root_group_parent_guid)
set(RunCMake_TEST_FAILED "Solution Items is nested" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_GUIDS "Outer Group" outer_group_guid)
if(NOT DEFINED outer_group_guid)
set(RunCMake_TEST_FAILED "Outer Group not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Outer Group" outer_group_path)
if(NOT "${outer_group_path}" STREQUAL "Outer Group")
set(RunCMake_TEST_FAILED "Invalid Outer Group path: '${outer_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${outer_group_guid}" outer_group_parent_guid)
if(DEFINED outer_group_parent_guid)
set(RunCMake_TEST_FAILED "Outer Group is nested" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_GUIDS "Inner Group" inner_group_guid)
if(NOT DEFINED inner_group_guid)
set(RunCMake_TEST_FAILED "Inner Group not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Inner Group" inner_group_path)
if(NOT "${inner_group_path}" STREQUAL "Outer Group\\Inner Group")
set(RunCMake_TEST_FAILED "Invalid Inner Group path: '${inner_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${inner_group_guid}" inner_group_parent_guid)
if(NOT DEFINED inner_group_parent_guid)
set(RunCMake_TEST_FAILED "Inner Group is not nested" PARENT_SCOPE)
return()
endif()
if(NOT "${inner_group_parent_guid}" STREQUAL "${outer_group_guid}")
set(RunCMake_TEST_FAILED "Inner Group is not nested within Outer Group" PARENT_SCOPE)
return()
endif()
# Check solution items and nesting:
MapLength(SOLUTION_ITEMS solution_item_count)
if(NOT "${solution_item_count}" EQUAL 4)
set(RunCMake_TEST_FAILED "Unexpected number of solution items: ${solution_item_count}")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-0-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-0-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Solution Items")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-0-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-1-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-1-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Outer Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-1-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-2-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-2-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Inner Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-2-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-2-2.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-2-2.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Inner Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-2-2.txt: '${group_name}'")
return()
endif()
endblock()
# Check the nested solution:
block()
ParseSln("${RunCMake_TEST_BINARY_DIR}/SolutionItems/SolutionItemsSubproject.sln")
if(DEFINED RunCMake_TEST_FAILED)
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return()
endif()
# Check group guids and nesting:
MapFind(GROUP_GUIDS "Extraneous" root_group_guid)
if(NOT DEFINED root_group_guid)
set(RunCMake_TEST_FAILED "Extraneous not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Extraneous" root_group_path)
if(NOT "${root_group_path}" STREQUAL "Extraneous")
set(RunCMake_TEST_FAILED "Invalid Extraneous path: '${root_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${root_group_guid}" root_group_parent_guid)
if(DEFINED root_group_parent_guid)
set(RunCMake_TEST_FAILED "Extraneous is nested" PARENT_SCOPE)
return()
endif()
# Check solution items and nesting:
MapLength(SOLUTION_ITEMS solution_item_count)
if(NOT "${solution_item_count}" EQUAL 1)
set(RunCMake_TEST_FAILED "Unexpected number of solution items: ${solution_item_count}" PARENT_SCOPE)
return()
endif()
MapFind(SOLUTION_ITEMS "extraneous.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: extraneous.txt" PARENT_SCOPE)
return()
endif()
if(NOT "${group_name}" STREQUAL "Extraneous")
set(RunCMake_TEST_FAILED "Invalid group for extraneous.txt: '${group_name}'" PARENT_SCOPE)
return()
endif()
endblock()

View File

@@ -1,351 +1 @@
function(MapAppend map key value)
list(APPEND "${map}_k" "${key}")
list(APPEND "${map}_v" "${value}")
set("${map}_k" "${${map}_k}" PARENT_SCOPE)
set("${map}_v" "${${map}_v}" PARENT_SCOPE)
endfunction()
function(MapLength map out_variable)
list(LENGTH "${map}_k" length)
set("${out_variable}" "${length}" PARENT_SCOPE)
endfunction()
function(MapFind map key out_variable)
list(FIND "${map}_k" "${key}" index)
if("${index}" LESS 0)
unset("${out_variable}" PARENT_SCOPE)
else()
list(GET "${map}_v" "${index}" value)
set("${out_variable}" "${value}" PARENT_SCOPE)
endif()
endfunction()
macro(MapPropagateToParentScope map)
set("${map}_k" "${${map}_k}" PARENT_SCOPE)
set("${map}_v" "${${map}_v}" PARENT_SCOPE)
endmacro()
function(ParseSln vcSlnFile)
if(NOT EXISTS "${vcSlnFile}")
set(RunCMake_TEST_FAILED "Solution file ${vcSlnFile} does not exist." PARENT_SCOPE)
return()
endif()
set(SCOPE "")
set(IN_SOLUTION_ITEMS FALSE)
set(IN_NESTED_PROJECTS FALSE)
set(REGUID "\\{[0-9A-F-]+\\}")
file(STRINGS "${vcSlnFile}" lines)
foreach(line IN LISTS lines)
string(STRIP "${line}" line)
# Project(...)
if(line MATCHES "Project\\(\"(${REGUID})\"\\) = \"([^\"]+)\", \"([^\"]+)\", \"(${REGUID})\"")
if(NOT "${SCOPE}" STREQUAL "")
set(RunCMake_TEST_FAILED "Improper nesting of Project" PARENT_SCOPE)
return()
endif()
set(SCOPE "Project")
if("${CMAKE_MATCH_1}" STREQUAL "{2150E333-8FDC-42A3-9474-1A3956D46DE8}")
set(GROUP_NAME "${CMAKE_MATCH_2}")
MapFind(GROUP_PATHS "${GROUP_NAME}" existing_path)
if(DEFINED existing_path)
set(RunCMake_TEST_FAILED "Duplicate solution items project '${GROUP_NAME}'" PARENT_SCOPE)
return()
endif()
MapAppend(GROUP_PATHS "${GROUP_NAME}" "${CMAKE_MATCH_3}")
MapAppend(GROUP_GUIDS "${GROUP_NAME}" "${CMAKE_MATCH_4}")
endif()
# EndProject
elseif(line STREQUAL "EndProject")
if(NOT "${SCOPE}" STREQUAL "Project")
set(RunCMake_TEST_FAILED "Improper nesting of EndProject" PARENT_SCOPE)
return()
endif()
set(SCOPE "")
unset(GROUP_NAME)
# ProjectSection
elseif(line MATCHES "ProjectSection\\(([a-zA-Z]+)\\) = ([a-zA-Z]+)")
if(NOT "${SCOPE}" STREQUAL "Project")
set(RunCMake_TEST_FAILED "Improper nesting of ProjectSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "ProjectSection")
if("${CMAKE_MATCH_1}" STREQUAL "SolutionItems")
if(NOT "${CMAKE_MATCH_2}" STREQUAL "preProject")
set(RunCMake_TEST_FAILED "SolutionItems must be preProject" PARENT_SCOPE)
return()
endif()
set(IN_SOLUTION_ITEMS TRUE)
endif()
# EndProjectSection
elseif(line STREQUAL "EndProjectSection")
if(NOT "${SCOPE}" STREQUAL "ProjectSection")
set(RunCMake_TEST_FAILED "Improper nesting of EndProjectSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "Project")
set(IN_SOLUTION_ITEMS FALSE)
# Global
elseif(line STREQUAL "Global")
if(NOT "${SCOPE}" STREQUAL "")
set(RunCMake_TEST_FAILED "Improper nesting of Global" PARENT_SCOPE)
return()
endif()
set(SCOPE "Global")
# EndGlobal
elseif(line STREQUAL "EndGlobal")
if(NOT "${SCOPE}" STREQUAL "Global")
set(RunCMake_TEST_FAILED "Improper nesting of EndGlobal" PARENT_SCOPE)
return()
endif()
set(SCOPE "")
# GlobalSection
elseif(line MATCHES "GlobalSection\\(([a-zA-Z]+)\\) = ([a-zA-Z]+)")
if(NOT "${SCOPE}" STREQUAL "Global")
set(RunCMake_TEST_FAILED "Improper nesting of GlobalSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "GlobalSection")
if("${CMAKE_MATCH_1}" STREQUAL "NestedProjects")
if(NOT "${CMAKE_MATCH_2}" STREQUAL "preSolution")
set(RunCMake_TEST_FAILED "NestedProjects must be preSolution" PARENT_SCOPE)
return()
endif()
set(IN_NESTED_PROJECTS TRUE)
endif()
# EndGlobalSection
elseif(line STREQUAL "EndGlobalSection")
if(NOT "${SCOPE}" STREQUAL "GlobalSection")
set(RunCMake_TEST_FAILED "Improper nesting of EndGlobalSection" PARENT_SCOPE)
return()
endif()
set(SCOPE "Global")
set(IN_NESTED_PROJECTS FALSE)
# .../solution-item-0-1.txt = .../solution-item-0-1.txt
elseif(${IN_SOLUTION_ITEMS})
if(NOT line MATCHES "([^=]+)=([^=]+)")
set(RunCMake_TEST_FAILED "Invalid solution item paths 1" PARENT_SCOPE)
return()
endif()
string(STRIP "${CMAKE_MATCH_1}" CMAKE_MATCH_1)
string(STRIP "${CMAKE_MATCH_2}" CMAKE_MATCH_2)
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CMAKE_MATCH_2}")
set(RunCMake_TEST_FAILED "Invalid solution item paths 2" PARENT_SCOPE)
return()
endif()
cmake_path(GET CMAKE_MATCH_1 FILENAME filename)
MapAppend(SOLUTION_ITEMS "${filename}" "${GROUP_NAME}")
# {1EB55F5E...} = {A11E84C6...}
elseif(${IN_NESTED_PROJECTS})
if(NOT line MATCHES "(${REGUID}) = (${REGUID})")
set(RunCMake_TEST_FAILED "Invalid nested project guids" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${CMAKE_MATCH_1}" existing_parent)
if(DEFINED existing_parent)
set(RunCMake_TEST_FAILED "Duplicate nested project: '${CMAKE_MATCH_1}'" PARENT_SCOPE)
return()
endif()
MapAppend(PROJECT_PARENTS "${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}")
endif()
MapPropagateToParentScope(GROUP_PATHS)
MapPropagateToParentScope(GROUP_GUIDS)
MapPropagateToParentScope(PROJECT_PARENTS)
MapPropagateToParentScope(SOLUTION_ITEMS)
endforeach()
endfunction()
# Check the root solution:
block()
ParseSln("${RunCMake_TEST_BINARY_DIR}/SolutionItems.sln")
if(DEFINED RunCMake_TEST_FAILED)
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return()
endif()
# Check group guids and nesting:
MapFind(GROUP_GUIDS "Solution Items" root_group_guid)
if(NOT DEFINED root_group_guid)
set(RunCMake_TEST_FAILED "Solution Items not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Solution Items" root_group_path)
if(NOT "${root_group_path}" STREQUAL "Solution Items")
set(RunCMake_TEST_FAILED "Invalid Solution Items path: '${root_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${root_group_guid}" root_group_parent_guid)
if(DEFINED root_group_parent_guid)
set(RunCMake_TEST_FAILED "Solution Items is nested" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_GUIDS "Outer Group" outer_group_guid)
if(NOT DEFINED outer_group_guid)
set(RunCMake_TEST_FAILED "Outer Group not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Outer Group" outer_group_path)
if(NOT "${outer_group_path}" STREQUAL "Outer Group")
set(RunCMake_TEST_FAILED "Invalid Outer Group path: '${outer_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${outer_group_guid}" outer_group_parent_guid)
if(DEFINED outer_group_parent_guid)
set(RunCMake_TEST_FAILED "Outer Group is nested" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_GUIDS "Inner Group" inner_group_guid)
if(NOT DEFINED inner_group_guid)
set(RunCMake_TEST_FAILED "Inner Group not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Inner Group" inner_group_path)
if(NOT "${inner_group_path}" STREQUAL "Outer Group\\Inner Group")
set(RunCMake_TEST_FAILED "Invalid Inner Group path: '${inner_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${inner_group_guid}" inner_group_parent_guid)
if(NOT DEFINED inner_group_parent_guid)
set(RunCMake_TEST_FAILED "Inner Group is not nested" PARENT_SCOPE)
return()
endif()
if(NOT "${inner_group_parent_guid}" STREQUAL "${outer_group_guid}")
set(RunCMake_TEST_FAILED "Inner Group is not nested within Outer Group" PARENT_SCOPE)
return()
endif()
# Check solution items and nesting:
MapLength(SOLUTION_ITEMS solution_item_count)
if(NOT "${solution_item_count}" EQUAL 4)
set(RunCMake_TEST_FAILED "Unexpected number of solution items: ${solution_item_count}")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-0-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-0-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Solution Items")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-0-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-1-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-1-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Outer Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-1-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-2-1.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-2-1.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Inner Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-2-1.txt: '${group_name}'")
return()
endif()
MapFind(SOLUTION_ITEMS "solution-item-2-2.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: solution-item-2-2.txt")
return()
endif()
if(NOT "${group_name}" STREQUAL "Inner Group")
set(RunCMake_TEST_FAILED "Invalid group for solution-item-2-2.txt: '${group_name}'")
return()
endif()
endblock()
# Check the nested solution:
block()
ParseSln("${RunCMake_TEST_BINARY_DIR}/SolutionItems/SolutionItemsSubproject.sln")
if(DEFINED RunCMake_TEST_FAILED)
set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
return()
endif()
# Check group guids and nesting:
MapFind(GROUP_GUIDS "Extraneous" root_group_guid)
if(NOT DEFINED root_group_guid)
set(RunCMake_TEST_FAILED "Extraneous not found" PARENT_SCOPE)
return()
endif()
MapFind(GROUP_PATHS "Extraneous" root_group_path)
if(NOT "${root_group_path}" STREQUAL "Extraneous")
set(RunCMake_TEST_FAILED "Invalid Extraneous path: '${root_group_path}'" PARENT_SCOPE)
return()
endif()
MapFind(PROJECT_PARENTS "${root_group_guid}" root_group_parent_guid)
if(DEFINED root_group_parent_guid)
set(RunCMake_TEST_FAILED "Extraneous is nested" PARENT_SCOPE)
return()
endif()
# Check solution items and nesting:
MapLength(SOLUTION_ITEMS solution_item_count)
if(NOT "${solution_item_count}" EQUAL 1)
set(RunCMake_TEST_FAILED "Unexpected number of solution items: ${solution_item_count}" PARENT_SCOPE)
return()
endif()
MapFind(SOLUTION_ITEMS "extraneous.txt" group_name)
if(NOT DEFINED group_name)
set(RunCMake_TEST_FAILED "Solution item not found: extraneous.txt" PARENT_SCOPE)
return()
endif()
if(NOT "${group_name}" STREQUAL "Extraneous")
set(RunCMake_TEST_FAILED "Invalid group for extraneous.txt: '${group_name}'" PARENT_SCOPE)
return()
endif()
endblock()
include(${CMAKE_CURRENT_LIST_DIR}/SolutionItems-check-sln.cmake)

View File

@@ -0,0 +1,5 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "TestStartup")
error("TestStartup is not the startup project")
endif()

View File

@@ -1,5 +1 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "TestStartup")
error("TestStartup is not the startup project")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/StartupProject-check-sln.cmake)

View File

@@ -0,0 +1,5 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "ALL_BUILD")
error("ALL_BUILD is not the startup project")
endif()

View File

@@ -1,5 +1 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "ALL_BUILD")
error("ALL_BUILD is not the startup project")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/StartupProjectMissing-check-sln.cmake)

View File

@@ -0,0 +1,9 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "CMakePredefinedTargets")
error("CMakePredefinedTargets is not the first project")
endif()
list(GET projects 1 second_project)
if(NOT second_project STREQUAL "TestStartup")
error("TestStartup does not immediately follow the CMakePredefinedTargets project")
endif()

View File

@@ -1,9 +1 @@
getProjectNames(projects)
list(GET projects 0 first_project)
if(NOT first_project STREQUAL "CMakePredefinedTargets")
error("CMakePredefinedTargets is not the first project")
endif()
list(GET projects 1 second_project)
if(NOT second_project STREQUAL "TestStartup")
error("TestStartup does not immediately follow the CMakePredefinedTargets project")
endif()
include(${CMAKE_CURRENT_LIST_DIR}/StartupProjectUseFolders-check-sln.cmake)

View File

@@ -0,0 +1 @@
check_project(CustomConfig external "aaa-bbb-ccc-000" "" "" "Custom - Release")

View File

@@ -1 +1 @@
check_project(CustomConfig external "aaa-bbb-ccc-000" "" "" "Custom - Release")
include(${CMAKE_CURRENT_LIST_DIR}/CustomConfig-check-sln.cmake)

View File

@@ -0,0 +1 @@
check_project(CustomGuid external "aaa-bbb-ccc-000" "" "" "")

View File

@@ -1 +1 @@
check_project(CustomGuid external "aaa-bbb-ccc-000" "" "" "")
include(${CMAKE_CURRENT_LIST_DIR}/CustomGuid-check-sln.cmake)

View File

@@ -0,0 +1 @@
check_project(CustomGuidTypePlatform external "aaa-bbb-ccc-111" "aaa-bbb-ccc-ddd-eee" "Custom Platform" "")

View File

@@ -1 +1 @@
check_project(CustomGuidTypePlatform external "aaa-bbb-ccc-111" "aaa-bbb-ccc-ddd-eee" "Custom Platform" "")
include(${CMAKE_CURRENT_LIST_DIR}/CustomGuidTypePlatform-check-sln.cmake)

View File

@@ -0,0 +1 @@
check_project(CustomTypePlatform external "" "aaa-bbb-ccc-ddd-eee" "Custom Platform" "")

View File

@@ -1 +1 @@
check_project(CustomTypePlatform external "" "aaa-bbb-ccc-ddd-eee" "Custom Platform" "")
include(${CMAKE_CURRENT_LIST_DIR}/CustomTypePlatform-check-sln.cmake)