VsCSharpDefines-check.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Check C# VS project for required elements.
  3. #
  4. set(csProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.csproj")
  5. if(NOT EXISTS "${csProjectFile}")
  6. set(RunCMake_TEST_FAILED "Project file ${csProjectFile} does not exist.")
  7. return()
  8. endif()
  9. set(inDebug FALSE)
  10. set(inRelease FALSE)
  11. set(debugOK FALSE)
  12. set(releaseOK FALSE)
  13. file(STRINGS "${csProjectFile}" lines)
  14. foreach(line IN LISTS lines)
  15. #message(STATUS ${line})
  16. if(line MATCHES "^ *<PropertyGroup .*Debug\\|(Win32|x64).*")
  17. set(inDebug TRUE)
  18. elseif(line MATCHES "^ *<PropertyGroup .*Release\\|(Win32|x64).*")
  19. set(inRelease TRUE)
  20. elseif(line MATCHES "^ *</PropertyGroup> *$")
  21. set(inRelease FALSE)
  22. set(inDebug FALSE)
  23. elseif(inDebug AND
  24. (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
  25. (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$") AND
  26. (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$") AND
  27. (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$"))
  28. )
  29. set(debugOK TRUE)
  30. elseif(inRelease AND
  31. (line MATCHES "^ *<DefineConstants>.*MY_FOO_DEFINE.*</DefineConstants> *$") AND
  32. (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_RELEASE.*</DefineConstants> *$") AND
  33. (line MATCHES "^ *<DefineConstants>.*MY_BAR_ASSIGNMENT=bar.*</DefineConstants> *$") AND
  34. (NOT (line MATCHES "^ *<DefineConstants>.*DEFINE_ONLY_FOR_DEBUG.*</DefineConstants> *$"))
  35. )
  36. set(releaseOK TRUE)
  37. endif()
  38. endforeach()
  39. function(print_csprojfile)
  40. file(STRINGS "${csProjectFile}" lines)
  41. foreach(line IN LISTS lines)
  42. message(STATUS ${line})
  43. endforeach()
  44. endfunction()
  45. if(NOT debugOK)
  46. message(STATUS "Failed to set Debug configuration defines correctly.")
  47. set(RunCMake_TEST_FAILED "Failed to set Debug configuration defines correctly.")
  48. print_csprojfile()
  49. return()
  50. endif()
  51. if(NOT releaseOK)
  52. message(STATUS "Failed to set Release configuration defines correctly.")
  53. set(RunCMake_TEST_FAILED "Failed to set Release configuration defines correctly.")
  54. print_csprojfile()
  55. return()
  56. endif()