CMakeLists.txt 8.5 KB
Newer Older
1 2 3
project(libprotobuf)
include(CheckIncludeFiles)

4 5
if(HAVE_PTHREAD)
  add_definitions(-DHAVE_PTHREAD=1)
6 7 8 9 10 11 12
endif()

if(MSVC)
  add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
  ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
                                       /wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610
                                       /wd4702 /wd4456 /wd4457 /wd4065 /wd4310 /wd4661 /wd4506
A
Alexander Alekhin 已提交
13 14
                                       /wd4701 /wd4703     # potentially uninitialized local/pointer variable 'value' used
                                       /wd4505             # unreferenced local function has been removed
15
  )
16
  if(MSVC_VERSION LESS 1920)  # MSVS 2015/2017
17 18
    ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4309)          # 'static_cast': truncation of constant value
  endif()
19
else()
O
oqtvs 已提交
20
  #NOTE: -Wno-invalid-offsetof was used as solution for invalid offset warning on protobuf #3450
21 22 23
  ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
                                       -Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo
                                       -Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra
O
oqtvs 已提交
24
                                       -Wunused-function -Wunused-const-variable -Wshorten-64-to-32 -Wno-invalid-offsetof
25
                                       -Wenum-compare-switch
26
                                       -Wsuggest-override -Winconsistent-missing-override
27
                                       -Wimplicit-fallthrough
A
Alexander Alekhin 已提交
28
                                       -Warray-bounds  # GCC 9+
29 30 31 32 33 34 35
  )
endif()
if(CV_ICC)
  ocv_warnings_disable(CMAKE_CXX_FLAGS
      -wd265 -wd858 -wd873 -wd2196
  )
endif()
36 37 38
if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
  ocv_warnings_disable(CMAKE_CXX_FLAGS -Wclass-memaccess)
endif()
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

# Easier to support different versions of protobufs
function(append_if_exist OUTPUT_LIST)
    set(${OUTPUT_LIST})
    foreach(fil ${ARGN})
        if(EXISTS ${fil})
            list(APPEND ${OUTPUT_LIST} "${fil}")
        else()
            message(WARNING "file missing: ${fil}")
        endif()
    endforeach()
    set(${OUTPUT_LIST} ${${OUTPUT_LIST}} PARENT_SCOPE)
endfunction()

set(PROTOBUF_ROOT "${CMAKE_CURRENT_LIST_DIR}")


