aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-08 21:34:45 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-09 13:56:49 +0200
commitdedfce3ccf6a5606a378e1c7a1bd934fedeb6955 (patch)
treec162238cfdf739936c109647f75d5afdb714b784
parentbe1a8aaf3074afee28d3c7ee34acd5aabe0f8634 (diff)
downloadtcp-dedfce3ccf6a5606a378e1c7a1bd934fedeb6955.tar.gz
Update CMakeLists.txt
-rw-r--r--CMakeLists.txt77
1 files changed, 48 insertions, 29 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eaaf6b0..62ad616 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,29 +1,48 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
-PROJECT(FileSender)
-
-INCLUDE(CheckIncludeFiles)
-CHECK_INCLUDE_FILES(sys/sendfile.h HAVE_SYS_SENDFILE_H)
-
-IF(HAVE_SYS_SENDFILE_H)
- ADD_COMPILE_DEFINITIONS(HAVE_SYS_SENDFILE_H)
-ENDIF(HAVE_SYS_SENDFILE_H)
-
-INCLUDE(CheckFunctionExists)
-CHECK_FUNCTION_EXISTS(sendfile HAVE_SENDFILE)
-IF(HAVE_SENDFILE)
- ADD_COMPILE_DEFINITIONS(HAVE_SENDFILE)
-ENDIF(HAVE_SENDFILE)
-
-CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
-IF(NOT HAVE_SOCKET)
- CHECK_LIBRARY_EXISTS(socket socket "" HAVE_SOCKET)
-ENDIF(NOT HAVE_SOCKET)
-
-INCLUDE(CheckStructHasMember)
-CHECK_STRUCT_HAS_MEMBER("struct sf_hdtr" hdr_cnt sys/socket.h HAVE_STRUCT_SF_HDTR_HDR_CNT)
-IF(HAVE_STRUCT_SF_HDTR_HDR_CNT)
- ADD_COMPILE_DEFINITIONS(HAVE_STRUCT_SF_HDTR_HDR_CNT)
-ENDIF(HAVE_STRUCT_SF_HDTR_HDR_CNT)
-
-ADD_EXECUTABLE(server server.c utils.c utils.h)
-ADD_EXECUTABLE(client client.c utils.c utils.h)
+cmake_minimum_required(VERSION 3.1)
+cmake_policy(SET CMP0054 NEW)
+
+project(FileSender)
+
+include(CheckFunctionExists)
+include(CheckIncludeFiles)
+include(CheckLibraryExists)
+include(CheckStructHasMember)
+
+macro(CMAKE_SEARCH_LIBS v_func v_lib func)
+ check_function_exists(${func} ${v_func})
+ if(NOT ${v_func})
+ foreach(lib ${ARGN})
+ check_library_exists(${lib} ${func} "" HAVE_${func}_IN_${lib})
+ if(HAVE_${func}_IN_${lib})
+ set(${v_func} TRUE)
+ set(${v_lib} "${lib}" CACHE INTERNAL "Library providing ${func}")
+ break()
+ endif()
+ endforeach()
+ endif()
+endmacro()
+
+
+check_include_files(sys/sendfile.h HAVE_SYS_SENDFILE_H)
+if(HAVE_SYS_SENDFILE_H)
+ add_compile_definitions(HAVE_SYS_SENDFILE_H)
+endif()
+
+cmake_search_libs(HAVE_SENDFILE SENDFILE_LIB sendfile sendfile)
+cmake_search_libs(HAVE_SOCKET SOCKET_LIB socket socket)
+
+if(HAVE_SENDFILE)
+ add_compile_definitions(HAVE_SENDFILE)
+endif()
+
+check_struct_has_member("struct sf_hdtr" hdr_cnt sys/socket.h HAVE_STRUCT_SF_HDTR_HDR_CNT)
+if(HAVE_STRUCT_SF_HDTR_HDR_CNT)
+ add_compile_definitions(HAVE_STRUCT_SF_HDTR_HDR_CNT)
+endif()
+
+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})
+