@@ -15,12 +15,19 @@ if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
1515 if (MSVC )
1616 unset (PATCH_PROTOBUF_SOURCES_OPTIONS CACHE )
1717 set (PATCH_PROTOBUF_SOURCES_OPTIONS
18+ /wd4100
1819 /wd4244
1920 /wd4251
2021 /wd4267
2122 /wd4309
2223 /wd4668
24+ /wd4702
25+ /wd4715
26+ /wd4800
27+ /wd4090
2328 /wd4946
29+ /wd4996
30+ /wd5054
2431 /wd6001
2532 /wd6244
2633 /wd6246)
@@ -43,8 +50,15 @@ if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
4350 unset (PATCH_PROTOBUF_SOURCES_OPTIONS CACHE )
4451 include (CheckCXXCompilerFlag)
4552 check_append_cxx_compiler_flag(
46- PATCH_PROTOBUF_SOURCES_OPTIONS -Wno-type -limits
47- -Wno-deprecated-declarations -Wno-unused-parameter)
53+ PATCH_PROTOBUF_SOURCES_OPTIONS
54+ -Wno-type -limits
55+ -Wno-sign-compare
56+ -Wno-sign-conversion
57+ -Wno-shadow
58+ -Wno-uninitialized
59+ -Wno-conversion
60+ -Wno-deprecated-declarations
61+ -Wno-unused-parameter)
4862 endif ()
4963 set (PATCH_PROTOBUF_SOURCES_OPTIONS_SET TRUE )
5064 if (PATCH_PROTOBUF_SOURCES_OPTIONS)
@@ -56,41 +70,121 @@ if(NOT PATCH_PROTOBUF_SOURCES_OPTIONS_SET)
5670endif ()
5771
5872function (patch_protobuf_sources)
59- if (PATCH_PROTOBUF_SOURCES_OPTIONS)
60- foreach (PROTO_SRC ${ARGN} )
61- unset (PROTO_SRC_OPTIONS)
62- get_source_file_property (PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
63- if (PROTO_SRC_OPTIONS)
64- list (APPEND PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
73+ if (protobuf_lib_compile_features_cxx_std)
74+ if (MSVC )
75+ set (__additional_cxx_standard
76+ "/std:c++${protobuf_lib_compile_features_cxx_std} " )
77+ else ()
78+ set (__additional_cxx_standard
79+ "-std=c++${protobuf_lib_compile_features_cxx_std} " )
80+ endif ()
81+ endif ()
82+
83+ foreach (PROTO_SRC ${ARGN} )
84+ unset (PROTO_SRC_OPTIONS)
85+ set (__proto_src_options_changed FALSE )
86+ get_source_file_property (PROTO_SRC_OPTIONS ${PROTO_SRC} COMPILE_OPTIONS)
87+ if (PROTO_SRC_OPTIONS)
88+ set (__need_cxx_standard TRUE )
89+ if (NOT protobuf_lib_compile_features_cxx_std
90+ OR PROTO_SRC_OPTIONS MATCHES
91+ "(/std:|-std=)(c|gnu)\\ +\\ +${protobuf_lib_compile_features_cxx_std} "
92+ )
93+ set (__need_cxx_standard FALSE )
6594 else ()
66- set (PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
95+ if (MSVC )
96+ string (REGEX REPLACE "/std:c\\ +\\ +[0-9a-zA-Z_]+" "" PROTO_SRC_OPTIONS
97+ "${PROTO_SRC_OPTIONS} " )
98+ endif ()
99+ string (REGEX REPLACE "-std=(c|gnu)\\ +\\ +[0-9a-zA-Z_]+" ""
100+ PROTO_SRC_OPTIONS "${PROTO_SRC_OPTIONS} " )
101+ set (__need_cxx_standard TRUE )
102+ endif ()
103+
104+ foreach (TEST_OPTION ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
105+ if (NOT "${TEST_OPTION} " IN_LIST PROTO_SRC_OPTIONS)
106+ list (APPEND PROTO_SRC_OPTIONS "${TEST_OPTION} " )
107+ set (__proto_src_options_changed TRUE )
108+ endif ()
109+ endforeach ()
110+ if (__need_cxx_standard)
111+ list (APPEND PROTO_SRC_OPTIONS "${__additional_cxx_standard} " )
112+ set (__proto_src_options_changed TRUE )
113+ endif ()
114+ else ()
115+ set (PROTO_SRC_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
116+ if (__additional_cxx_standard)
117+ list (APPEND PROTO_SRC_OPTIONS "${__additional_cxx_standard} " )
67118 endif ()
119+ set (__proto_src_options_changed TRUE )
120+ endif ()
68121
122+ if (__proto_src_options_changed)
69123 set_source_files_properties (
70124 ${PROTO_SRC} PROPERTIES COMPILE_OPTIONS "${PROTO_SRC_OPTIONS} " )
71- endforeach ()
72- unset (PROTO_SRC)
73- unset (PROTO_SRC_OPTIONS)
74- endif ()
125+ endif ()
126+ endforeach ()
75127endfunction ()
76128
77129function (patch_protobuf_targets)
78- if (PATCH_PROTOBUF_SOURCES_OPTIONS )
130+ if (protobuf_lib_compile_features_cxx_std )
79131 foreach (PROTO_TARGET ${ARGN} )
80- unset (PROTO_TARGET_OPTIONS)
81- get_target_property (PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
82- if (PROTO_TARGET_OPTIONS)
83- list (APPEND PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
132+ set_target_properties (
133+ ${PROTO_TARGET} PROPERTIES CXX_STANDARD
134+ ${protobuf_lib_compile_features_cxx_std} )
135+ endforeach ()
136+
137+ if (MSVC )
138+ set (__additional_cxx_standard
139+ "/std:c++${protobuf_lib_compile_features_cxx_std} " )
140+ else ()
141+ set (__additional_cxx_standard
142+ "-std=c++${protobuf_lib_compile_features_cxx_std} " )
143+ endif ()
144+ endif ()
145+
146+ foreach (PROTO_TARGET ${ARGN} )
147+ set (__proto_target_options_changed FALSE )
148+ get_target_property (PROTO_TARGET_OPTIONS ${PROTO_TARGET} COMPILE_OPTIONS)
149+ if (PROTO_TARGET_OPTIONS)
150+ set (__need_cxx_standard TRUE )
151+ if (NOT protobuf_lib_compile_features_cxx_std
152+ OR PROTO_TARGET_OPTIONS MATCHES
153+ "(/std:|-std=)(c|gnu)\\ +\\ +${protobuf_lib_compile_features_cxx_std} "
154+ )
155+ set (__need_cxx_standard FALSE )
84156 else ()
85- set (PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
157+ if (MSVC )
158+ string (REGEX REPLACE "/std:c\\ +\\ +[0-9a-zA-Z_]+" ""
159+ PROTO_TARGET_OPTIONS "${PROTO_TARGET_OPTIONS} " )
160+ endif ()
161+ string (REGEX REPLACE "-std=(c|gnu)\\ +\\ +[0-9a-zA-Z_]+" ""
162+ PROTO_TARGET_OPTIONS "${PROTO_TARGET_OPTIONS} " )
163+ set (__need_cxx_standard TRUE )
86164 endif ()
87165
166+ foreach (TEST_OPTION ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
167+ if (NOT "${TEST_OPTION} " IN_LIST PROTO_TARGET_OPTIONS)
168+ list (APPEND PROTO_TARGET_OPTIONS "${TEST_OPTION} " )
169+ set (__proto_target_options_changed TRUE )
170+ endif ()
171+ endforeach ()
172+ if (__need_cxx_standard)
173+ list (APPEND PROTO_TARGET_OPTIONS "${__additional_cxx_standard} " )
174+ set (__proto_target_options_changed TRUE )
175+ endif ()
176+ else ()
177+ set (PROTO_TARGET_OPTIONS ${PATCH_PROTOBUF_SOURCES_OPTIONS} )
178+ if (__additional_cxx_standard)
179+ list (APPEND PROTO_TARGET_OPTIONS "${__additional_cxx_standard} " )
180+ endif ()
181+ set (__proto_target_options_changed TRUE )
182+ endif ()
183+ if (__proto_target_options_changed)
88184 set_target_properties (
89185 ${PROTO_TARGET} PROPERTIES COMPILE_OPTIONS "${PROTO_TARGET_OPTIONS} " )
90- endforeach ()
91- unset (PROTO_TARGET)
92- unset (PROTO_TARGET_OPTIONS)
93- endif ()
186+ endif ()
187+ endforeach ()
94188endfunction ()
95189
96190function (project_build_tools_get_imported_location OUTPUT_VAR_NAME TARGET_NAME)
0 commit comments