VsGlobals-check.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. macro(check_project_file projectFile)
  2. if(NOT EXISTS "${projectFile}")
  3. set(RunCMake_TEST_FAILED "Project file ${projectFile} does not exist.")
  4. return()
  5. endif()
  6. string(REPLACE "${RunCMake_TEST_BINARY_DIR}/" "" projectName ${projectFile})
  7. set(InsideGlobals FALSE)
  8. set(DefaultLanguageSet FALSE)
  9. set(MinimumVisualStudioVersionSet FALSE)
  10. set(TestPropertySet FALSE)
  11. file(STRINGS "${projectFile}" lines)
  12. foreach(line IN LISTS lines)
  13. if(line MATCHES "^ *<PropertyGroup Label=\"Globals\"> *$")
  14. set(InsideGlobals TRUE)
  15. elseif(line MATCHES "^ *<DefaultLanguage>([a-zA-Z\\-]+)</DefaultLanguage> *$")
  16. if("${CMAKE_MATCH_1}" STREQUAL "en-US")
  17. if(InsideGlobals)
  18. message(STATUS "${projectName} has correct DefaultLanguage global property")
  19. set(DefaultLanguageSet TRUE)
  20. else()
  21. message(STATUS "DefaultLanguage is set but not within \"Globals\" property group")
  22. endif()
  23. endif()
  24. elseif(line MATCHES "^ *<MinimumVisualStudioVersion>([0-9\\.]+)</MinimumVisualStudioVersion> *$")
  25. if("${CMAKE_MATCH_1}" STREQUAL "10.0")
  26. if(InsideGlobals)
  27. message(STATUS "${projectName} has correct MinimumVisualStudioVersion global property")
  28. set(MinimumVisualStudioVersionSet TRUE)
  29. else()
  30. message(STATUS "MinimumVisualStudioVersion is set but not within \"Globals\" property group")
  31. endif()
  32. endif()
  33. elseif(line MATCHES "^ *<TestProperty>(.+)</TestProperty> *$")
  34. if("${CMAKE_MATCH_1}" STREQUAL "TestValue")
  35. if(InsideGlobals)
  36. message(STATUS "${projectName} has correct TestProperty global property")
  37. set(TestPropertySet TRUE)
  38. else()
  39. message(STATUS "TestProperty is set but not within \"Globals\" property group")
  40. endif()
  41. endif()
  42. endif()
  43. endforeach()
  44. if(NOT DefaultLanguageSet)
  45. set(RunCMake_TEST_FAILED "DefaultLanguage not found or not set correctly in ${projectName}.")
  46. return()
  47. endif()
  48. if(NOT MinimumVisualStudioVersionSet)
  49. set(RunCMake_TEST_FAILED "MinimumVisualStudioVersion not found or not set correctly in ${projectName}.")
  50. return()
  51. endif()
  52. if(NOT TestPropertySet)
  53. set(RunCMake_TEST_FAILED "TestProperty not found or not set correctly in ${projectName}.")
  54. return()
  55. endif()
  56. endmacro()
  57. check_project_file("${RunCMake_TEST_BINARY_DIR}/CMakeFiles/${CMAKE_VERSION}/CompilerIdCXX/CompilerIdCXX.vcxproj")
  58. check_project_file("${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")