1
1
cmake_minimum_required (VERSION 3.11 FATAL_ERROR )
2
2
3
+ set (CMAKE_CXX_STANDARD 14 )
4
+
3
5
if (NeoOnnx_BUILD_SHARED )
4
6
add_library (${PROJECT_NAME} SHARED common.cpp )
5
7
else ()
@@ -142,62 +144,70 @@ endif()
142
144
143
145
configure_target (${PROJECT_NAME} )
144
146
147
+ # Have to first set the compile flags and then go through your subfolders.
148
+ if (MSVC )
149
+ target_compile_options (${PROJECT_NAME} PRIVATE /W2 )
150
+ if (NeoOnnx_BUILD_SHARED )
151
+ target_compile_options (${PROJECT_NAME} PRIVATE /MD$<$<CONFIG:Debug>:d> )
152
+ else ()
153
+ target_compile_options (${PROJECT_NAME} PRIVATE /MT$<$<CONFIG:Debug>:d> )
154
+ endif ()
155
+ # Because of the code generated by protobuf
156
+ set (CMAKE_CXX_FLAGS " /wd4946 /wd4251 /wd4141 /wd4068 /wd4530 /wd4715 /wd4018 /wd4267 /wd4267 " )
157
+ elseif (LINUX OR DARWIN )
158
+ target_compile_options (${PROJECT_NAME} PUBLIC -Wno-pedantic -Wno-array-bounds )
159
+ if (USE_FINE_OBJECTS )
160
+ target_compile_options (${PROJECT_NAME} PRIVATE -Wno-nonportable-include-path )
161
+ endif ()
162
+ add_compile_options ( -Wno-attributes )
163
+ endif ()
164
+
145
165
if (DEFINED ENV{Protobuf_ROOT} AND (IOS OR ANDROID ))
146
166
list (APPEND CMAKE_FIND_ROOT_PATH $ENV{Protobuf_ROOT} )
147
167
endif ()
148
168
169
+ #----------------------------------------------------------------------------------------------------------------------
170
+
171
+ set (CMAKE_FOLDER "protobuf" )
172
+
173
+ #--------------------------
149
174
if (${CMAKE_VERSION} VERSION_GREATER "3.16.0" )
150
175
set (CMAKE_UNITY_BUILD OFF )
151
176
endif ()
152
177
153
- set (protobuf_BUILD_TESTS OFF CACHE BOOL "" )
154
- set (protobuf_MSVC_STATIC_RUNTIME "${STATIC_NEOML} " CACHE BOOL "" )
155
- set (protobuf_WITH_ZLIB OFF CACHE BOOL "" )
156
- set (protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "" )
157
- set (protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" )
178
+ set (protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and files" )
179
+ set (protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests" )
180
+ set (protobuf_BUILD_LIBUPB OFF CACHE BOOL "Build libupb" )
181
+ set (protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "Build libprotoc and protoc compiler" )
182
+ set (protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries" )
183
+ set (protobuf_WITH_ZLIB OFF CACHE BOOL "Build with zlib support" )
184
+ set (protobuf_MSVC_STATIC_RUNTIME ON CACHE BOOL "Link static runtime libraries" )
185
+ set (ABSL_IDE_FOLDER "protobuf/absl" CACHE BOOL "The IDE sub-folder" )
158
186
159
187
if (USE_FINE_OBJECTS )
160
- add_subdirectory ("${FINE_ROOT} /ThirdParty/protobuf/cmake "
188
+ add_subdirectory ("${FINE_ROOT} /ThirdParty/protobuf"
161
189
"${CMAKE_BINARY_DIR} /protobuf" EXCLUDE_FROM_ALL )
162
190
else ()
163
191
include (FetchContent )
164
192
FetchContent_Declare (
165
193
protobuf
166
194
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
167
- GIT_TAG v3.11.4
195
+ GIT_TAG v28.0
168
196
)
169
197
170
198
FetchContent_GetProperties (protobuf )
171
199
172
200
if (NOT protobuf_POPULATED )
173
201
FetchContent_Populate (protobuf )
174
- add_subdirectory (${protobuf_SOURCE_DIR} /cmake ${protobuf_BINARY_DIR} EXCLUDE_FROM_ALL )
202
+ add_subdirectory (${protobuf_SOURCE_DIR} ${protobuf_BINARY_DIR} EXCLUDE_FROM_ALL )
175
203
endif ()
176
204
endif ()
177
205
178
- if (LINUX )
179
- target_compile_options (libprotobuf PRIVATE -Wno-stringop-overflow )
180
- target_compile_options (libprotobuf-lite PRIVATE -Wno-stringop-overflow )
181
- endif ()
182
-
183
- if (DARWIN )
184
- target_compile_options (libprotobuf PRIVATE -Wno-deprecated-declarations )
185
- target_compile_options (libprotobuf-lite PRIVATE -Wno-deprecated-declarations )
186
- endif ()
187
-
206
+ #--------------------------
188
207
if (${CMAKE_VERSION} VERSION_GREATER "3.16.0" )
189
208
set (CMAKE_UNITY_BUILD ${NeoML_UNITY_BUILD} )
190
209
endif ()
191
210
192
- if (USE_FINE_OBJECTS )
193
- target_link_libraries (${PROJECT_NAME} PRIVATE FineObjects )
194
-
195
- # Todo: properly link FineStlStaticPart if any problems occure
196
- if (MSVC )
197
- target_link_libraries (${PROJECT_NAME} PRIVATE "msvcprt$<$<CONFIG:Debug>:d>" )
198
- endif ()
199
- endif ()
200
-
201
211
set (PROTO_DIR ${CMAKE_CURRENT_BINARY_DIR} /cpp_proto/${CMAKE_CFG_INTDIR} )
202
212
set (PROTO_SRCS ${PROTO_DIR} /onnx.pb.cc )
203
213
set (PROTO_HDRS ${PROTO_DIR} /onnx.pb.h )
@@ -216,15 +226,15 @@ add_custom_command(
216
226
target_sources (${PROJECT_NAME} PRIVATE ${PROTO_HDRS} ${PROTO_SRCS} )
217
227
set_property (SOURCE ${PROTO_HDRS} ${PROTO_SRCS} PROPERTY SKIP_UNITY_BUILD_INCLUSION ON )
218
228
219
- if ( MSVC )
220
- target_compile_options ( ${PROJECT_NAME} PRIVATE /W2 )
221
- target_compile_options ( ${PROJECT_NAME} PRIVATE /MD$<$<CONFIG:Debug>:d> )
222
- # Because of the code generated by protobuf
223
- target_compile_options ( ${PROJECT_NAME} PRIVATE /wd4946 /wd4251 )
224
- elseif ( NOT WIN32 )
225
- set_property ( SOURCE ${PROTO_SRCS} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-pedantic -Wno-array-bounds " )
226
- if (USE_FINE_OBJECTS )
227
- target_compile_options (${PROJECT_NAME} PRIVATE -Wno-nonportable-include-path )
229
+ unset ( CMAKE_FOLDER )
230
+
231
+ # ----------------------------------------------------------------------------------------------------------------------
232
+
233
+ if ( USE_FINE_OBJECTS )
234
+ target_link_libraries ( ${PROJECT_NAME} PRIVATE FineObjects )
235
+ # TODO: properly link FineStlStaticPart if any problems occure
236
+ if (MSVC )
237
+ target_link_libraries (${PROJECT_NAME} PRIVATE "msvcprt$<$<CONFIG:Debug>:d>" )
228
238
endif ()
229
239
endif ()
230
240
@@ -261,12 +271,7 @@ if(NOT TARGET protobuf::libprotobuf)
261
271
message (FATAL_ERROR "Protobuf not found!" )
262
272
endif ()
263
273
264
- # Fix for a known protobuf Windows dll issue https://github.com/protocolbuffers/protobuf/issues/2502
265
- if ((Protobuf_LIBRARY MATCHES ".*dll" ) OR (Protobuf_LIBRARY MATCHES ".*DLL" ))
266
- target_compile_definitions (${PROJECT_NAME} PRIVATE PROTOBUF_USE_DLLS )
267
- endif ()
268
-
269
- target_link_libraries (${PROJECT_NAME} PRIVATE protobuf::libprotobuf PUBLIC NeoML )
274
+ target_link_libraries (${PROJECT_NAME} PRIVATE protobuf::libprotobuf ${protobuf_ABSL_USED_TARGETS} PUBLIC NeoML )
270
275
if (ANDROID )
271
276
target_link_libraries (${PROJECT_NAME} PRIVATE log )
272
277
endif ()
0 commit comments