append_if_exist(Protobuf_SRCS
# libprotobuf-lite
58
  ${PROTOBUF_ROOT}/src/google/protobuf/any_lite.cc
59 60 61
  ${PROTOBUF_ROOT}/src/google/protobuf/arena.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/arenastring.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/extension_set.cc
62 63 64
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_enum_util.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven_lite.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_tctable_lite.cc
65
  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_util.cc
66 67
  ${PROTOBUF_ROOT}/src/google/protobuf/implicit_weak_message.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/inlined_string_field.cc
68
  ${PROTOBUF_ROOT}/src/google/protobuf/io/coded_stream.cc
69 70
  ${PROTOBUF_ROOT}/src/google/protobuf/io/io_win32.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/io/strtod.cc
71
  ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream.cc
72
  ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream_impl.cc
73
  ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
74
  ${PROTOBUF_ROOT}/src/google/protobuf/map.cc
75
  ${PROTOBUF_ROOT}/src/google/protobuf/message_lite.cc
76
  ${PROTOBUF_ROOT}/src/google/protobuf/parse_context.cc
77
  ${PROTOBUF_ROOT}/src/google/protobuf/repeated_field.cc
78
  ${PROTOBUF_ROOT}/src/google/protobuf/repeated_ptr_field.cc
79 80 81 82
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/bytestream.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/common.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/int128.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/status.cc
83
#  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/statusor.cc
84 85 86 87
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/stringpiece.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/stringprintf.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/structurally_valid.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/strutil.cc
88
#  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/time.cc
89
  ${PROTOBUF_ROOT}/src/google/protobuf/wire_format_lite.cc
90

91 92
# libprotobuf
  ${PROTOBUF_ROOT}/src/google/protobuf/any.cc
93 94
#  ${PROTOBUF_ROOT}/src/google/protobuf/any.pb.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/api.pb.cc
95 96 97 98 99
#  ${PROTOBUF_ROOT}/src/google/protobuf/compiler/importer.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/compiler/parser.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/descriptor.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/descriptor.pb.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/descriptor_database.cc
100
#  ${PROTOBUF_ROOT}/src/google/protobuf/duration.pb.cc
101
  ${PROTOBUF_ROOT}/src/google/protobuf/dynamic_message.cc
102
#  ${PROTOBUF_ROOT}/src/google/protobuf/empty.pb.cc
103
  ${PROTOBUF_ROOT}/src/google/protobuf/extension_set_heavy.cc
104 105
#  ${PROTOBUF_ROOT}/src/google/protobuf/field_mask.pb.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_bases.cc
106
  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_reflection.cc
107 108 109 110
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_tctable_full.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/io/gzip_stream.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/io/printer.cc
111 112 113 114
  ${PROTOBUF_ROOT}/src/google/protobuf/io/tokenizer.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/map_field.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/message.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/reflection_ops.cc
115 116 117
#  ${PROTOBUF_ROOT}/src/google/protobuf/service.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/source_context.pb.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/struct.pb.cc
118 119
  ${PROTOBUF_ROOT}/src/google/protobuf/stubs/substitute.cc
  ${PROTOBUF_ROOT}/src/google/protobuf/text_format.cc
120 121
#  ${PROTOBUF_ROOT}/src/google/protobuf/timestamp.pb.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/type.pb.cc
122
  ${PROTOBUF_ROOT}/src/google/protobuf/unknown_field_set.cc
123 124 125 126 127
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/delimited_message_util.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/field_comparator.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/field_mask_util.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/datapiece.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/default_value_objectwriter.cc
128
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/error_listener.cc
129 130 131 132 133 134 135 136 137 138 139 140 141 142
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/field_mask_utility.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_escaping.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_objectwriter.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_stream_parser.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/object_writer.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/proto_writer.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/protostream_objectsource.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/protostream_objectwriter.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/type_info.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/utility.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/json_util.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/message_differencer.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/time_util.cc
#  ${PROTOBUF_ROOT}/src/google/protobuf/util/type_resolver_util.cc
143
  ${PROTOBUF_ROOT}/src/google/protobuf/wire_format.cc
144
#  ${PROTOBUF_ROOT}/src/google/protobuf/wrappers.pb.cc
145 146
)

147 148 149

include_directories(BEFORE "${PROTOBUF_ROOT}/src")  # ensure using of own headers: https://github.com/opencv/opencv/issues/13328

150
add_library(libprotobuf STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${Protobuf_SRCS})
151
target_include_directories(libprotobuf SYSTEM PUBLIC $<BUILD_INTERFACE:${PROTOBUF_ROOT}/src>)
152 153 154 155 156
set_target_properties(libprotobuf
    PROPERTIES
    FOLDER "3rdparty"
    OUTPUT_NAME libprotobuf
    DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
157 158
    COMPILE_PDB_NAME libprotobuf
    COMPILE_PDB_NAME_DEBUG "libprotobuf${OPENCV_DEBUG_POSTFIX}"
159 160 161
    ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
    )

162 163 164 165 166
if(ANDROID)
  # https://github.com/opencv/opencv/issues/17282
  target_link_libraries(libprotobuf INTERFACE "-landroid" "-llog")
endif()

167 168 169
get_protobuf_version(Protobuf_VERSION "${PROTOBUF_ROOT}/src")
set(Protobuf_VERSION ${Protobuf_VERSION} CACHE INTERNAL "" FORCE)

170
if(NOT BUILD_SHARED_LIBS)
171
  ocv_install_target(libprotobuf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL)
172
endif()
173 174

ocv_install_3rdparty_licenses(protobuf LICENSE README.md)