CMakeLists.txt 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. project(libprotobuf)
  2. include(CheckIncludeFiles)
  3. if(HAVE_PTHREAD)
  4. add_definitions(-DHAVE_PTHREAD=1)
  5. endif()
  6. if(MSVC)
  7. add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
  8. ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
  9. /wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610
  10. /wd4702 /wd4456 /wd4457 /wd4065 /wd4310 /wd4661 /wd4506
  11. /wd4701 /wd4703 # potentially uninitialized local/pointer variable 'value' used
  12. /wd4505 # unreferenced local function has been removed
  13. )
  14. if(MSVC_VERSION LESS 1920) # MSVS 2015/2017
  15. ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4309) # 'static_cast': truncation of constant value
  16. endif()
  17. else()
  18. #NOTE: -Wno-invalid-offsetof was used as solution for invalid offset warning on protobuf #3450
  19. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow
  20. -Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo
  21. -Wundef -Wtautological-undefined-compare -Wignored-qualifiers -Wextra
  22. -Wunused-function -Wunused-const-variable -Wshorten-64-to-32 -Wno-invalid-offsetof
  23. -Wenum-compare-switch
  24. -Wsuggest-override -Winconsistent-missing-override
  25. -Wimplicit-fallthrough
  26. -Warray-bounds # GCC 9+
  27. -Wstringop-overflow -Wstringop-overread # GCC 11-12
  28. -Wextra-semi # clang
  29. -Wcomma # clang
  30. )
  31. endif()
  32. if(CV_ICC)
  33. ocv_warnings_disable(CMAKE_CXX_FLAGS
  34. -wd265 -wd858 -wd873 -wd2196
  35. )
  36. endif()
  37. if(CV_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
  38. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wclass-memaccess)
  39. endif()
  40. # Easier to support different versions of protobufs
  41. function(append_if_exist OUTPUT_LIST)
  42. set(${OUTPUT_LIST})
  43. foreach(fil ${ARGN})
  44. if(EXISTS ${fil})
  45. list(APPEND ${OUTPUT_LIST} "${fil}")
  46. else()
  47. message(WARNING "file missing: ${fil}")
  48. endif()
  49. endforeach()
  50. set(${OUTPUT_LIST} ${${OUTPUT_LIST}} PARENT_SCOPE)
  51. endfunction()
  52. set(PROTOBUF_ROOT "${CMAKE_CURRENT_LIST_DIR}")
  53. append_if_exist(Protobuf_SRCS
  54. # libprotobuf-lite
  55. ${PROTOBUF_ROOT}/src/google/protobuf/any_lite.cc
  56. ${PROTOBUF_ROOT}/src/google/protobuf/arena.cc
  57. ${PROTOBUF_ROOT}/src/google/protobuf/arenastring.cc
  58. ${PROTOBUF_ROOT}/src/google/protobuf/extension_set.cc
  59. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_enum_util.cc
  60. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven_lite.cc
  61. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_tctable_lite.cc
  62. ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_util.cc
  63. ${PROTOBUF_ROOT}/src/google/protobuf/implicit_weak_message.cc
  64. # ${PROTOBUF_ROOT}/src/google/protobuf/inlined_string_field.cc
  65. ${PROTOBUF_ROOT}/src/google/protobuf/io/coded_stream.cc
  66. ${PROTOBUF_ROOT}/src/google/protobuf/io/io_win32.cc
  67. ${PROTOBUF_ROOT}/src/google/protobuf/io/strtod.cc
  68. ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream.cc
  69. ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream_impl.cc
  70. ${PROTOBUF_ROOT}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
  71. ${PROTOBUF_ROOT}/src/google/protobuf/map.cc
  72. ${PROTOBUF_ROOT}/src/google/protobuf/message_lite.cc
  73. ${PROTOBUF_ROOT}/src/google/protobuf/parse_context.cc
  74. ${PROTOBUF_ROOT}/src/google/protobuf/repeated_field.cc
  75. ${PROTOBUF_ROOT}/src/google/protobuf/repeated_ptr_field.cc
  76. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/bytestream.cc
  77. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/common.cc
  78. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/int128.cc
  79. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/status.cc
  80. # ${PROTOBUF_ROOT}/src/google/protobuf/stubs/statusor.cc
  81. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/stringpiece.cc
  82. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/stringprintf.cc
  83. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/structurally_valid.cc
  84. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/strutil.cc
  85. # ${PROTOBUF_ROOT}/src/google/protobuf/stubs/time.cc
  86. ${PROTOBUF_ROOT}/src/google/protobuf/wire_format_lite.cc
  87. # libprotobuf
  88. ${PROTOBUF_ROOT}/src/google/protobuf/any.cc
  89. # ${PROTOBUF_ROOT}/src/google/protobuf/any.pb.cc
  90. # ${PROTOBUF_ROOT}/src/google/protobuf/api.pb.cc
  91. # ${PROTOBUF_ROOT}/src/google/protobuf/compiler/importer.cc
  92. # ${PROTOBUF_ROOT}/src/google/protobuf/compiler/parser.cc
  93. ${PROTOBUF_ROOT}/src/google/protobuf/descriptor.cc
  94. ${PROTOBUF_ROOT}/src/google/protobuf/descriptor.pb.cc
  95. ${PROTOBUF_ROOT}/src/google/protobuf/descriptor_database.cc
  96. # ${PROTOBUF_ROOT}/src/google/protobuf/duration.pb.cc
  97. ${PROTOBUF_ROOT}/src/google/protobuf/dynamic_message.cc
  98. # ${PROTOBUF_ROOT}/src/google/protobuf/empty.pb.cc
  99. ${PROTOBUF_ROOT}/src/google/protobuf/extension_set_heavy.cc
  100. # ${PROTOBUF_ROOT}/src/google/protobuf/field_mask.pb.cc
  101. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_bases.cc
  102. ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_reflection.cc
  103. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_table_driven.cc
  104. # ${PROTOBUF_ROOT}/src/google/protobuf/generated_message_tctable_full.cc
  105. # ${PROTOBUF_ROOT}/src/google/protobuf/io/gzip_stream.cc
  106. # ${PROTOBUF_ROOT}/src/google/protobuf/io/printer.cc
  107. ${PROTOBUF_ROOT}/src/google/protobuf/io/tokenizer.cc
  108. ${PROTOBUF_ROOT}/src/google/protobuf/map_field.cc
  109. ${PROTOBUF_ROOT}/src/google/protobuf/message.cc
  110. ${PROTOBUF_ROOT}/src/google/protobuf/reflection_ops.cc
  111. # ${PROTOBUF_ROOT}/src/google/protobuf/service.cc
  112. # ${PROTOBUF_ROOT}/src/google/protobuf/source_context.pb.cc
  113. # ${PROTOBUF_ROOT}/src/google/protobuf/struct.pb.cc
  114. ${PROTOBUF_ROOT}/src/google/protobuf/stubs/substitute.cc
  115. ${PROTOBUF_ROOT}/src/google/protobuf/text_format.cc
  116. # ${PROTOBUF_ROOT}/src/google/protobuf/timestamp.pb.cc
  117. # ${PROTOBUF_ROOT}/src/google/protobuf/type.pb.cc
  118. ${PROTOBUF_ROOT}/src/google/protobuf/unknown_field_set.cc
  119. # ${PROTOBUF_ROOT}/src/google/protobuf/util/delimited_message_util.cc
  120. # ${PROTOBUF_ROOT}/src/google/protobuf/util/field_comparator.cc
  121. # ${PROTOBUF_ROOT}/src/google/protobuf/util/field_mask_util.cc
  122. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/datapiece.cc
  123. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/default_value_objectwriter.cc
  124. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/error_listener.cc
  125. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/field_mask_utility.cc
  126. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_escaping.cc
  127. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_objectwriter.cc
  128. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/json_stream_parser.cc
  129. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/object_writer.cc
  130. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/proto_writer.cc
  131. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/protostream_objectsource.cc
  132. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/protostream_objectwriter.cc
  133. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/type_info.cc
  134. # ${PROTOBUF_ROOT}/src/google/protobuf/util/internal/utility.cc
  135. # ${PROTOBUF_ROOT}/src/google/protobuf/util/json_util.cc
  136. # ${PROTOBUF_ROOT}/src/google/protobuf/util/message_differencer.cc
  137. # ${PROTOBUF_ROOT}/src/google/protobuf/util/time_util.cc
  138. # ${PROTOBUF_ROOT}/src/google/protobuf/util/type_resolver_util.cc
  139. ${PROTOBUF_ROOT}/src/google/protobuf/wire_format.cc
  140. # ${PROTOBUF_ROOT}/src/google/protobuf/wrappers.pb.cc
  141. )
  142. include_directories(BEFORE "${PROTOBUF_ROOT}/src") # ensure using of own headers: https://github.com/opencv/opencv/issues/13328
  143. add_library(libprotobuf STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${Protobuf_SRCS})
  144. target_include_directories(libprotobuf SYSTEM PUBLIC $<BUILD_INTERFACE:${PROTOBUF_ROOT}/src>)
  145. set_target_properties(libprotobuf
  146. PROPERTIES
  147. FOLDER "3rdparty"
  148. OUTPUT_NAME libprotobuf
  149. DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
  150. COMPILE_PDB_NAME libprotobuf
  151. COMPILE_PDB_NAME_DEBUG "libprotobuf${OPENCV_DEBUG_POSTFIX}"
  152. ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
  153. )
  154. if(ANDROID)
  155. # https://github.com/opencv/opencv/issues/17282
  156. target_link_libraries(libprotobuf INTERFACE "-landroid" "-llog")
  157. endif()
  158. get_protobuf_version(Protobuf_VERSION "${PROTOBUF_ROOT}/src")
  159. set(Protobuf_VERSION ${Protobuf_VERSION} CACHE INTERNAL "" FORCE)
  160. if(NOT BUILD_SHARED_LIBS)
  161. ocv_install_target(libprotobuf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL)
  162. endif()
  163. ocv_install_3rdparty_licenses(protobuf LICENSE README.md)