CMakeLists.txt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. enable_testing()
  2. # MUST do this before including IDNA
  3. # because it will otherwise poison GTest with BUILD_GMOCK=OFF
  4. find_package(GTest CONFIG REQUIRED COMPONENTS gtest gmock)
  5. find_package(jsoncpp REQUIRED)
  6. find_package(CURL REQUIRED)
  7. # ICU Components Reference:
  8. # https://cmake.org/cmake/help/latest/module/FindICU.html
  9. # ICU components = data, i18n, io, le, lx, test, tu and uc.
  10. find_package(ICU 77.1 COMPONENTS uc i18n)
  11. FetchContent_Declare(
  12. IDNA
  13. GIT_REPOSITORY https://github.com/ada-url/idna.git
  14. GIT_TAG 0.5.0
  15. )
  16. FetchContent_MakeAvailable(IDNA)
  17. FetchContent_Declare(
  18. json_schema_test_suite
  19. GIT_REPOSITORY https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
  20. GIT_TAG Test-JSON-Schema-Acceptance-1.037
  21. )
  22. FetchContent_MakeAvailable(json_schema_test_suite)
  23. include(GoogleTest)
  24. add_executable(annotation_test annotation_test.cxx)
  25. target_link_libraries(annotation_test GTest::gtest GTest::gmock jsoncpp_lib)
  26. gtest_discover_tests(annotation_test)
  27. add_executable(extension_test extension_test.cxx)
  28. target_link_libraries(extension_test GTest::gtest GTest::gmock jsoncpp_lib)
  29. gtest_discover_tests(extension_test)
  30. add_executable(selfvalidate_test selfvalidate_test.cxx)
  31. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_USE_EXCEPTIONS)
  32. if (${json_schema_test_suite_POPULATED})
  33. target_compile_definitions(selfvalidate_test
  34. PUBLIC
  35. JVALIDATE_JSON_SCHEMA_TEST_SUITE_DIR="${json_schema_test_suite_SOURCE_DIR}"
  36. )
  37. endif()
  38. target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock jsoncpp_lib CURL::libcurl)
  39. string(
  40. JOIN ":"
  41. SelfValidateTest_Unsupported
  42. "*optional_content"
  43. "*optional_*ecmascript_regex"
  44. "*optional_zeroTerminatedFloats"
  45. )
  46. set(SelfValidateTest_Unsupported_Suites "")
  47. set(SelfValidateTest_Unsupported_Cases "*leap second")
  48. if (ICU_FOUND)
  49. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_ICU=1)
  50. target_link_libraries(annotation_test ICU::uc ICU::i18n)
  51. target_link_libraries(extension_test ICU::uc ICU::i18n)
  52. target_link_libraries(selfvalidate_test ICU::uc ICU::i18n)
  53. else()
  54. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_ICU=0)
  55. string(
  56. APPEND SelfValidateTest_Unsupported
  57. ":*optional_non_bmp_regex"
  58. )
  59. endif()
  60. if (idna_POPULATED)
  61. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_IDNA=1)
  62. target_link_libraries(annotation_test ada-idna)
  63. target_link_libraries(extension_test ada-idna)
  64. target_link_libraries(selfvalidate_test ada-idna)
  65. else()
  66. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_HAS_IDNA=0)
  67. string(
  68. APPEND SelfValidateTest_Unsupported
  69. ":*optional_*iri*"
  70. ":*optional_*idn*"
  71. ":*optional_*uri_template*"
  72. )
  73. string(
  74. APPEND SelfValidateTest_Unsupported_Suites
  75. ":*punycode*"
  76. ":*puny-code"
  77. )
  78. string(
  79. APPEND SelfValidateTest_Unsupported_Cases
  80. ":*punycode*"
  81. ":*puny-code"
  82. )
  83. endif()
  84. gtest_discover_tests(selfvalidate_test
  85. EXTRA_ARGS --json_suite_filter=-${SelfValidateTest_Unsupported_Suites}
  86. --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
  87. TEST_FILTER -${SelfValidateTest_Unsupported})