@@ -81,7 +81,7 @@ find_package(GTest)
8181set (CMAKE_MACOSX_RPATH ON )
8282
8383# Set standard version for compiler.
84- if (MSVC )
84+ if (MSVC AND MSVC_TOOLSET_VERSION LESS 143 )
8585 # https://developercommunity.visualstudio.com/t/older-winsdk-headers-are-incompatible-with-zcprepr/1593479
8686 set (CMAKE_C_STANDARD 99)
8787else ()
@@ -94,6 +94,35 @@ set(CMAKE_CXX_EXTENSIONS OFF)
9494message (STATUS "Supported C compiler features = ${CMAKE_C_COMPILE_FEATURES} " )
9595message (STATUS "Supported C++ compiler features = ${CMAKE_CXX_COMPILE_FEATURES} " )
9696
97+ # Enable some warnings if we know the compiler.
98+ if (MSVC )
99+ add_compile_options (/W4 /analyze)
100+ add_compile_options (/wd4100) # unreferenced formal parameter
101+ add_compile_options (/wd4267) # narrowing conversion
102+ add_compile_options (/wd4244) # narrowing conversion
103+ add_compile_options (/wd4127) # conditional expression is constant
104+ add_compile_options (/wd4995) # #pragma deprecated
105+ add_compile_options (/wd4018) # signed/unsigned compare
106+ add_compile_options (/wd4310) # cast truncates constant value
107+ add_compile_options (/wd4389) # signed/unsigned compare
108+ add_compile_options (/wd4245) # signed/unsigned assign/return/function call
109+ add_compile_options (/wd4200) # nonstandard extension used: zero-sized array in struct/union
110+ add_compile_options (/wd4702) # unreachable code
111+ add_compile_options (/wd6340) # unsigned int passed to signed parameter
112+ add_compile_options (/wd6326) # potential comparison of a constant with another constant
113+
114+ # TODO(iphydf): Look into these
115+ add_compile_options (/wd4996) # use WSAAddressToStringW() instead of WSAAddressToStringA()
116+ add_compile_options (/wd6255) # don't use alloca
117+ add_compile_options (/wd6385) # reading invalid data
118+ add_compile_options (/wd6001) # using uninitialized memory
119+ add_compile_options (/wd6101) # returning uninitialized memory
120+ add_compile_options (/wd6386) # buffer overrun
121+ add_compile_options (/wd6011) # NULL dereference
122+ add_compile_options (/wd6031) # sscanf return value ignored
123+ add_compile_options (/wd6387) # passing NULL to fwrite
124+ endif ()
125+
97126set (MIN_LOGGER_LEVEL "" CACHE STRING "Logging level to use (TRACE, DEBUG, INFO, WARNING, ERROR)" )
98127if (MIN_LOGGER_LEVEL)
99128 if (("${MIN_LOGGER_LEVEL} " STREQUAL "TRACE" ) OR
@@ -307,10 +336,14 @@ set(toxcore_SOURCES
307336 toxcore/tox_unpack.h
308337 toxcore/util.c
309338 toxcore/util.h)
310- set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES} )
311- set (toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS} )
312- set (toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS} )
313- set (toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER} )
339+ if (TARGET unofficial-sodium::sodium)
340+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} unofficial-sodium::sodium)
341+ else ()
342+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${LIBSODIUM_LIBRARIES} )
343+ set (toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${LIBSODIUM_LIBRARY_DIRS} )
344+ set (toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${LIBSODIUM_INCLUDE_DIRS} )
345+ set (toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${LIBSODIUM_CFLAGS_OTHER} )
346+ endif ()
314347set (toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} libsodium)
315348set (toxcore_API_HEADERS
316349 ${toxcore_SOURCE_DIR} /toxcore/tox.h^tox
@@ -346,10 +379,14 @@ if(BUILD_TOXAV)
346379 set (toxcore_API_HEADERS ${toxcore_API_HEADERS}
347380 ${toxcore_SOURCE_DIR} /toxav/toxav.h^toxav)
348381
349- set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES} )
350- set (toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS} )
351- set (toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS} )
352- set (toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER} )
382+ if (MSVC )
383+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PkgConfig::OPUS PkgConfig::VPX)
384+ else ()
385+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${OPUS_LIBRARIES} ${VPX_LIBRARIES} )
386+ set (toxcore_LINK_DIRECTORIES ${toxcore_LINK_DIRECTORIES} ${OPUS_LIBRARY_DIRS} ${VPX_LIBRARY_DIRS} )
387+ set (toxcore_INCLUDE_DIRECTORIES ${toxcore_INCLUDE_DIRECTORIES} ${OPUS_INCLUDE_DIRS} ${VPX_INCLUDE_DIRS} )
388+ set (toxcore_COMPILE_OPTIONS ${toxcore_COMPILE_OPTIONS} ${OPUS_CFLAGS_OTHER} ${VPX_CFLAGS_OTHER} )
389+ endif ()
353390 set (toxcore_PKGCONFIG_REQUIRES ${toxcore_PKGCONFIG_REQUIRES} opus vpx)
354391endif ()
355392
@@ -380,7 +417,6 @@ if(CMAKE_THREAD_LIBS_INIT)
380417 set (toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} ${CMAKE_THREAD_LIBS_INIT} )
381418endif ()
382419
383-
384420if (NSL_LIBRARIES)
385421 set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ${NSL_LIBRARIES} )
386422 set (toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lnsl)
@@ -396,9 +432,13 @@ if(SOCKET_LIBRARIES)
396432 set (toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lsocket)
397433endif ()
398434
435+ if (TARGET PThreads4W::PThreads4W)
436+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} PThreads4W::PThreads4W)
437+ elseif (TARGET Threads::Threads)
438+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} Threads::Threads)
439+ endif ()
399440if (WIN32 )
400- set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} ws2_32 iphlpapi)
401- set (toxcore_PKGCONFIG_LIBS ${toxcore_PKGCONFIG_LIBS} -lws2_32 -liphlpapi)
441+ set (toxcore_LINK_LIBRARIES ${toxcore_LINK_LIBRARIES} iphlpapi wsock32 ws2_32)
402442endif ()
403443
404444################################################################################
@@ -496,6 +536,14 @@ if(DHT_BOOTSTRAP)
496536 target_link_libraries (DHT_bootstrap PRIVATE toxcore_shared)
497537 endif ()
498538 target_link_libraries (DHT_bootstrap PRIVATE misc_tools)
539+ if (TARGET unofficial-sodium::sodium)
540+ target_link_libraries (DHT_bootstrap PRIVATE unofficial-sodium::sodium)
541+ endif ()
542+ if (TARGET PThreads4W::PThreads4W)
543+ target_link_libraries (DHT_bootstrap PRIVATE PThreads4W::PThreads4W)
544+ elseif (TARGET Threads::Threads)
545+ target_link_libraries (DHT_bootstrap PRIVATE Threads::Threads)
546+ endif ()
499547 install (TARGETS DHT_bootstrap RUNTIME DESTINATION bin)
500548endif ()
501549
0 commit comments