Skip to content

Commit be92325

Browse files
Copilotithewei
andauthored
Improve build system: --disable-shared support, consistent library naming, conditional examples (#808)
* Initial plan * Improve build system: add --disable-shared support, fix library naming, conditional examples 1. Add --disable-shared and --disable-static options to configure/makefile 2. Make CMake static library output name consistent with Makefile (libhv.a) 3. Make Makefile examples target conditional based on module settings 4. Add multi-thread examples to CMakeLists.txt Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com> * Fix config.mk self-referential comment and Windows MSVC static lib naming conflict 1. Remove self-referential comment from config.mk (comment was for config.ini) 2. Guard OUTPUT_NAME hv on static target to avoid .lib conflict on Windows when both BUILD_SHARED and BUILD_STATIC are enabled Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
1 parent 207a467 commit be92325

6 files changed

Lines changed: 94 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ if(BUILD_STATIC)
267267
target_include_directories(hv_static PRIVATE ${LIBHV_SRCDIRS}
268268
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
269269
target_link_libraries(hv_static ${LIBS})
270+
if(NOT (WIN32 AND BUILD_SHARED))
271+
set_target_properties(hv_static PROPERTIES OUTPUT_NAME hv)
272+
endif()
270273
install(TARGETS hv_static
271274
EXPORT libhvConfig
272275
ARCHIVE DESTINATION lib)

Makefile

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ ifeq ($(WITH_KCP), yes)
88
CORE_SRCDIRS += event/kcp
99
endif
1010

11+
BUILD_SHARED ?= yes
12+
BUILD_STATIC ?= yes
13+
1114
LIBHV_SRCDIRS = $(CORE_SRCDIRS) util
1215
LIBHV_HEADERS = hv.h hconfig.h hexport.h
1316
LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)
@@ -52,8 +55,8 @@ default: all
5255
all: libhv examples
5356
@echo "make all done, please enjoy libhv."
5457

55-
examples: hmain_test htimer_test hloop_test pipe_test \
56-
nc nmap tinyhttpd tinyproxyd httpd curl wget wrk consul \
58+
EXAMPLES = hmain_test htimer_test hloop_test pipe_test \
59+
nc tinyhttpd tinyproxyd \
5760
tcp_client_test \
5861
tcp_echo_server \
5962
tcp_chat_server \
@@ -64,13 +67,29 @@ examples: hmain_test htimer_test hloop_test pipe_test \
6467
multi-acceptor-processes \
6568
multi-acceptor-threads \
6669
one-acceptor-multi-workers \
67-
http_server_test http_client_test \
68-
websocket_server_test \
69-
websocket_client_test \
70-
mqtt_sub \
71-
mqtt_pub \
72-
mqtt_client_test \
7370
jsonrpc
71+
72+
ifeq ($(WITH_EVPP), yes)
73+
EXAMPLES += nmap
74+
ifeq ($(WITH_HTTP), yes)
75+
EXAMPLES += wrk
76+
ifeq ($(WITH_HTTP_SERVER), yes)
77+
EXAMPLES += http_server_test websocket_server_test
78+
endif
79+
ifeq ($(WITH_HTTP_CLIENT), yes)
80+
EXAMPLES += curl wget consul http_client_test websocket_client_test
81+
ifeq ($(WITH_HTTP_SERVER), yes)
82+
EXAMPLES += httpd
83+
endif
84+
endif
85+
endif
86+
endif
87+
88+
ifeq ($(WITH_MQTT), yes)
89+
EXAMPLES += mqtt_sub mqtt_pub mqtt_client_test
90+
endif
91+
92+
examples: $(EXAMPLES)
7493
@echo "make examples done."
7594

7695
clean:
@@ -84,7 +103,17 @@ prepare:
84103

85104
libhv:
86105
$(MKDIR) lib
106+
ifeq ($(BUILD_SHARED), yes)
107+
ifeq ($(BUILD_STATIC), yes)
87108
$(MAKEF) TARGET=$@ TARGET_TYPE="SHARED|STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
109+
else
110+
$(MAKEF) TARGET=$@ TARGET_TYPE="SHARED" SRCDIRS="$(LIBHV_SRCDIRS)"
111+
endif
112+
else
113+
ifeq ($(BUILD_STATIC), yes)
114+
$(MAKEF) TARGET=$@ TARGET_TYPE="STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
115+
endif
116+
endif
88117
$(MKDIR) include/hv
89118
$(CP) $(LIBHV_HEADERS) include/hv
90119
@echo "make libhv done."

config.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PREFIX=/usr/local
55
INSTALL_INCDIR=$(PREFIX)/include/hv
66
INSTALL_LIBDIR=$(PREFIX)/lib
77

8+
BUILD_SHARED=yes
9+
BUILD_STATIC=yes
10+
811
# modules
912
# include icmp dns ftp smtp
1013
WITH_PROTOCOL=no

config.mk

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
21
PREFIX=/usr/local
32
INSTALL_INCDIR=$(PREFIX)/include/hv
43
INSTALL_LIBDIR=$(PREFIX)/lib
4+
5+
BUILD_SHARED=yes
6+
BUILD_STATIC=yes
7+
8+
# modules
9+
# include icmp dns ftp smtp
510
WITH_PROTOCOL=no
11+
612
WITH_EVPP=yes
713
WITH_HTTP=yes
814
WITH_HTTP_SERVER=yes
915
WITH_HTTP_CLIENT=yes
1016
WITH_MQTT=no
17+
18+
# features
19+
# base/hsocket.h: Unix Domain Socket
1120
ENABLE_UDS=no
21+
# base/RAII.cpp: Windows MiniDumpWriteDump
1222
ENABLE_WINDUMP=no
23+
# http/http_content.h: KeyValue,QueryParams,MultiPart
1324
USE_MULTIMAP=no
25+
26+
# dependencies
27+
# for http/client
1428
WITH_CURL=no
29+
# for http2
1530
WITH_NGHTTP2=no
31+
# for SSL/TLS
1632
WITH_OPENSSL=no
1733
WITH_GNUTLS=no
1834
WITH_MBEDTLS=no
35+
36+
# rudp
1937
WITH_KCP=no
20-
CONFIG_DATE=20220224

configure

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ options:
1717
--enable-FEATURE
1818
--disable-FEATURE
1919
20+
build:
21+
--enable-shared build shared library? (DEFAULT: $BUILD_SHARED)
22+
--disable-shared do not build shared library
23+
--enable-static build static library? (DEFAULT: $BUILD_STATIC)
24+
--disable-static do not build static library
25+
2026
modules:
2127
--with-protocol compile protocol module? (DEFAULT: $WITH_PROTOCOL)
2228
--with-evpp compile evpp module? (DEFAULT: $WITH_EVPP)
@@ -65,6 +71,20 @@ do
6571
KEY="INSTALL_LIBDIR"
6672
VAL=${opt:9}
6773
;;
74+
--enable-shared)
75+
KEY="BUILD_SHARED"
76+
;;
77+
--disable-shared)
78+
KEY="BUILD_SHARED"
79+
VAL=no
80+
;;
81+
--enable-static)
82+
KEY="BUILD_STATIC"
83+
;;
84+
--disable-static)
85+
KEY="BUILD_STATIC"
86+
VAL=no
87+
;;
6888
--with-*)
6989
KEY="WITH_${opt:7}"
7090
;;

