• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt")
2  message(FATAL_ERROR "Cannot find gmock directory.")
3endif()
4
5option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
6  "Using absolute test_plugin path in tests" ON)
7
8include_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
15add_library(gmock STATIC
16  ${protobuf_source_dir}/gmock/src/gmock-all.cc
17  ${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc
18)
19add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc)
20target_link_libraries(gmock_main gmock)
21
22set(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
30set(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_proto3_arena_lite.proto
56  google/protobuf/unittest_proto3_lite.proto
57  google/protobuf/unittest_well_known_types.proto
58  google/protobuf/util/internal/testdata/anys.proto
59  google/protobuf/util/internal/testdata/books.proto
60  google/protobuf/util/internal/testdata/default_value.proto
61  google/protobuf/util/internal/testdata/default_value_test.proto
62  google/protobuf/util/internal/testdata/field_mask.proto
63  google/protobuf/util/internal/testdata/maps.proto
64  google/protobuf/util/internal/testdata/oneofs.proto
65  google/protobuf/util/internal/testdata/struct.proto
66  google/protobuf/util/internal/testdata/timestamp_duration.proto
67  google/protobuf/util/json_format_proto3.proto
68  google/protobuf/util/message_differencer_unittest.proto
69)
70
71macro(compile_proto_file filename)
72  get_filename_component(dirname ${filename} PATH)
73  get_filename_component(basename ${filename} NAME_WE)
74  add_custom_command(
75    OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc
76    DEPENDS protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
77    COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
78        --proto_path=${protobuf_source_dir}/src
79        --cpp_out=${protobuf_source_dir}/src
80  )
81endmacro(compile_proto_file)
82
83set(lite_test_proto_files)
84foreach(proto_file ${lite_test_protos})
85  compile_proto_file(${proto_file})
86  string(REPLACE .proto .pb.cc pb_file ${proto_file})
87  set(lite_test_proto_files ${lite_test_proto_files}
88      ${protobuf_source_dir}/src/${pb_file})
89endforeach(proto_file)
90
91set(tests_proto_files)
92foreach(proto_file ${tests_protos})
93  compile_proto_file(${proto_file})
94  string(REPLACE .proto .pb.cc pb_file ${proto_file})
95  set(tests_proto_files ${tests_proto_files}
96      ${protobuf_source_dir}/src/${pb_file})
97endforeach(proto_file)
98
99set(common_test_files
100  ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
101  ${protobuf_source_dir}/src/google/protobuf/map_test_util.cc
102  ${protobuf_source_dir}/src/google/protobuf/test_util.cc
103  ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
104  ${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc
105)
106
107set(common_lite_test_files
108  ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
109  ${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc
110  ${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc
111)
112
113set(tests_files
114  ${protobuf_source_dir}/src/google/protobuf/any_test.cc
115  ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc
116  ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc
117  ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc
118  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
119  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
120  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc
121  ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/metadata_test.cc
122  ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
123  ${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc
124  ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
125  ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc
126  ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
127  ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
128  ${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc
129  ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc
130  ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
131  ${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc
132  ${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc
133  ${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc
134  ${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc
135  ${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc
136  ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc
137  ${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc
138  ${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc
139  ${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc
140  ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc
141  ${protobuf_source_dir}/src/google/protobuf/map_field_test.cc
142  ${protobuf_source_dir}/src/google/protobuf/map_test.cc
143  ${protobuf_source_dir}/src/google/protobuf/message_unittest.cc
144  ${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc
145  ${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc
146  ${protobuf_source_dir}/src/google/protobuf/proto3_arena_lite_unittest.cc
147  ${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc
148  ${protobuf_source_dir}/src/google/protobuf/proto3_lite_unittest.cc
149  ${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc
150  ${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc
151  ${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc
152  ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc
153  ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc
154  ${protobuf_source_dir}/src/google/protobuf/stubs/int128_unittest.cc
155  ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc
156  ${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc
157  ${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc
158  ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece_unittest.cc
159  ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc
160  ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc
161  ${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc
162  ${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc
163  ${protobuf_source_dir}/src/google/protobuf/stubs/time_test.cc
164  ${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc
165  ${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc
166  ${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc
167  ${protobuf_source_dir}/src/google/protobuf/util/field_comparator_test.cc
168  ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util_test.cc
169  ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
170  ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter_test.cc
171  ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc
172  ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc
173  ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
174  ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
175  ${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc
176  ${protobuf_source_dir}/src/google/protobuf/util/message_differencer_unittest.cc
177  ${protobuf_source_dir}/src/google/protobuf/util/time_util_test.cc
178  ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc
179  ${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc
180  ${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc
181)
182
183if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
184  add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
185endif()
186
187add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files})
188target_link_libraries(tests libprotoc libprotobuf gmock_main)
189
190set(test_plugin_files
191  ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
192  ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
193  ${protobuf_source_dir}/src/google/protobuf/testing/file.h
194  ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc
195)
196
197add_executable(test_plugin ${test_plugin_files})
198target_link_libraries(test_plugin libprotoc libprotobuf gmock)
199
200set(lite_test_files
201  ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc
202)
203add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files})
204target_link_libraries(lite-test libprotobuf-lite)
205
206set(lite_arena_test_files
207  ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc
208)
209add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
210target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
211
212add_custom_target(check
213  COMMAND tests
214  WORKING_DIRECTORY ${protobuf_source_dir})
215