• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.4.1)
2
3set( PROTOBUF_INSTALL_DIR "${CMAKE_CURRENT_LIST_DIR}/../../third_party/protobuf-3.0.0/install/linux-x86")
4set( PROTOBUF_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/../../third_party/protobuf-3.0.0/src")
5if( NOT DEFINED PROTOBUF_NANO_SRC_DIR)
6  set( PROTOBUF_NANO_SRC_DIR "${EXTERNAL_ROOT}/nanopb-c")
7endif()
8set(PROTOC_EXE ${PROTOBUF_INSTALL_DIR}/bin/protoc)
9set( PROTOBUF_INCLUDE_DIR ${PROTOBUF_SRC_DIR} )
10
11set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Werror -Wthread-safety" )
12set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D _LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Os -fPIC" )
13set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti" )
14set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGOOGLE_PROTOBUF_NO_RTTI -DHAVE_PTHREAD")
15set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections" )
16
17function(set_link_options libname versionscript)
18  if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
19  set_target_properties( ${libname} PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/${versionscript}")
20  endif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
21endfunction()
22
23function(extra_pb_link_options libname)
24  set_link_options(${libname} "protobuf/protobuf_version.script")
25endfunction()
26
27function(extra_pb_nano_link_options libname)
28  set_link_options(${libname} "protobuf/protobuf_nano_version.script")
29endfunction()
30
31set(PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens)
32get_directory_property(hasParent PARENT_DIRECTORY)
33if(hasParent)
34  set(PROTO_GENS_DIR ${_PROTO_GENS_DIR} PARENT_SCOPE)
35  set(PROTOC_EXE ${PROTOC_EXE} PARENT_SCOPE)
36  set(PROTOBUF_SRC_DIR ${PROTOBUF_SRC_DIR} PARENT_SCOPE)
37  set(PROTOBUF_NANO_SRC_DIR ${PROTOBUF_NANO_SRC_DIR} PARENT_SCOPE)
38endif()
39file(MAKE_DIRECTORY ${PROTO_GENS_DIR}/full)
40file(MAKE_DIRECTORY ${PROTO_GENS_DIR}/lite)
41file(MAKE_DIRECTORY ${PROTO_GENS_DIR}/nano)
42
43function(protobuf_generate_base)
44  if(NOT ARGN)
45    message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
46    return()
47  endif()
48
49  set(_extension ${ARGV0})
50  set(_out_opt ${ARGV1})
51  set(_extra_opts ${ARGV2})
52  set(_gens_subdir ${ARGV3})
53  set(_working_dir ${ARGV4})
54  list(REMOVE_AT ARGN 0)
55  list(REMOVE_AT ARGN 0)
56  list(REMOVE_AT ARGN 0)
57  list(REMOVE_AT ARGN 0)
58  list(REMOVE_AT ARGN 0)
59
60  set(_protobuf_include_path -I .)
61  set(_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens${_gens_subdir})
62  message(STATUS "protobuf_generate_base._working_dir=${_working_dir}")
63  message(STATUS "protobuf_generate_base._PROTO_GENS_DIR=${_PROTO_GENS_DIR}")
64  message(STATUS "protobuf_generate_base._extension=${_extension}")
65  message(STATUS "protobuf_generate_base.PROTOC_EXE=${PROTOC_EXE}")
66  foreach(FIL ${ARGN})
67    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
68    get_filename_component(FIL_WE ${FIL} NAME_WE)
69    file(RELATIVE_PATH REL_FIL ${_working_dir} ${ABS_FIL})
70    get_filename_component(REL_DIR ${REL_FIL} DIRECTORY)
71    set(RELFIL_WE "${REL_DIR}/${FIL_WE}")
72
73    add_custom_command(
74      OUTPUT "${_PROTO_GENS_DIR}${RELFIL_WE}.pb.${_extension}"
75             "${_PROTO_GENS_DIR}${RELFIL_WE}.pb.h"
76      COMMAND ${PROTOC_EXE}
77      ARGS ${_out_opt}=${_PROTO_GENS_DIR}
78           ${_extra_opts}
79           ${_protobuf_include_path}
80           ${REL_FIL}
81      WORKING_DIRECTORY ${_working_dir}
82      COMMENT "Running C++ protocol buffer compiler on ${FIL}"
83      VERBATIM)
84
85    message(STATUS "${PROTOC_EXE} will generate ${_PROTO_GENS_DIR}${RELFIL_WE}.pb.*")
86
87    set_source_files_properties(
88      "${_PROTO_GENS_DIR}${RELFIL_WE}.pb.${_extension}"
89      "${_PROTO_GENS_DIR}${RELFIL_WE}.pb.h" PROPERTIES GENERATED TRUE)
90  endforeach()
91endfunction()
92
93get_filename_component(ABS_PROTOBUF_NANO_SRC_DIR ${PROTOBUF_NANO_SRC_DIR} ABSOLUTE)
94
95function(protobuf_generate_nano_c)
96  protobuf_generate_base("c" "--nanopb_out"
97    "--plugin=protoc-gen-nanopb=${ABS_PROTOBUF_NANO_SRC_DIR}/generator/protoc-gen-nanopb"
98    "/nano" ${ARGN})
99endfunction()
100
101function(protobuf_generate_full_cpp)
102  protobuf_generate_base("cc" "--cpp_out" "" "/full" ${ARGN})
103endfunction()
104
105function(protobuf_generate_lite_cpp)
106  protobuf_generate_base("cc" "--cpp_out" "" "/lite" ${ARGN})
107endfunction()
108
109set(GP_SRC_DIR ${PROTOBUF_SRC_DIR}/google/protobuf)
110
111set(PROTOBUF_LITE_SRCS
112    ${GP_SRC_DIR}/arena.cc
113    ${GP_SRC_DIR}/arenastring.cc
114    ${GP_SRC_DIR}/extension_set.cc
115    ${GP_SRC_DIR}/generated_message_util.cc
116    ${GP_SRC_DIR}/io/coded_stream.cc
117    ${GP_SRC_DIR}/io/zero_copy_stream.cc
118    ${GP_SRC_DIR}/io/zero_copy_stream_impl_lite.cc
119    ${GP_SRC_DIR}/message_lite.cc
120    ${GP_SRC_DIR}/repeated_field.cc
121    ${GP_SRC_DIR}/stubs/atomicops_internals_x86_gcc.cc
122    ${GP_SRC_DIR}/stubs/atomicops_internals_x86_msvc.cc
123    ${GP_SRC_DIR}/stubs/bytestream.cc
124    ${GP_SRC_DIR}/stubs/common.cc
125    ${GP_SRC_DIR}/stubs/int128.cc
126    ${GP_SRC_DIR}/stubs/once.cc
127    ${GP_SRC_DIR}/stubs/status.cc
128    ${GP_SRC_DIR}/stubs/statusor.cc
129    ${GP_SRC_DIR}/stubs/stringpiece.cc
130    ${GP_SRC_DIR}/stubs/stringprintf.cc
131    ${GP_SRC_DIR}/stubs/structurally_valid.cc
132    ${GP_SRC_DIR}/stubs/strutil.cc
133    ${GP_SRC_DIR}/stubs/time.cc
134    ${GP_SRC_DIR}/wire_format_lite.cc)
135
136set(PROTOBUF_SRCS
137    ${GP_SRC_DIR}/any.cc
138    ${GP_SRC_DIR}/any.pb.cc
139    ${GP_SRC_DIR}/api.pb.cc
140    ${GP_SRC_DIR}/compiler/importer.cc
141    ${GP_SRC_DIR}/compiler/parser.cc
142    ${GP_SRC_DIR}/descriptor.cc
143    ${GP_SRC_DIR}/descriptor.pb.cc
144    ${GP_SRC_DIR}/descriptor_database.cc
145    ${GP_SRC_DIR}/duration.pb.cc
146    ${GP_SRC_DIR}/dynamic_message.cc
147    ${GP_SRC_DIR}/empty.pb.cc
148    ${GP_SRC_DIR}/extension_set_heavy.cc
149    ${GP_SRC_DIR}/field_mask.pb.cc
150    ${GP_SRC_DIR}/generated_message_reflection.cc
151    ${GP_SRC_DIR}/io/gzip_stream.cc
152    ${GP_SRC_DIR}/io/printer.cc
153    ${GP_SRC_DIR}/io/strtod.cc
154    ${GP_SRC_DIR}/io/tokenizer.cc
155    ${GP_SRC_DIR}/io/zero_copy_stream_impl.cc
156    ${GP_SRC_DIR}/map_field.cc
157    ${GP_SRC_DIR}/message.cc
158    ${GP_SRC_DIR}/reflection_ops.cc
159    ${GP_SRC_DIR}/service.cc
160    ${GP_SRC_DIR}/source_context.pb.cc
161    ${GP_SRC_DIR}/struct.pb.cc
162    ${GP_SRC_DIR}/stubs/mathlimits.cc
163    ${GP_SRC_DIR}/stubs/substitute.cc
164    ${GP_SRC_DIR}/text_format.cc
165    ${GP_SRC_DIR}/timestamp.pb.cc
166    ${GP_SRC_DIR}/type.pb.cc
167    ${GP_SRC_DIR}/unknown_field_set.cc
168    ${GP_SRC_DIR}/util/field_comparator.cc
169    ${GP_SRC_DIR}/util/field_mask_util.cc
170    ${GP_SRC_DIR}/util/internal/datapiece.cc
171    ${GP_SRC_DIR}/util/internal/default_value_objectwriter.cc
172    ${GP_SRC_DIR}/util/internal/error_listener.cc
173    ${GP_SRC_DIR}/util/internal/field_mask_utility.cc
174    ${GP_SRC_DIR}/util/internal/json_escaping.cc
175    ${GP_SRC_DIR}/util/internal/json_objectwriter.cc
176    ${GP_SRC_DIR}/util/internal/json_stream_parser.cc
177    ${GP_SRC_DIR}/util/internal/object_writer.cc
178    ${GP_SRC_DIR}/util/internal/proto_writer.cc
179    ${GP_SRC_DIR}/util/internal/protostream_objectsource.cc
180    ${GP_SRC_DIR}/util/internal/protostream_objectwriter.cc
181    ${GP_SRC_DIR}/util/internal/type_info.cc
182    ${GP_SRC_DIR}/util/internal/type_info_test_helper.cc
183    ${GP_SRC_DIR}/util/internal/utility.cc
184    ${GP_SRC_DIR}/util/json_util.cc
185    ${GP_SRC_DIR}/util/message_differencer.cc
186    ${GP_SRC_DIR}/util/time_util.cc
187    ${GP_SRC_DIR}/util/type_resolver_util.cc
188    ${GP_SRC_DIR}/wire_format.cc
189    ${GP_SRC_DIR}/wrappers.pb.cc)
190
191set(PROTOBUF_NANO_SRCS
192    ${PROTOBUF_NANO_SRC_DIR}/pb_encode.c
193    ${PROTOBUF_NANO_SRC_DIR}/pb_decode.c
194    ${PROTOBUF_NANO_SRC_DIR}/pb_common.c)
195