examples/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ list(APPEND EXAMPLES
1212
udp_echo_server
1313
udp_proxy_server
1414
socks5_proxy_server
15+
multi-acceptor-processes
16+
multi-acceptor-threads
17+
one-acceptor-multi-workers
1518
jsonrpc_client
1619
jsonrpc_server
1720
)
@@ -57,6 +60,15 @@ target_link_libraries(udp_proxy_server ${HV_LIBRARIES})
5760
add_executable(socks5_proxy_server socks5_proxy_server.c)
5861
target_link_libraries(socks5_proxy_server ${HV_LIBRARIES})
5962

63+
add_executable(multi-acceptor-processes multi-thread/multi-acceptor-processes.c)
64+
target_link_libraries(multi-acceptor-processes ${HV_LIBRARIES})
65+
66+
add_executable(multi-acceptor-threads multi-thread/multi-acceptor-threads.c)
67+
target_link_libraries(multi-acceptor-threads ${HV_LIBRARIES})
68+
69+
add_executable(one-acceptor-multi-workers multi-thread/one-acceptor-multi-workers.c)
70+
target_link_libraries(one-acceptor-multi-workers ${HV_LIBRARIES})
71+
6072
add_executable(jsonrpc_client jsonrpc/jsonrpc_client.c jsonrpc/cJSON.c)
6173
target_compile_definitions(jsonrpc_client PRIVATE CJSON_HIDE_SYMBOLS)
6274
target_link_libraries(jsonrpc_client ${HV_LIBRARIES})

0 commit comments

Comments
 (0)