- 准备编译环境为wsl
- 编写cmake文件
源码根下CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(unpv13e-master)
include_directories(./key)
#添库文件
add_subdirectory(./lib)
#各模块文件 本文使用intro模块举例,自己使用时将需要运行的模块逐一添加
add_subdirectory(./intro)
lib库下文件CMakeLists.txt 注意这里我排除了wrappthread.c
set(source
connect_nonb.c connect_timeo.c daemon_inetd.c daemon_init.c dg_cli.c dg_echo.c error.c get_ifi_info.c gf_time.c
host_serv.c family_to_level.c mcast_leave.c mcast_join.c mcast_get_if.c mcast_get_loop.c mcast_get_ttl.c
mcast_set_if.c mcast_set_loop.c mcast_set_ttl.c my_addrs.c read_fd.c readline.c readn.c readable_timeo.c rtt.c
signal.c signal_intr.c sock_bind_wild.c sock_cmp_addr.c sock_cmp_port.c sock_ntop.c sock_ntop_host.c
sock_get_port.c sock_set_addr.c sock_set_port.c sock_set_wild.c sockfd_to_family.c str_cli.c str_echo.c
tcp_connect.c tcp_listen.c tv_sub.c udp_client.c udp_connect.c udp_server.c wraplib.c wrapsock.c wrapstdio.c
wrapunix.c write_fd.c writen.c writable_timeo.c
)
add_library(libunp SHARED ${source})
各模块下的 这里使用./intro模块举例
#链接库文件
link_libraries(libunp)
#源文件
aux_source_directory(. source)
message(${source})
foreach(SUBDIR ${source})
STRING(REGEX REPLACE ".+/(.+)\\..*" "\\1" FILE_NAME ${SUBDIR})
message(${FILE_NAME})
add_executable(${FILE_NAME} ${SUBDIR})
endforeach()