Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame^] | 1 | if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt") |
| 2 | message(FATAL_ERROR "Cannot find gmock directory.") |
| 3 | endif() |
| 4 | |
| 5 | option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH |
| 6 | "Using absolute test_plugin path in tests" ON) |
| 7 | |
| 8 | include_directories( |
| 9 | ${protobuf_source_dir}/gmock |
| 10 | ${protobuf_source_dir}/gmock/gtest |
| 11 | ${protobuf_source_dir}/gmock/gtest/include |
| 12 | ${protobuf_source_dir}/gmock/include |
| 13 | ) |
| 14 | |
| 15 | add_library(gmock STATIC |
| 16 | ${protobuf_source_dir}/gmock/src/gmock-all.cc |
| 17 | ${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc |
| 18 | ) |
| 19 | add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc) |
| 20 | target_link_libraries(gmock_main gmock) |
| 21 | |
| 22 | set(lite_test_protos |
| 23 | google/protobuf/map_lite_unittest.proto |
| 24 | google/protobuf/unittest_import_lite.proto |
| 25 | google/protobuf/unittest_import_public_lite.proto |
| 26 | google/protobuf/unittest_lite.proto |
| 27 | google/protobuf/unittest_no_arena_lite.proto |
| 28 | ) |
| 29 | |
| 30 | set(tests_protos |
| 31 | google/protobuf/any_test.proto |
| 32 | google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto |
| 33 | google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto |
| 34 | google/protobuf/map_proto2_unittest.proto |
| 35 | google/protobuf/map_unittest.proto |
| 36 | google/protobuf/unittest.proto |
| 37 | google/protobuf/unittest_arena.proto |
| 38 | google/protobuf/unittest_custom_options.proto |
| 39 | google/protobuf/unittest_drop_unknown_fields.proto |
| 40 | google/protobuf/unittest_embed_optimize_for.proto |
| 41 | google/protobuf/unittest_empty.proto |
| 42 | google/protobuf/unittest_import.proto |
| 43 | google/protobuf/unittest_import_public.proto |
| 44 | google/protobuf/unittest_lite_imports_nonlite.proto |
| 45 | google/protobuf/unittest_mset.proto |
| 46 | google/protobuf/unittest_mset_wire_format.proto |
| 47 | google/protobuf/unittest_no_arena.proto |
| 48 | google/protobuf/unittest_no_arena_import.proto |
| 49 | google/protobuf/unittest_no_field_presence.proto |
| 50 | google/protobuf/unittest_no_generic_services.proto |
| 51 | google/protobuf/unittest_optimize_for.proto |
| 52 | google/protobuf/unittest_preserve_unknown_enum.proto |
| 53 | google/protobuf/unittest_preserve_unknown_enum2.proto |
| 54 | google/protobuf/unittest_proto3_arena.proto |
| 55 | google/protobuf/unittest_well_known_types.proto |
| 56 | google/protobuf/util/internal/testdata/anys.proto |
| 57 | google/protobuf/util/internal/testdata/books.proto |
| 58 | google/protobuf/util/internal/testdata/default_value.proto |
| 59 | google/protobuf/util/internal/testdata/default_value_test.proto |
| 60 | google/protobuf/util/internal/testdata/field_mask.proto |
| 61 | google/protobuf/util/internal/testdata/maps.proto |
| 62 | google/protobuf/util/internal/testdata/oneofs.proto |
| 63 | google/protobuf/util/internal/testdata/struct.proto |
| 64 | google/protobuf/util/internal/testdata/timestamp_duration.proto |
| 65 | google/protobuf/util/json_format_proto3.proto |
| 66 | google/protobuf/util/message_differencer_unittest.proto |
| 67 | ) |
| 68 | |
| 69 | macro(compile_proto_file filename) |
| 70 | get_filename_component(dirname ${filename} PATH) |
| 71 | get_filename_component(basename ${filename} NAME_WE) |
| 72 | add_custom_command( |
| 73 | OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc |
| 74 | DEPENDS protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto |
| 75 | COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto |
| 76 | --proto_path=${protobuf_source_dir}/src |
| 77 | --cpp_out=${protobuf_source_dir}/src |
| 78 | ) |
| 79 | endmacro(compile_proto_file) |
| 80 | |
| 81 | set(lite_test_proto_files) |
| 82 | foreach(proto_file ${lite_test_protos}) |
| 83 | compile_proto_file(${proto_file}) |
| 84 | string(REPLACE .proto .pb.cc pb_file ${proto_file}) |
| 85 | set(lite_test_proto_files ${lite_test_proto_files} |
| 86 | ${protobuf_source_dir}/src/${pb_file}) |
| 87 | endforeach(proto_file) |
| 88 | |
| 89 | set(tests_proto_files) |
| 90 | foreach(proto_file ${tests_protos}) |
| 91 | compile_proto_file(${proto_file}) |
| 92 | string(REPLACE .proto .pb.cc pb_file ${proto_file}) |
| 93 | set(tests_proto_files ${tests_proto_files} |
| 94 | ${protobuf_source_dir}/src/${pb_file}) |
| 95 | endforeach(proto_file) |
| 96 | |
| 97 | set(common_test_files |
| 98 | ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc |
| 99 | ${protobuf_source_dir}/src/google/protobuf/map_test_util.cc |
| 100 | ${protobuf_source_dir}/src/google/protobuf/test_util.cc |
| 101 | ${protobuf_source_dir}/src/google/protobuf/testing/file.cc |
| 102 | ${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc |
| 103 | ) |
| 104 | |
| 105 | set(common_lite_test_files |
| 106 | ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc |
| 107 | ${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc |
| 108 | ${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc |
| 109 | ) |
| 110 | |
| 111 | set(tests_files |
| 112 | ${protobuf_source_dir}/src/google/protobuf/any_test.cc |
| 113 | ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc |
| 114 | ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc |
| 115 | ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc |
| 116 | ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc |
| 117 | ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
| 118 | ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc |
| 119 | ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc |
| 120 | ${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc |
| 121 | ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc |
| 122 | ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc |
| 123 | ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc |
| 124 | ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc |
| 125 | ${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc |
| 126 | ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc |
| 127 | ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc |
| 128 | ${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc |
| 129 | ${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc |
| 130 | ${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc |
| 131 | ${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc |
| 132 | ${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc |
| 133 | ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc |
| 134 | ${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc |
| 135 | ${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc |
| 136 | ${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc |
| 137 | ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc |
| 138 | ${protobuf_source_dir}/src/google/protobuf/map_field_test.cc |
| 139 | ${protobuf_source_dir}/src/google/protobuf/map_test.cc |
| 140 | ${protobuf_source_dir}/src/google/protobuf/message_unittest.cc |
| 141 | ${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc |
| 142 | ${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc |
| 143 | ${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc |
| 144 | ${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc |
| 145 | ${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc |
| 146 | ${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc |
| 147 | ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc |
| 148 | ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc |
| 149 | ${protobuf_source_dir}/src/google/protobuf/stubs/int128_unittest.cc |
| 150 | ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc |
| 151 | ${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc |
| 152 | ${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc |
| 153 | ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece_unittest.cc |
| 154 | ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc |
| 155 | ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc |
| 156 | ${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc |
| 157 | ${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc |
| 158 | ${protobuf_source_dir}/src/google/protobuf/stubs/time_test.cc |
| 159 | ${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc |
| 160 | ${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc |
| 161 | ${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc |
| 162 | ${protobuf_source_dir}/src/google/protobuf/util/field_comparator_test.cc |
| 163 | ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util_test.cc |
| 164 | ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc |
| 165 | ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter_test.cc |
| 166 | ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc |
| 167 | ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc |
| 168 | ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc |
| 169 | ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc |
| 170 | ${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc |
| 171 | ${protobuf_source_dir}/src/google/protobuf/util/message_differencer_unittest.cc |
| 172 | ${protobuf_source_dir}/src/google/protobuf/util/time_util_test.cc |
| 173 | ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc |
| 174 | ${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc |
| 175 | ${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc |
| 176 | ) |
| 177 | |
| 178 | if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) |
| 179 | add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>") |
| 180 | endif() |
| 181 | |
| 182 | add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files}) |
| 183 | target_link_libraries(tests libprotoc libprotobuf gmock_main) |
| 184 | |
| 185 | set(test_plugin_files |
| 186 | ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc |
| 187 | ${protobuf_source_dir}/src/google/protobuf/testing/file.cc |
| 188 | ${protobuf_source_dir}/src/google/protobuf/testing/file.h |
| 189 | ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc |
| 190 | ) |
| 191 | |
| 192 | add_executable(test_plugin ${test_plugin_files}) |
| 193 | target_link_libraries(test_plugin libprotoc libprotobuf gmock) |
| 194 | |
| 195 | set(lite_test_files |
| 196 | ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc |
| 197 | ) |
| 198 | add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files}) |
| 199 | target_link_libraries(lite-test libprotobuf-lite) |
| 200 | |
| 201 | set(lite_arena_test_files |
| 202 | ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc |
| 203 | ) |
| 204 | add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files}) |
| 205 | target_link_libraries(lite-arena-test libprotobuf-lite gmock_main) |
| 206 | |
| 207 | add_custom_target(check |
| 208 | COMMAND tests |
| 209 | WORKING_DIRECTORY ${protobuf_source_dir}) |