blob: c08467d134284a34129f6118e971960721bb5189 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
cmake_minimum_required(VERSION 3.1)
project(FileSender)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckStructHasMember)
macro(CX_SEARCH_LIBS func)
string(TOUPPER ${func} _FUNC)
check_function_exists(${func} HAVE_${_FUNC})
if(NOT HAVE_${_FUNC})
foreach(lib ${ARGN})
unset(HAVE_${_FUNC} CACHE)
check_library_exists(${lib} ${func} "" HAVE_${_FUNC})
if(HAVE_${_FUNC})
set("${_FUNC}_LIB" "${lib}" CACHE INTERNAL "Library providing `${func}'")
break()
endif()
endforeach()
endif()
if(HAVE_${_FUNC})
add_compile_definitions("HAVE_${_FUNC}")
endif()
endmacro()
macro(CX_CHECK_HEADERS)
foreach(h ${ARGN})
string(TOUPPER ${h} _HDR)
string(REGEX REPLACE "[/.-]" "_" _HDR ${_HDR})
check_include_files(${h} HAVE_${_HDR})
if(HAVE_${_HDR})
add_compile_definitions("HAVE_${_HDR}")
endif()
endforeach()
endmacro()
macro(CX_CHECK_MEMBERS _members)
foreach(s ${_members})
string(STRIP "${s}" s)
string(REGEX REPLACE "[ \t]+" " " s ${s})
string(REGEX REPLACE "([^.]+)\.([^.]+)$" "\\1" struct ${s})
string(REGEX REPLACE "([^.]+)\.([^.]+)$" "\\2" field ${s})
string(REGEX REPLACE "[ .]" "_" M ${s})
string(TOUPPER "HAVE_${M}" HAVE)
check_struct_has_member("${struct}" "${field}" "${ARGN}" ${HAVE})
if(${HAVE})
add_compile_definitions(${HAVE})
endif()
endforeach()
endmacro()
cx_check_headers(fcntl.h netinet/in.h stddef.h stdlib.h string.h sys/socket.h unistd.h sys/sendfile.h)
cx_search_libs(sendfile sendfile)
cx_search_libs(socket socket)
cx_check_members("struct sf_hdtr.hdr_cnt" sys/socket.h)
add_executable(server server.c utils.c utils.h)
target_link_libraries(server ${SOCKET_LIB})
add_executable(client client.c utils.c utils.h)
target_link_libraries(client ${SOCKET_LIB} ${SENDFILE_LIB})
|