Skip to content

Commit 1d11919

Browse files
committed
Disable some warnings in tests/examples.
Refactored a bunch of common stuff into a function to do this
1 parent 3fe367e commit 1d11919

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,51 @@ if(USE_CRYPTO STREQUAL "libsodium")
142142
endif()
143143
endif()
144144

145+
146+
function(set_target_common_gns_properties TGT)
147+
target_compile_definitions( ${TGT} PRIVATE GOOGLE_PROTOBUF_NO_RTTI )
148+
149+
if(CMAKE_SYSTEM_NAME MATCHES Linux)
150+
target_compile_definitions(${TGT} PUBLIC POSIX LINUX)
151+
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
152+
target_compile_definitions(${TGT} PUBLIC POSIX OSX)
153+
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
154+
#target_compile_definitions(${TGT} PUBLIC WIN32)
155+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
156+
if(NOT Protobuf_USE_STATIC_LIBS)
157+
target_compile_definitions(${TGT} PRIVATE PROTOBUF_USE_DLLS)
158+
endif()
159+
target_compile_options(${TGT} PRIVATE
160+
/EHs-c- # Disable C++ exceptions
161+
/GR- # Disable RTTI
162+
163+
# Below are warnings we can't fix and don't want to see (mostly from protobuf, some from MSVC standard library)
164+
/wd4146 # include/google/protobuf/wire_format_lite.h(863): warning C4146: unary minus operator applied to unsigned type, result still unsigned
165+
/wd4530 # .../xlocale(319): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
166+
/wd4244 # google/protobuf/wire_format_lite.h(935): warning C4244: 'argument': conversion from 'google::protobuf::uint64' to 'google::protobuf::uint32', possible loss of data
167+
/wd4251 # 'google::protobuf::io::CodedOutputStream::default_serialization_deterministic_': struct 'std::atomic<bool>' needs to have dll-interface to be used by clients of class
168+
/wd4267 # google/protobuf/has_bits.h(73): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
169+
)
170+
else()
171+
target_compile_definitions(${TGT} PRIVATE
172+
__STDC_FORMAT_MACROS=1
173+
__USE_MINGW_ANSI_STDIO=0
174+
)
175+
target_compile_options(${TGT} PRIVATE -fno-stack-protector)
176+
endif()
177+
else()
178+
message(FATAL_ERROR "Could not identify your target operating system")
179+
endif()
180+
181+
if(NOT CMAKE_SYSTEM_NAME MATCHES Windows)
182+
target_compile_options(${TGT} PRIVATE -fstack-protector-strong)
183+
endif()
184+
185+
set_target_properties(${TGT} PROPERTIES
186+
CXX_STANDARD 11
187+
)
188+
endfunction()
189+
145190
if(GAMENETWORKINGSOCKETS_BUILD_EXAMPLES)
146191
add_subdirectory(examples)
147192
endif()

examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ add_executable(
3030
example_chat
3131
example_chat.cpp)
3232

33+
set_target_common_gns_properties( example_chat )
34+
3335
# If building the example as a standalone project, need to find GameNetworkingSockets
3436
if(${CMAKE_PROJECT_NAME} STREQUAL "gns_example")
3537
find_package(GameNetworkingSockets CONFIG REQUIRED)

src/CMakeLists.txt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ macro(gamenetworkingsockets_common GNS_TARGET)
152152
target_sources(${GNS_TARGET} PRIVATE ${GNS_SRCS})
153153
target_sources(${GNS_TARGET} PRIVATE ${GNS_PROTO_SRCS})
154154

155+
set_target_common_gns_properties( ${GNS_TARGET} )
156+
155157
target_include_directories(${GNS_TARGET} PUBLIC
156158
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
157159
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/GameNetworkingSockets>"
@@ -213,7 +215,6 @@ macro(gamenetworkingsockets_common GNS_TARGET)
213215
STEAMNETWORKINGSOCKETS_FOREXPORT
214216
ENABLE_OPENSSLCONNECTION
215217
CRYPTO_DISABLE_ENCRYPT_WITH_PASSWORD
216-
GOOGLE_PROTOBUF_NO_RTTI
217218
${GNS_CRYPTO_DEFINES}
218219
)
219220

