VsControlFlowGuardLinkSetting-check.cmake 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/ControlFlowGuardProject.vcxproj")
  2. if(NOT EXISTS "${vcProjectFile}")
  3. set(RunCMake_TEST_FAILED "Project file ControlFlowGuardProject.vcxproj does not exist.")
  4. return()
  5. endif()
  6. set(Is_in_link_section 0)
  7. set(HAS_ControlFlowGuardSetting 0)
  8. file(STRINGS "${vcProjectFile}" lines)
  9. foreach(line IN LISTS lines)
  10. if(line MATCHES "^ *<LinkControlFlowGuard>([^<>]+)</LinkControlFlowGuard>")
  11. set(RunCMake_TEST_FAILED "Project file ControlFlowGuardProject.vcxproj contains the invalid <LinkControlFlowGuard> link property.")
  12. return()
  13. break()
  14. endif()
  15. if(line MATCHES "^ *<Link>")
  16. # The start of the link section of the vcxproj file
  17. set(Is_in_link_section 1)
  18. continue()
  19. endif()
  20. if(line MATCHES "^ *</Link>")
  21. # The end of the link section of the vcxproj file
  22. set(Is_in_link_section 0)
  23. continue()
  24. endif()
  25. if(Is_in_link_section)
  26. if(line MATCHES "^ *<AdditionalOptions>([^<>]+)</AdditionalOptions>")
  27. if("${CMAKE_MATCH_1}" MATCHES ".*/guard:cf.*")
  28. set(HAS_ControlFlowGuardSetting 1)
  29. break()
  30. endif()
  31. endif()
  32. endif()
  33. endforeach()
  34. if(NOT HAS_ControlFlowGuardSetting)
  35. set(RunCMake_TEST_FAILED "Project file ControlFlowGuardProject.vcxproj does not have '/guard:cf' specified in the <AdditionalOptions> property.")
  36. return()
  37. endif()