UnityBuildNative-check.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. set(unitybuild_c0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c")
  2. if(NOT EXISTS "${unitybuild_c0}")
  3. set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c0} does not exist.")
  4. return()
  5. endif()
  6. set(tgt_project "${RunCMake_TEST_BINARY_DIR}/tgt.vcxproj")
  7. if (NOT EXISTS "${tgt_project}")
  8. set(RunCMake_TEST_FAILED "Generated project file ${tgt_project} doesn't exist.")
  9. return()
  10. endif()
  11. file(STRINGS ${tgt_project} tgt_projects_strings)
  12. foreach(line IN LISTS tgt_projects_strings)
  13. if (line MATCHES "<EnableUnitySupport>true</EnableUnitySupport>")
  14. set(have_unity_support ON)
  15. endif()
  16. if (line MATCHES "<ClCompile Include=.*IncludeInUnityFile=\"false\" CustomUnityFile=\"true\"")
  17. set(unity_source_line ${line})
  18. endif()
  19. if (line MATCHES "<ClCompile Include=.*IncludeInUnityFile=\"true\" CustomUnityFile=\"true\"")
  20. list(APPEND sources_list ${line})
  21. endif()
  22. endforeach()
  23. if (NOT have_unity_support)
  24. set(RunCMake_TEST_FAILED "Generated project should include the <EnableUnitySupport> block.")
  25. return()
  26. endif()
  27. string(REPLACE "\\" "/" unity_source_line "${unity_source_line}")
  28. string(FIND "${unity_source_line}" "CMakeFiles/tgt.dir/Unity/unity_0_c.c" unity_source_file_position)
  29. if (unity_source_file_position EQUAL "-1")
  30. set(RunCMake_TEST_FAILED "Generated project should include the generated unity source file.")
  31. return()
  32. endif()
  33. list(LENGTH sources_list number_of_sources)
  34. if(NOT number_of_sources EQUAL 8)
  35. set(RunCMake_TEST_FAILED "Generated project doesn't include the expect number of files.")
  36. return()
  37. endif()