1
+ project (libprotobuf )
2
+
3
+ include (CheckIncludeFiles )
4
+ include (cmake/CheckCxxHashset.cmake )
5
+ include (cmake/CheckCxxHashmap.cmake )
6
+
7
+ check_include_files ("pthread.h" HAVE_PTHREAD )
8
+
9
+ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
10
+ include (CheckIncludeFileCXX )
11
+ set (CMAKE_REQUIRED_FLAGS "-std=c++11" )
12
+ check_include_file_cxx ("unordered_map" HAVE_UNORDERED_MAP )
13
+ check_include_file_cxx ("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP )
14
+ set (CMAKE_REQUIRED_FLAGS )
15
+
16
+ if (HAVE_UNORDERED_MAP )
17
+ add_definitions ("-std=c++11" ) # For unordered_map
18
+ set (HASH_MAP_H "<unordered_map>" )
19
+ set (HASH_MAP_CLASS "unordered_map" )
20
+ set (HASH_NAMESPACE "std" )
21
+ set (HAVE_HASH_MAP 1 )
22
+ elseif (HAVE_TR1_UNORDERED_MAP )
23
+ add_definitions ("-std=c++11" ) # For unordered_map
24
+ set (HASH_MAP_H "<tr1/unordered_map>" )
25
+ set (HASH_MAP_CLASS "unordered_map" )
26
+ set (HASH_NAMESPACE "std::tr1" )
27
+ set (HAVE_HASH_MAP 1 )
28
+ else ()
29
+ CHECK_HASHMAP ()
30
+ if (HAVE_GNU_EXT_HASH_MAP )
31
+ set (HASH_MAP_H "<ext/hash_map>" )
32
+ set (HASH_NAMESPACE "__gnu_cxx" )
33
+ set (HASH_MAP_CLASS "hash_map" )
34
+ set (HAVE_HASH_MAP 1 )
35
+ elseif (HAVE_STD_EXT_HASH_MAP )
36
+ set (HASH_MAP_H "<ext/hash_map>" )
37
+ set (HASH_NAMESPACE "std" )
38
+ set (HASH_MAP_CLASS "hash_map" )
39
+ set (HAVE_HASH_MAP 1 )
40
+ elseif (HAVE_GLOBAL_HASH_MAP )
41
+ set (HASH_MAP_H "<ext/hash_map>" )
42
+ set (HASH_NAMESPACE "" )
43
+ set (HASH_MAP_CLASS "hash_map" )
44
+ set (HAVE_HASH_MAP 1 )
45
+ else ()
46
+ set (HAVE_HASH_MAP 0 )
47
+ endif ()
48
+ endif ()
49
+
50
+ set (CMAKE_REQUIRED_FLAGS "-std=c++11" )
51
+ check_include_file_cxx ("unordered_set" HAVE_UNORDERED_SET )
52
+ check_include_file_cxx ("tr1/unordered_set" HAVE_TR1_UNORDERED_SET )
53
+ set (CMAKE_REQUIRED_FLAGS )
54
+
55
+ if (HAVE_UNORDERED_SET )
56
+ set (HASH_SET_H "<unordered_set>" )
57
+ set (HASH_SET_CLASS "unordered_set" )
58
+ set (HAVE_HASH_SET 1 )
59
+ elseif (HAVE_TR1_UNORDERED_SET )
60
+ add_definitions ("-std=c++11" )
61
+ set (HASH_SET_H "<tr1/unordered_set>" )
62
+ set (HASH_SET_CLASS "unordered_set" )
63
+ set (HAVE_HASH_SET 1 )
64
+ else ()
65
+ CHECK_HASHSET ()
66
+ if (HAVE_GNU_EXT_HASH_SET )
67
+ set (HASH_SET_H "<ext/hash_set>" )
68
+ set (HASH_NAMESPACE "__gnu_cxx" )
69
+ set (HASH_SET_CLASS "hash_set" )
70
+ set (HAVE_HASH_SET 1 )
71
+ elseif (HAVE_STD_EXT_HASH_SET )
72
+ set (HASH_SET_H "<ext/hash_set>" )
73
+ set (HASH_NAMESPACE "std" )
74
+ set (HASH_SET_CLASS "hash_set" )
75
+ set (HAVE_HASH_SET 1 )
76
+ elseif (HAVE_GLOBAL_HASH_SET )
77
+ set (HASH_SET_H "<hash_set>" )
78
+ set (HASH_NAMESPACE "" )
79
+ set (HASH_SET_CLASS "hash_set" )
80
+ set (HAVE_HASH_SET 1 )
81
+ else ()
82
+ set (HAVE_HASH_SET 0 )
83
+ endif ()
84
+ endif ()
85
+ endif ()
86
+
87
+ if (WIN32 AND BUILD_SHARED_LIBS AND MSVC )
88
+ add_definitions (-DPROTOBUF_USE_DLLS )
89
+ add_definitions (-DLIBPROTOBUF_EXPORTS )
90
+ endif ()
91
+
92
+ #add_definitions( -DGOOGLE_PROTOBUF_NO_THREAD_SAFETY ) #we don't need thread safety
93
+ add_definitions ( -D_GNU_SOURCE=1 ) #it's maybe useful
94
+ add_definitions ( -DHAVE_CONFIG_H ) #we will use config.h
95
+ configure_file ("cmake/config.h.in" "config.h" )
96
+
97
+ if (MSVC )
98
+ add_definitions ( -D_CRT_SECURE_NO_WARNINGS=1 )
99
+ ocv_warnings_disable (CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305 /wd4127 /wd4100 /wd4512 /wd4125 /wd4389 /wd4510 /wd4610 /wd4702 )
100
+ else ()
101
+ ocv_warnings_disable (CMAKE_CXX_FLAGS -Wno-deprecated -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wunused-parameter -Wunused-local-typedefs -Wsign-compare -Wsign-promo -Wundef )
102
+ endif ()
103
+
104
+ # Easier to support different versions of protobufs
105
+ function (append_if_exist OUTPUT_LIST )
106
+ set (${OUTPUT_LIST} )
107
+ foreach (fil ${ARGN} )
108
+ if (EXISTS ${fil} )
109
+ list (APPEND ${OUTPUT_LIST} "${fil} " )
110
+ else ()
111
+ message (WARNING "file missing: ${fil} " )
112
+ endif ()
113
+ endforeach ()
114
+ set (${OUTPUT_LIST} ${${OUTPUT_LIST}} PARENT_SCOPE )
115
+ endfunction ()
116
+
117
+ set (PROTOBUF_ROOT ${CMAKE_CURRENT_SOURCE_DIR} )
118
+
119
+ if (MSVC )
120
+ set (ATOMICOPS_INTERNALS ${PROTOBUF_ROOT} /src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc )
121
+ else ()
122
+ set (ATOMICOPS_INTERNALS ${PROTOBUF_ROOT} /src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc )
123
+ endif ()
124
+
125
+ append_if_exist (PROTOBUF_SRCS
126
+ ${PROTOBUF_ROOT} /src/google/protobuf/compiler/importer.cc
127
+ ${PROTOBUF_ROOT} /src/google/protobuf/compiler/parser.cc
128
+ ${PROTOBUF_ROOT} /src/google/protobuf/descriptor.cc
129
+ ${PROTOBUF_ROOT} /src/google/protobuf/descriptor.pb.cc
130
+ ${PROTOBUF_ROOT} /src/google/protobuf/descriptor_database.cc
131
+ ${PROTOBUF_ROOT} /src/google/protobuf/dynamic_message.cc
132
+ ${PROTOBUF_ROOT} /src/google/protobuf/extension_set.cc
133
+ ${PROTOBUF_ROOT} /src/google/protobuf/extension_set_heavy.cc
134
+ ${PROTOBUF_ROOT} /src/google/protobuf/generated_message_reflection.cc
135
+ ${PROTOBUF_ROOT} /src/google/protobuf/generated_message_util.cc
136
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/coded_stream.cc
137
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/gzip_stream.cc
138
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/printer.cc
139
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/tokenizer.cc
140
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/zero_copy_stream.cc
141
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/zero_copy_stream_impl.cc
142
+ ${PROTOBUF_ROOT} /src/google/protobuf/io/zero_copy_stream_impl_lite.cc
143
+ ${PROTOBUF_ROOT} /src/google/protobuf/message.cc
144
+ ${PROTOBUF_ROOT} /src/google/protobuf/message_lite.cc
145
+ ${PROTOBUF_ROOT} /src/google/protobuf/reflection_ops.cc
146
+ ${PROTOBUF_ROOT} /src/google/protobuf/repeated_field.cc
147
+ ${PROTOBUF_ROOT} /src/google/protobuf/service.cc
148
+ ${ATOMICOPS_INTERNALS}
149
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/common.cc
150
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/once.cc
151
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/stringprintf.cc
152
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/structurally_valid.cc
153
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/strutil.cc
154
+ ${PROTOBUF_ROOT} /src/google/protobuf/stubs/substitute.cc
155
+ ${PROTOBUF_ROOT} /src/google/protobuf/text_format.cc
156
+ ${PROTOBUF_ROOT} /src/google/protobuf/unknown_field_set.cc
157
+ ${PROTOBUF_ROOT} /src/google/protobuf/wire_format.cc
158
+ ${PROTOBUF_ROOT} /src/google/protobuf/wire_format_lite.cc
159
+ #${PROTOBUF_ROOT}/src/google/protobuf/stubs/hash.cc
160
+ )
161
+
162
+ if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR CV_ICC ))
163
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
164
+ endif ()
165
+
166
+ add_library (libprotobuf STATIC ${PROTOBUF_SRCS} )
167
+ include_directories (${PROTOBUF_ROOT} /src ${CMAKE_CURRENT_BINARY_DIR} )
168
+
169
+ set_target_properties (libprotobuf
170
+ PROPERTIES
171
+ OUTPUT_NAME libprotobuf
172
+ DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX} "
173
+ ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
174
+ )
175
+
176
+ if (ENABLE_SOLUTION_FOLDERS )
177
+ set_target_properties (libprotobuf PROPERTIES FOLDER "3rdparty" )
178
+ endif ()
179
+
180
+ if (NOT BUILD_SHARED_LIBS )
181
+ ocv_install_target (libprotobuf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev )
182
+ endif ()
0 commit comments