@@ -253,42 +254,19 @@ macro(gamenetworkingsockets_common GNS_TARGET)
253254
if(USE_STEAMWEBRTC AND NOT STEAMWEBRTC_USE_STATIC_LIBS)
254255
target_link_libraries(${GNS_TARGET} PRIVATE dl)
255256
endif()
256-
target_compile_definitions(${GNS_TARGET} PUBLIC POSIX LINUX)
257257
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
258258
if(USE_STEAMWEBRTC AND NOT STEAMWEBRTC_USE_STATIC_LIBS)
259259
target_link_libraries(${GNS_TARGET} PRIVATE dl)
260260
endif()
261-
target_compile_definitions(${GNS_TARGET} PUBLIC POSIX OSX)
262261
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
263-
target_compile_definitions(${GNS_TARGET} PUBLIC WIN32)
264262
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
265-
if(NOT Protobuf_USE_STATIC_LIBS)
266-
target_compile_definitions(${GNS_TARGET} PRIVATE
267-
PROTOBUF_USE_DLLS)
268-
endif()
269263
get_target_property(TARGET_TYPE ${GNS_TARGET} TYPE)
270-
target_compile_options(${GNS_TARGET} PRIVATE
271-
/EHs-c- # Disable C++ exceptions
272-
/GR- # Disable RTTI
273-
274-
# Below are warnings we can't fix and don't want to see (mostly from protobuf, some from MSVC standard library)
275-
/wd4146 # include/google/protobuf/wire_format_lite.h(863): warning C4146: unary minus operator applied to unsigned type, result still unsigned
276-
/wd4530 # .../xlocale(319): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
277-
/wd4244 # google/protobuf/wire_format_lite.h(935): warning C4244: 'argument': conversion from 'google::protobuf::uint64' to 'google::protobuf::uint32', possible loss of data
278-
/wd4251 # 'google::protobuf::io::CodedOutputStream::default_serialization_deterministic_': struct 'std::atomic<bool>' needs to have dll-interface to be used by clients of class
279-
)
280264
if(NOT TARGET_TYPE STREQUAL STATIC_LIBRARY)
281265
target_compile_options(${GNS_TARGET} PRIVATE
282266
/GL # Enable link-time code generation
283267
)
284268
set_target_properties(${GNS_TARGET} PROPERTIES LINK_FLAGS "/LTCG /SUBSYSTEM:WINDOWS")
285269
endif()
286-
else()
287-
target_compile_definitions(${GNS_TARGET} PRIVATE
288-
__STDC_FORMAT_MACROS=1
289-
__USE_MINGW_ANSI_STDIO=0
290-
)
291-
target_compile_options(${GNS_TARGET} PRIVATE -fno-stack-protector)
292270
endif()
293271
target_link_libraries(${GNS_TARGET} PUBLIC ws2_32 crypt32)
294272
if(USE_CRYPTO STREQUAL "BCrypt")
@@ -298,14 +276,6 @@ macro(gamenetworkingsockets_common GNS_TARGET)
298276
message(FATAL_ERROR "Could not identify your target operating system")
299277
endif()
300278

301-
if(NOT CMAKE_SYSTEM_NAME MATCHES Windows)
302-
target_compile_options(${GNS_TARGET} PRIVATE -fstack-protector-strong)
303-
endif()
304-
305-
set_target_properties(${GNS_TARGET} PROPERTIES
306-
CXX_STANDARD 11
307-
)
308-
309279
add_sanitizers(${GNS_TARGET})
310280

311281
endmacro()

tests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ target_include_directories(test_crypto PRIVATE ../src ../src/public ../src/commo
3131
target_link_libraries(test_crypto GameNetworkingSockets_s)
3232
add_sanitizers(test_crypto)
3333

34+
set_target_common_gns_properties( test_connection )
35+
set_target_common_gns_properties( test_p2p )
36+
set_target_common_gns_properties( test_crypto )
37+
3438
file(COPY aesgcmtestvectors DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
3539

3640
# NOTE: This happens when we generate the projects, and really we'd like to actually

0 commit comments

Comments
 (0)