1# This file was generated from BUILD using tools/make_cmakelists.py.
2
3cmake_minimum_required(VERSION 3.1)
4
5if(${CMAKE_VERSION} VERSION_LESS 3.12)
6    cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
7else()
8    cmake_policy(VERSION 3.12)
9endif()
10
11cmake_minimum_required (VERSION 3.0)
12cmake_policy(SET CMP0048 NEW)
13
14project(upb)
15set(CMAKE_C_STANDARD 99)
16
17
18# Prevent CMake from setting -rdynamic on Linux (!!).
19SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
20SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
21
22# Set default build type.
23if(NOT CMAKE_BUILD_TYPE)
24  message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
25  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
26      "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
27      FORCE)
28endif()
29
30# When using Ninja, compiler output won't be colorized without this.
31include(CheckCXXCompilerFlag)
32CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS)
33if(SUPPORTS_COLOR_ALWAYS)
34  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
35endif()
36
37# Implement ASAN/UBSAN options
38if(UPB_ENABLE_ASAN)
39  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
40  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
41  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
42  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
43endif()
44
45if(UPB_ENABLE_UBSAN)
46  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
47  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
48  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
49  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
50endif()
51
52include_directories(..)
53include_directories(../cmake)
54include_directories(${CMAKE_CURRENT_BINARY_DIR})
55
56if(NOT TARGET utf8_range)
57  if(EXISTS ../external/utf8_range)
58    # utf8_range is already installed
59    include_directories(../external/utf8_range)
60  else()
61    include(FetchContent)
62    FetchContent_Declare(
63      utf8_range
64      GIT_REPOSITORY "https://github.com/protocolbuffers/utf8_range.git"
65      GIT_TAG "de0b4a8ff9b5d4c98108bdfe723291a33c52c54f"
66    )
67    FetchContent_GetProperties(utf8_range)
68    if(NOT utf8_range_POPULATED)
69      FetchContent_Populate(utf8_range)
70      include_directories(${utf8_range_SOURCE_DIR})
71    endif()
72  endif()
73endif()
74
75if(APPLE)
76  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
77elseif(UNIX)
78  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
79endif()
80
81enable_testing()
82
83add_library(port INTERFACE)
84add_library(upb INTERFACE)
85target_link_libraries(upb INTERFACE
86  base
87  collections_internal
88  fastdecode
89  hash
90  lex
91  mem
92  message_internal
93  mini_table_internal
94  port
95  wire)
96add_library(base
97  ../upb/base/status.c
98  ../upb/base/descriptor_constants.h
99  ../upb/base/log2.h
100  ../upb/base/status.h
101  ../upb/base/string_view.h)
102target_link_libraries(base
103  port)
104add_library(mini_table INTERFACE)
105target_link_libraries(mini_table INTERFACE
106  base
107  mem
108  mini_table_internal
109  port)
110add_library(mini_table_internal
111  ../upb/mini_table/common.c
112  ../upb/mini_table/decode.c
113  ../upb/mini_table/encode.c
114  ../upb/mini_table/extension_registry.c
115  ../upb/mini_table/common.h
116  ../upb/mini_table/common_internal.h
117  ../upb/mini_table/decode.h
118  ../upb/mini_table/encode_internal.h
119  ../upb/mini_table/encode_internal.hpp
120  ../upb/mini_table/enum_internal.h
121  ../upb/mini_table/extension_internal.h
122  ../upb/mini_table/extension_registry.h
123  ../upb/mini_table/field_internal.h
124  ../upb/mini_table/file_internal.h
125  ../upb/mini_table/message_internal.h
126  ../upb/mini_table/sub_internal.h
127  ../upb/mini_table/types.h)
128target_link_libraries(mini_table_internal
129  base
130  hash
131  mem
132  port)
133add_library(message INTERFACE)
134target_link_libraries(message INTERFACE
135  mem
136  message_internal
137  mini_table
138  port)
139add_library(message_internal
140  ../upb/message/message.c
141  ../upb/message/extension_internal.h
142  ../upb/message/internal.h
143  ../upb/message/message.h)
144target_link_libraries(message_internal
145  base
146  hash
147  mem
148  mini_table_internal
149  port)
150add_library(message_accessors
151  ../upb/message/accessors.c
152  ../upb/message/accessors_internal.h
153  ../upb/message/accessors.h)
154target_link_libraries(message_accessors
155  collections_internal
156  eps_copy_input_stream
157  hash
158  message_internal
159  mini_table_internal
160  port
161  upb
162  wire
163  wire_reader)
164add_library(message_promote
165  ../upb/message/promote.c
166  ../upb/message/promote.h)
167target_link_libraries(message_promote
168  collections_internal
169  eps_copy_input_stream
170  hash
171  message_accessors
172  message_internal
173  mini_table_internal
174  port
175  upb
176  wire
177  wire_reader)
178add_library(message_copy
179  ../upb/message/copy.c
180  ../upb/message/copy.h)
181target_link_libraries(message_copy
182  collections_internal
183  message_accessors
184  message_internal
185  mini_table_internal
186  port
187  upb)
188add_library(fastdecode INTERFACE)
189target_link_libraries(fastdecode INTERFACE
190  base
191  collections_internal
192  hash
193  mem_internal
194  message_internal
195  mini_table_internal
196  port
197  wire)
198add_library(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
199target_link_libraries(generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
200  base
201  collections_internal
202  hash
203  upb)
204add_library(generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
205target_link_libraries(generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
206  base
207  collections_internal
208  hash
209  message_copy
210  mini_table
211  upb)
212add_library(generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE)
213target_link_libraries(generated_reflection_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE
214  base
215  descriptor_upb_proto
216  hash
217  mini_table_internal
218  reflection_internal)
219add_library(collections INTERFACE)
220target_link_libraries(collections INTERFACE
221  base
222  collections_internal
223  mem
224  port)
225add_library(collections_internal
226  ../upb/collections/array.c
227  ../upb/collections/map.c
228  ../upb/collections/map_sorter.c
229  ../upb/collections/array.h
230  ../upb/collections/array_internal.h
231  ../upb/collections/map.h
232  ../upb/collections/map_gencode_util.h
233  ../upb/collections/map_internal.h
234  ../upb/collections/map_sorter_internal.h
235  ../upb/collections/message_value.h)
236target_link_libraries(collections_internal
237  base
238  hash
239  mem
240  message_internal
241  mini_table_internal
242  port)
243add_library(textformat
244  ../upb/text/encode.c
245  ../upb/text/encode.h
246  ../upb/text_encode.h)
247target_link_libraries(textformat
248  collections_internal
249  eps_copy_input_stream
250  lex
251  port
252  reflection
253  wire
254  wire_reader
255  wire_types)
256add_library(json
257  ../upb/json/decode.c
258  ../upb/json/encode.c
259  ../upb/json/decode.h
260  ../upb/json/encode.h
261  ../upb/json_decode.h
262  ../upb/json_encode.h)
263target_link_libraries(json
264  collections
265  lex
266  port
267  reflection
268  upb)
269add_library(mem INTERFACE)
270target_link_libraries(mem INTERFACE
271  mem_internal
272  port)
273add_library(mem_internal
274  ../upb/mem/alloc.c
275  ../upb/mem/arena.c
276  ../upb/mem/alloc.h
277  ../upb/mem/arena.h
278  ../upb/mem/arena_internal.h)
279target_link_libraries(mem_internal
280  port)
281add_library(wire INTERFACE)
282target_link_libraries(wire INTERFACE
283  mem
284  message_internal
285  mini_table_internal
286  port
287  wire_internal)
288add_library(wire_internal
289  ../upb/wire/decode.c
290  ../upb/wire/decode_fast.c
291  ../upb/wire/encode.c
292  ../upb/wire/common.h
293  ../upb/wire/common_internal.h
294  ../upb/wire/decode.h
295  ../upb/wire/decode_fast.h
296  ../upb/wire/decode_internal.h
297  ../upb/wire/encode.h
298  ../upb/wire/swap_internal.h)
299target_link_libraries(wire_internal
300  base
301  collections_internal
302  eps_copy_input_stream
303  hash
304  mem_internal
305  message_internal
306  mini_table_internal
307  port
308  wire_reader
309  wire_types
310  utf8_range)
311add_library(wire_types INTERFACE)
312add_library(eps_copy_input_stream
313  ../upb/wire/eps_copy_input_stream.c
314  ../upb/wire/eps_copy_input_stream.h)
315target_link_libraries(eps_copy_input_stream
316  mem
317  port)
318add_library(wire_reader
319  ../upb/wire/reader.c
320  ../upb/wire/swap_internal.h
321  ../upb/wire/reader.h)
322target_link_libraries(wire_reader
323  eps_copy_input_stream
324  port
325  wire_types)
326add_library(hash
327  ../upb/hash/common.c
328  ../upb/hash/common.h
329  ../upb/hash/int_table.h
330  ../upb/hash/str_table.h)
331target_link_libraries(hash
332  base
333  mem
334  port)
335add_library(lex
336  ../upb/lex/atoi.c
337  ../upb/lex/round_trip.c
338  ../upb/lex/strtod.c
339  ../upb/lex/unicode.c
340  ../upb/lex/atoi.h
341  ../upb/lex/round_trip.h
342  ../upb/lex/strtod.h
343  ../upb/lex/unicode.h)
344target_link_libraries(lex
345  port)
346
347
348