1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Do not build protobuf without dnn (#10689)

* Do not build protobuf if dnn is disabled

* Added BUILD_LIST cmake option to the cache

* Moved protobuf to the top level

* Fixed static build

* Fixed world build

* fixup! Fixed world build
This commit is contained in:
Maksim Shabunin
2018-02-01 16:30:23 +03:00
committed by Vadim Pisarevsky
parent 36222c9eed
commit e56d6054aa
8 changed files with 113 additions and 67 deletions
+11 -25
View File
@@ -2,12 +2,7 @@ if(WINRT)
ocv_module_disable(dnn)
endif()
if(DEFINED BUILD_opencv_dnn AND NOT BUILD_opencv_dnn)
return()
endif()
include(${OpenCV_SOURCE_DIR}/cmake/OpenCVFindLibProtobuf.cmake)
if(NOT Protobuf_FOUND)
if(NOT HAVE_PROTOBUF)
ocv_module_disable(opencv_dnn)
endif()
@@ -21,8 +16,6 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses -Wmaybe-uninit
)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4701 /wd4100)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ocl4dnn/include ${OPENCL_INCLUDE_DIRS})
if(MSVC)
add_definitions( -D_CRT_SECURE_NO_WARNINGS=1 )
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146
@@ -45,8 +38,9 @@ if(ANDROID)
add_definitions(-DDISABLE_POSIX_MEMALIGN -DTH_DISABLE_HEAP_TRACKING)
endif()
#supress warnings in autogenerated caffe.pb.* files
add_definitions(-DHAVE_PROTOBUF=1)
#supress warnings in autogenerated caffe.pb.* files
ocv_warnings_disable(CMAKE_CXX_FLAGS
-Wunused-parameter -Wundef -Wignored-qualifiers -Wno-enum-compare
-Wdeprecated-declarations
@@ -59,26 +53,18 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS
)
if(PROTOBUF_UPDATE_FILES)
file(GLOB proto_files ${CMAKE_CURRENT_SOURCE_DIR}/src/tensorflow/*.proto)
list(APPEND proto_files ${CMAKE_CURRENT_SOURCE_DIR}/src/caffe/opencv-caffe.proto)
file(GLOB proto_files "${CMAKE_CURRENT_SOURCE_DIR}/src/tensorflow/*.proto" "${CMAKE_CURRENT_SOURCE_DIR}/src/caffe/opencv-caffe.proto")
set(PROTOBUF_GENERATE_CPP_APPEND_PATH ON) # required for tensorflow
PROTOBUF_GENERATE_CPP(Protobuf_HDRS Protobuf_SRCS ${proto_files})
protobuf_generate_cpp(fw_srcs fw_hdrs ${proto_files})
else()
file(GLOB fw_srcs ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.cc)
file(GLOB fw_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.h)
list(APPEND fw_srcs ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/opencv-caffe.pb.cc)
list(APPEND fw_hdrs ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/opencv-caffe.pb.h)
list(APPEND Protobuf_SRCS ${fw_srcs})
list(APPEND Protobuf_HDRS ${fw_hdrs})
list(APPEND Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe)
list(APPEND Protobuf_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow)
file(GLOB fw_srcs "${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.cc" "${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/opencv-caffe.pb.cc")
file(GLOB fw_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/misc/tensorflow/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/misc/caffe/opencv-caffe.pb.h")
set(fw_inc "misc/caffe" "misc/tensorflow")
endif()
ocv_source_group("Src\\protobuf" FILES ${Protobuf_SRCS} ${Protobuf_HDRS})
ocv_module_include_directories(include ${Protobuf_INCLUDE_DIRS})
ocv_glob_module_sources(${Protobuf_SRCS} ${Protobuf_HDRS} ${CBLAS_H_PROXY_PATH})
ocv_create_module(${Protobuf_LIBRARIES} ${LAPACK_LIBRARIES})
ocv_module_include_directories(${fw_inc} src/ocl4dnn/include ${OPENCL_INCLUDE_DIRS})
ocv_glob_module_sources(SOURCES ${fw_srcs})
ocv_create_module(libprotobuf ${LAPACK_LIBRARIES})
ocv_add_samples()
ocv_add_accuracy_tests()
ocv_add_perf_tests()
+4
View File
@@ -54,7 +54,11 @@ void shrinkCaffeModel(const String& src, const String& dst, const std::vector<St
blob->set_raw_data_type(caffe::FLOAT16);
}
}
#if GOOGLE_PROTOBUF_VERSION < 3005000
size_t msgSize = saturate_cast<size_t>(net.ByteSize());
#else
size_t msgSize = net.ByteSizeLong();
#endif
std::vector<uint8_t> output(msgSize);
net.SerializeWithCachedSizesToArray(&output[0]);
+5 -5
View File
@@ -38,20 +38,20 @@ endif()
ocv_add_module(world opencv_core)
set(headers_list "HEADERS")
set(sources_list "SOURCES")
set(headers_list)
set(sources_list)
set(link_deps "")
foreach(m ${OPENCV_MODULE_${the_module}_DEPS} opencv_world)
if(OPENCV_MODULE_${m}_IS_PART_OF_WORLD)
set(headers_list "${headers_list};${OPENCV_MODULE_${m}_HEADERS}")
set(sources_list "${sources_list};${OPENCV_MODULE_${m}_SOURCES}")
list(APPEND headers_list ${OPENCV_MODULE_${m}_HEADERS})
list(APPEND sources_list ${OPENCV_MODULE_${m}_SOURCES})
endif()
if(NOT " ${OPENCV_MODULE_${m}_LINK_DEPS}" STREQUAL " ")
list(APPEND link_deps ${OPENCV_MODULE_${m}_LINK_DEPS})
endif()
endforeach()
ocv_glob_module_sources(${headers_list} ${sources_list})
ocv_glob_module_sources(HEADERS ${headers_list} SOURCES ${sources_list})
ocv_module_include_directories()