Skip to content

Commit

Permalink
Disable some warnings in tests/examples.
Browse files Browse the repository at this point in the history
Refactored a bunch of common stuff into a function to do this
  • Loading branch information
zpostfacto committed Sep 3, 2020
1 parent 3fe367e commit 1d11919
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 32 deletions.
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,51 @@ if(USE_CRYPTO STREQUAL "libsodium")
endif()
endif()


function(set_target_common_gns_properties TGT)
target_compile_definitions( ${TGT} PRIVATE GOOGLE_PROTOBUF_NO_RTTI )

if(CMAKE_SYSTEM_NAME MATCHES Linux)
target_compile_definitions(${TGT} PUBLIC POSIX LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
target_compile_definitions(${TGT} PUBLIC POSIX OSX)
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
#target_compile_definitions(${TGT} PUBLIC WIN32)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(NOT Protobuf_USE_STATIC_LIBS)
target_compile_definitions(${TGT} PRIVATE PROTOBUF_USE_DLLS)
endif()
target_compile_options(${TGT} PRIVATE
/EHs-c- # Disable C++ exceptions
/GR- # Disable RTTI

# Below are warnings we can't fix and don't want to see (mostly from protobuf, some from MSVC standard library)
/wd4146 # include/google/protobuf/wire_format_lite.h(863): warning C4146: unary minus operator applied to unsigned type, result still unsigned
/wd4530 # .../xlocale(319): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
/wd4244 # google/protobuf/wire_format_lite.h(935): warning C4244: 'argument': conversion from 'google::protobuf::uint64' to 'google::protobuf::uint32', possible loss of data
/wd4251 # 'google::protobuf::io::CodedOutputStream::default_serialization_deterministic_': struct 'std::atomic<bool>' needs to have dll-interface to be used by clients of class
/wd4267 # google/protobuf/has_bits.h(73): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
)
else()
target_compile_definitions(${TGT} PRIVATE
__STDC_FORMAT_MACROS=1
__USE_MINGW_ANSI_STDIO=0
)
target_compile_options(${TGT} PRIVATE -fno-stack-protector)
endif()
else()
message(FATAL_ERROR "Could not identify your target operating system")
endif()

if(NOT CMAKE_SYSTEM_NAME MATCHES Windows)
target_compile_options(${TGT} PRIVATE -fstack-protector-strong)
endif()

set_target_properties(${TGT} PROPERTIES
CXX_STANDARD 11
)
endfunction()

if(GAMENETWORKINGSOCKETS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ add_executable(
example_chat
example_chat.cpp)

set_target_common_gns_properties( example_chat )

# If building the example as a standalone project, need to find GameNetworkingSockets
if(${CMAKE_PROJECT_NAME} STREQUAL "gns_example")
find_package(GameNetworkingSockets CONFIG REQUIRED)
Expand Down
34 changes: 2 additions & 32 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ macro(gamenetworkingsockets_common GNS_TARGET)
target_sources(${GNS_TARGET} PRIVATE ${GNS_SRCS})
target_sources(${GNS_TARGET} PRIVATE ${GNS_PROTO_SRCS})

set_target_common_gns_properties( ${GNS_TARGET} )

target_include_directories(${GNS_TARGET} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/GameNetworkingSockets>"
Expand Down Expand Up @@ -213,7 +215,6 @@ macro(gamenetworkingsockets_common GNS_TARGET)
STEAMNETWORKINGSOCKETS_FOREXPORT
ENABLE_OPENSSLCONNECTION
CRYPTO_DISABLE_ENCRYPT_WITH_PASSWORD
GOOGLE_PROTOBUF_NO_RTTI
${GNS_CRYPTO_DEFINES}
)

Expand Down Expand Up @@ -253,42 +254,19 @@ macro(gamenetworkingsockets_common GNS_TARGET)
if(USE_STEAMWEBRTC AND NOT STEAMWEBRTC_USE_STATIC_LIBS)
target_link_libraries(${GNS_TARGET} PRIVATE dl)
endif()
target_compile_definitions(${GNS_TARGET} PUBLIC POSIX LINUX)
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
if(USE_STEAMWEBRTC AND NOT STEAMWEBRTC_USE_STATIC_LIBS)
target_link_libraries(${GNS_TARGET} PRIVATE dl)
endif()
target_compile_definitions(${GNS_TARGET} PUBLIC POSIX OSX)
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
target_compile_definitions(${GNS_TARGET} PUBLIC WIN32)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(NOT Protobuf_USE_STATIC_LIBS)
target_compile_definitions(${GNS_TARGET} PRIVATE
PROTOBUF_USE_DLLS)
endif()
get_target_property(TARGET_TYPE ${GNS_TARGET} TYPE)
target_compile_options(${GNS_TARGET} PRIVATE
/EHs-c- # Disable C++ exceptions
/GR- # Disable RTTI

# Below are warnings we can't fix and don't want to see (mostly from protobuf, some from MSVC standard library)
/wd4146 # include/google/protobuf/wire_format_lite.h(863): warning C4146: unary minus operator applied to unsigned type, result still unsigned
/wd4530 # .../xlocale(319): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
/wd4244 # google/protobuf/wire_format_lite.h(935): warning C4244: 'argument': conversion from 'google::protobuf::uint64' to 'google::protobuf::uint32', possible loss of data
/wd4251 # 'google::protobuf::io::CodedOutputStream::default_serialization_deterministic_': struct 'std::atomic<bool>' needs to have dll-interface to be used by clients of class
)
if(NOT TARGET_TYPE STREQUAL STATIC_LIBRARY)
target_compile_options(${GNS_TARGET} PRIVATE
/GL # Enable link-time code generation
)
set_target_properties(${GNS_TARGET} PROPERTIES LINK_FLAGS "/LTCG /SUBSYSTEM:WINDOWS")
endif()
else()
target_compile_definitions(${GNS_TARGET} PRIVATE
__STDC_FORMAT_MACROS=1
__USE_MINGW_ANSI_STDIO=0
)
target_compile_options(${GNS_TARGET} PRIVATE -fno-stack-protector)
endif()
target_link_libraries(${GNS_TARGET} PUBLIC ws2_32 crypt32)
if(USE_CRYPTO STREQUAL "BCrypt")
Expand All @@ -298,14 +276,6 @@ macro(gamenetworkingsockets_common GNS_TARGET)
message(FATAL_ERROR "Could not identify your target operating system")
endif()

if(NOT CMAKE_SYSTEM_NAME MATCHES Windows)
target_compile_options(${GNS_TARGET} PRIVATE -fstack-protector-strong)
endif()

set_target_properties(${GNS_TARGET} PROPERTIES
CXX_STANDARD 11
)

add_sanitizers(${GNS_TARGET})

endmacro()
Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ target_include_directories(test_crypto PRIVATE ../src ../src/public ../src/commo
target_link_libraries(test_crypto GameNetworkingSockets_s)
add_sanitizers(test_crypto)

set_target_common_gns_properties( test_connection )
set_target_common_gns_properties( test_p2p )
set_target_common_gns_properties( test_crypto )

file(COPY aesgcmtestvectors DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

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

0 comments on commit 1d11919

Please sign in to comment.