From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/civetweb/cmake/FindWinSock.cmake | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/civetweb/cmake/FindWinSock.cmake (limited to 'src/civetweb/cmake/FindWinSock.cmake') diff --git a/src/civetweb/cmake/FindWinSock.cmake b/src/civetweb/cmake/FindWinSock.cmake new file mode 100644 index 000000000..0bf355dec --- /dev/null +++ b/src/civetweb/cmake/FindWinSock.cmake @@ -0,0 +1,102 @@ +#.rst: +# FindWinSock +# -------- +# +# Find the native realtime includes and library. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``WINSOCK::WINSOCK``, if +# WINSOCK has been found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following variables: +# +# :: +# +# WINSOCK_INCLUDE_DIRS - where to find winsock.h, etc. +# WINSOCK_LIBRARIES - List of libraries when using librt. +# WINSOCK_FOUND - True if realtime library found. +# +# Hints +# ^^^^^ +# +# A user may set ``WINSOCK_ROOT`` to a realtime installation root to tell this +# module where to look. + +macro(REMOVE_DUPLICATE_PATHS LIST_VAR) + set(WINSOCK_LIST "") + foreach(PATH IN LISTS ${LIST_VAR}) + get_filename_component(PATH "${PATH}" REALPATH) + list(APPEND WINSOCK_LIST "${PATH}") + endforeach(PATH) + set(${LIST_VAR} ${WINSOCK_LIST}) + list(REMOVE_DUPLICATES ${LIST_VAR}) +endmacro(REMOVE_DUPLICATE_PATHS) + +set(WINSOCK_INCLUDE_PATHS "${WINSOCK_ROOT}/include/") +if(MINGW) + execute_process( + COMMAND ${CMAKE_C_COMPILER} -xc -E -v - + RESULT_VARIABLE RESULT + INPUT_FILE nul + ERROR_VARIABLE ERR + OUTPUT_QUIET + ) + if (NOT RESULT) + string(FIND "${ERR}" "#include <...> search starts here:" START) + string(FIND "${ERR}" "End of search list." END) + if (NOT ${START} EQUAL -1 AND NOT ${END} EQUAL -1) + math(EXPR START "${START} + 36") + math(EXPR END "${END} - 1") + math(EXPR LENGTH "${END} - ${START}") + string(SUBSTRING "${ERR}" ${START} ${LENGTH} WINSOCK_INCLUDE_PATHS) + string(REPLACE "\n " ";" WINSOCK_INCLUDE_PATHS "${WINSOCK_INCLUDE_PATHS}") + list(REVERSE WINSOCK_INCLUDE_PATHS) + endif() + endif() +endif() +remove_duplicate_paths(WINSOCK_INCLUDE_PATHS) + +set(WINSOCK_LIBRARY_PATHS "${WINSOCK_ROOT}/lib/") +if(MINGW) + execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-search-dirs + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE OUT + ERROR_QUIET + ) + if (NOT RESULT) + string(REGEX MATCH "libraries: =([^\r\n]*)" OUT "${OUT}") + list(APPEND WINSOCK_LIBRARY_PATHS "${CMAKE_MATCH_1}") + endif() +endif() +if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64" AND ${CMAKE_SIZEOF_VOID_P} EQUAL 4) + list(APPEND WINSOCK_LIBRARY_PATHS "C:/Windows/SysWOW64") +endif() +list(APPEND WINSOCK_LIBRARY_PATHS "C:/Windows/System32") +remove_duplicate_paths(WINSOCK_LIBRARY_PATHS) + +find_path(WINSOCK_INCLUDE_DIRS + NAMES winsock2.h + PATHS ${WINSOCK_INCLUDE_PATHS} +) +find_library(WINSOCK_LIBRARIES ws2_32 + PATHS ${WINSOCK_LIBRARY_PATHS} + NO_DEFAULT_PATH +) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WinSock DEFAULT_MSG WINSOCK_LIBRARIES WINSOCK_INCLUDE_DIRS) +mark_as_advanced(WINSOCK_INCLUDE_DIRS WINSOCK_LIBRARIES) + +if(WINSOCK_FOUND) + if(NOT TARGET WINSOCK::WINSOCK) + add_library(WINSOCK::WINSOCK UNKNOWN IMPORTED) + set_target_properties(WINSOCK::WINSOCK PROPERTIES + IMPORTED_LOCATION "${WINSOCK_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${WINSOCK_INCLUDE_DIRS}") + endif() +endif() -- cgit v1.2.3