check-custom-content.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. include(${CMAKE_CURRENT_LIST_DIR}/json.cmake)
  2. if (NOT IS_DIRECTORY "${v1}/data/content")
  3. add_error("Custom content directory does not exist.")
  4. endif()
  5. file(GLOB content_files ${v1}/data/content/*)
  6. list(LENGTH content_files num)
  7. if (NOT ${num} EQUAL 2)
  8. add_error("Found ${num} custom content files, expected 2.")
  9. endif()
  10. # Check contents of configureContent files
  11. set(firstFile "")
  12. foreach(content_file IN LISTS content_files)
  13. read_json("${content_file}" contents)
  14. json_assert_key("${content_file}" "${contents}" myString "string")
  15. json_assert_key("${content_file}" "${contents}" myBool "OFF")
  16. json_assert_key("${content_file}" "${contents}" myInt "1")
  17. json_assert_key("${content_file}" "${contents}" myFloat "2.5")
  18. json_assert_key("${content_file}" "${contents}" myTrue "ON")
  19. json_assert_key("${content_file}" "${contents}" myList "[ \"a\", \"b\", \"c\" ]")
  20. json_assert_key("${content_file}" "${contents}" myObject "{.*\"key\".*:.*\"value\".*}")
  21. if (NOT firstFile)
  22. set(firstFile "${content_file}")
  23. endif()
  24. if ("${content_file}" STREQUAL "${firstFile}")
  25. string(JSON firstN GET "${contents}" nConfigure)
  26. else()
  27. string(JSON secondN GET "${contents}" nConfigure)
  28. endif()
  29. endforeach()
  30. # Ensure provided -DN=* arguments result in differing JSON contents
  31. math(EXPR expectedSecondN "3-${firstN}")
  32. if (NOT ${secondN} EQUAL ${expectedSecondN})
  33. add_error("Configure content did not correspond to provided cache variables.\nGot: ${firstN} and ${secondN}")
  34. endif()
  35. # Ensure snippets reference valid files
  36. foreach(snippet IN LISTS snippets)
  37. read_json("${snippet}" contents)
  38. string(JSON filename GET "${contents}" configureContent)
  39. if (NOT EXISTS "${v1}/data/${filename}")
  40. add_error("Reference to content file that does not exist.")
  41. endif()
  42. endforeach()