CMakeLists.txt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. json_schema_test_suite
  13. GIT_REPOSITORY https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
  14. GIT_TAG Test-JSON-Schema-Acceptance-1.037
  15. )
  16. FetchContent_MakeAvailable(json_schema_test_suite)
  17. include(GoogleTest)
  18. add_executable(annotation_test annotation_test.cxx)
  19. target_link_libraries(annotation_test GTest::gtest GTest::gmock jsoncpp_lib)
  20. gtest_discover_tests(annotation_test)
  21. add_executable(extension_test extension_test.cxx)
  22. target_link_libraries(extension_test GTest::gtest GTest::gmock jsoncpp_lib)
  23. gtest_discover_tests(extension_test)
  24. add_executable(selfvalidate_test selfvalidate_test.cxx)
  25. target_compile_definitions(selfvalidate_test PUBLIC JVALIDATE_USE_EXCEPTIONS)
  26. if (${json_schema_test_suite_POPULATED})
  27. target_compile_definitions(selfvalidate_test
  28. PUBLIC
  29. JVALIDATE_JSON_SCHEMA_TEST_SUITE_DIR="${json_schema_test_suite_SOURCE_DIR}"
  30. )
  31. endif()
  32. target_link_libraries(selfvalidate_test GTest::gtest GTest::gmock jsoncpp_lib CURL::libcurl)
  33. if (ICU_FOUND)
  34. target_link_libraries(annotation_test ICU::uc ICU::i18n)
  35. target_link_libraries(extension_test ICU::uc ICU::i18n)
  36. target_link_libraries(selfvalidate_test ICU::uc ICU::i18n)
  37. endif()
  38. string(
  39. JOIN ":"
  40. SelfValidateTest_Unsupported
  41. "*optional_content"
  42. "*optional_*ecmascript_regex"
  43. "*optional_zeroTerminatedFloats"
  44. "*optional_format*"
  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. gtest_discover_tests(selfvalidate_test
  61. EXTRA_ARGS --json_suite_filter=-${SelfValidateTest_Unsupported_Suites}
  62. --json_case_filter=-${SelfValidateTest_Unsupported_Cases}
  63. TEST_FILTER -${SelfValidateTest_Unsupported})