1if (protobuf_JSONCPP_PROVIDER STREQUAL "module") 2 if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/jsoncpp/CMakeLists.txt") 3 message(FATAL_ERROR 4 "Cannot find third_party/jsoncpp directory that's needed to " 5 "build conformance tests. If you use git, make sure you have cloned " 6 "submodules:\n" 7 " git submodule update --init --recursive\n" 8 "If instead you want to skip them, run cmake with:\n" 9 " cmake -Dprotobuf_BUILD_CONFORMANCE=OFF\n") 10 endif() 11elseif(protobuf_JSONCPP_PROVIDER STREQUAL "package") 12 find_package(jsoncpp REQUIRED) 13endif() 14 15file(MAKE_DIRECTORY ${protobuf_BINARY_DIR}/conformance) 16 17add_custom_command( 18 OUTPUT 19 ${protobuf_BINARY_DIR}/conformance/conformance.pb.h 20 ${protobuf_BINARY_DIR}/conformance/conformance.pb.cc 21 ${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h 22 ${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc 23 DEPENDS ${protobuf_PROTOC_EXE} 24 ${protobuf_SOURCE_DIR}/conformance/conformance.proto 25 ${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto 26 COMMAND ${protobuf_PROTOC_EXE} 27 ${protobuf_SOURCE_DIR}/conformance/conformance.proto 28 ${protobuf_SOURCE_DIR}/conformance/test_protos/test_messages_edition2023.proto 29 --proto_path=${protobuf_SOURCE_DIR} 30 --cpp_out=${protobuf_BINARY_DIR} 31) 32 33 34add_custom_command( 35 OUTPUT 36 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.h 37 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.cc 38 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.h 39 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.cc 40 DEPENDS ${protobuf_PROTOC_EXE} 41 ${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto3_editions.proto 42 ${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto2_editions.proto 43 COMMAND ${protobuf_PROTOC_EXE} 44 ${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto3_editions.proto 45 ${protobuf_SOURCE_DIR}/editions/golden/test_messages_proto2_editions.proto 46 --proto_path=${protobuf_SOURCE_DIR} 47 --proto_path=${protobuf_SOURCE_DIR}/src 48 --cpp_out=${protobuf_BINARY_DIR} 49) 50 51file(MAKE_DIRECTORY ${protobuf_BINARY_DIR}/src) 52 53add_custom_command( 54 OUTPUT 55 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.h 56 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.cc 57 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.h 58 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.cc 59 DEPENDS ${protobuf_PROTOC_EXE} 60 ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto 61 ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto 62 COMMAND ${protobuf_PROTOC_EXE} 63 ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto 64 ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto 65 --proto_path=${protobuf_SOURCE_DIR}/src 66 --cpp_out=${protobuf_BINARY_DIR}/src 67) 68 69add_library(libconformance_common STATIC 70 ${protobuf_BINARY_DIR}/conformance/conformance.pb.h 71 ${protobuf_BINARY_DIR}/conformance/conformance.pb.cc 72 ${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.h 73 ${protobuf_BINARY_DIR}/conformance/test_protos/test_messages_edition2023.pb.cc 74 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.h 75 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto3_editions.pb.cc 76 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.h 77 ${protobuf_BINARY_DIR}/editions/golden/test_messages_proto2_editions.pb.cc 78 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.h 79 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto2.pb.cc 80 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.h 81 ${protobuf_BINARY_DIR}/src/google/protobuf/test_messages_proto3.pb.cc 82) 83target_link_libraries(libconformance_common 84 ${protobuf_LIB_PROTOBUF} 85 ${protobuf_ABSL_USED_TARGETS} 86) 87 88add_executable(conformance_test_runner 89 ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.cc 90 ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.h 91 ${protobuf_SOURCE_DIR}/conformance/conformance_test.cc 92 ${protobuf_SOURCE_DIR}/conformance/conformance_test_runner.cc 93 ${protobuf_SOURCE_DIR}/conformance/conformance_test_main.cc 94 ${protobuf_SOURCE_DIR}/conformance/text_format_conformance_suite.cc 95 ${protobuf_SOURCE_DIR}/conformance/text_format_conformance_suite.h 96 ${protobuf_SOURCE_DIR}/conformance/failure_list_trie_node.cc 97 ${protobuf_SOURCE_DIR}/conformance/failure_list_trie_node.h 98) 99 100add_executable(conformance_cpp 101 ${protobuf_SOURCE_DIR}/conformance/conformance_cpp.cc 102) 103 104target_include_directories( 105 conformance_test_runner 106 PUBLIC ${protobuf_SOURCE_DIR} ${protobuf_SOURCE_DIR}/conformance) 107 108target_include_directories( 109 conformance_cpp 110 PUBLIC ${protobuf_SOURCE_DIR}) 111 112target_include_directories(conformance_test_runner PRIVATE ${ABSL_ROOT_DIR}) 113target_include_directories(conformance_cpp PRIVATE ${ABSL_ROOT_DIR}) 114 115target_link_libraries(conformance_test_runner 116 libconformance_common 117 ${protobuf_LIB_PROTOBUF} 118 ${protobuf_ABSL_USED_TARGETS} 119) 120target_link_libraries(conformance_cpp 121 libconformance_common 122 ${protobuf_LIB_PROTOBUF} 123 ${protobuf_ABSL_USED_TARGETS} 124) 125 126add_test(NAME conformance_cpp_test 127 COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/conformance_test_runner 128 --failure_list ${protobuf_SOURCE_DIR}/conformance/failure_list_cpp.txt 129 --text_format_failure_list ${protobuf_SOURCE_DIR}/conformance/text_format_failure_list_cpp.txt 130 --output_dir ${protobuf_TEST_XML_OUTDIR} 131 --maximum_edition 2023 132 ${CMAKE_CURRENT_BINARY_DIR}/conformance_cpp 133 DEPENDS conformance_test_runner conformance_cpp) 134 135set(JSONCPP_WITH_TESTS OFF CACHE BOOL "Disable tests") 136if(protobuf_JSONCPP_PROVIDER STREQUAL "module") 137 add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/jsoncpp third_party/jsoncpp) 138 target_include_directories(conformance_test_runner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/jsoncpp/include) 139 if(BUILD_SHARED_LIBS) 140 target_link_libraries(conformance_test_runner jsoncpp_lib) 141 else() 142 target_link_libraries(conformance_test_runner jsoncpp_static) 143 endif() 144else() 145 target_link_libraries(conformance_test_runner jsoncpp) 146endif() 147