2
2
# the standard cmake script with version and python generation support
3
3
macro (custom_protobuf_find)
4
4
message (STATUS "Use custom protobuf build." )
5
- option (protobuf_BUILD_TESTS "" OFF )
6
- option (protobuf_BUILD_EXAMPLES "" OFF )
7
- option (protobuf_WITH_ZLIB "" OFF )
5
+ set (ABSL_BUILD_TESTING OFF )
6
+ set (ABSL_ENABLE_INSTALL OFF )
7
+ set (ABSL_PROPAGATE_CXX_STD ON )
8
+ set (protobuf_FORCE_FETCH_DEPENDENCIES ON )
9
+ set (protobuf_BUILD_TESTS OFF )
10
+ set (protobuf_BUILD_EXAMPLES OFF )
11
+ set (protobuf_WITH_ZLIB OFF )
12
+ set (__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE} )
13
+ set (CMAKE_POSITION_INDEPENDENT_CODE ON )
14
+ set (__caffe2_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} )
15
+ set (BUILD_SHARED_LIBS OFF )
8
16
if (${CAFFE2_LINK_LOCAL_PROTOBUF} )
9
17
# If we are going to link protobuf locally, we will need to turn off
10
18
# shared libs build for protobuf.
@@ -18,10 +26,7 @@ macro(custom_protobuf_find)
18
26
option (protobuf_MSVC_STATIC_RUNTIME "" ${CAFFE2_USE_MSVC_STATIC_RUNTIME} )
19
27
20
28
if (${CAFFE2_LINK_LOCAL_PROTOBUF} )
21
- set (__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS} )
22
29
set (__caffe2_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
23
- set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF )
24
- set (BUILD_SHARED_LIBS OFF )
25
30
if (${COMPILER_SUPPORTS_HIDDEN_VISIBILITY} )
26
31
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden" )
27
32
endif ()
@@ -30,9 +35,6 @@ macro(custom_protobuf_find)
30
35
endif ()
31
36
endif ()
32
37
33
- set (__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE} )
34
- set (CMAKE_POSITION_INDEPENDENT_CODE ON )
35
-
36
38
if (MSVC )
37
39
foreach (flag_var
38
40
CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL
@@ -52,35 +54,13 @@ macro(custom_protobuf_find)
52
54
endif (MSVC_Z7_OVERRIDE)
53
55
endif (MSVC )
54
56
55
- if (CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0" )
56
- message (WARNING "Ancient protobuf forces CMake compatibility" )
57
- set (CMAKE_POLICY_VERSION_MINIMUM 3.5)
58
- add_subdirectory (${CMAKE_CURRENT_LIST_DIR} /../third_party/protobuf/cmake)
59
- unset (CMAKE_POLICY_VERSION_MINIMUM)
60
- else ()
61
- add_subdirectory (${CMAKE_CURRENT_LIST_DIR} /../third_party/protobuf/cmake)
62
- endif ()
63
-
64
- set (CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE} )
57
+ add_subdirectory (${CMAKE_CURRENT_LIST_DIR} /../third_party/protobuf)
65
58
66
59
if (${CAFFE2_LINK_LOCAL_PROTOBUF} )
67
- set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${__caffe2_CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS} )
68
- set (BUILD_SHARED_LIBS ON )
69
60
set (CMAKE_CXX_FLAGS ${__caffe2_CMAKE_CXX_FLAGS} )
70
61
endif ()
71
-
72
- # Protobuf "namespaced" target is only added post protobuf 3.5.1. As a
73
- # result, for older versions, we will manually add alias.
74
- if (NOT TARGET protobuf::libprotobuf)
75
- add_library (protobuf::libprotobuf ALIAS libprotobuf)
76
- add_library (protobuf::libprotobuf-lite ALIAS libprotobuf-lite)
77
- # There is link error when cross compiling protoc on mobile:
78
- # https://github.com/protocolbuffers/protobuf/issues/2719
79
- # And protoc is very unlikely needed for mobile builds.
80
- if (NOT (ANDROID OR IOS))
81
- add_executable (protobuf::protoc ALIAS protoc)
82
- endif ()
83
- endif ()
62
+ set (BUILD_SHARED_LIBS ${__caffe2_BUILD_SHARED_LIBS} )
63
+ set (CMAKE_POSITION_INDEPENDENT_CODE ${__caffe2_CMAKE_POSITION_INDEPENDENT_CODE} )
84
64
endmacro ()
85
65
86
66
# Main entry for protobuf. If we are building on Android, iOS or we have hard
0 commit comments