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})