Skip to content

Commit ce692fe

Browse files
Copilotithewei
andcommitted
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>
1 parent 718e774 commit ce692fe

6 files changed

Lines changed: 94 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ 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+
set_target_properties(hv_static PROPERTIES OUTPUT_NAME hv)
270271
install(TARGETS hv_static
271272
EXPORT libhvConfig
272273
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: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1+
# Don't modify this file, you should modify config.mk or
2+
# run ./configure --with-MODULE --enable-FEATURE
13

24
PREFIX=/usr/local
35
INSTALL_INCDIR=$(PREFIX)/include/hv
46
INSTALL_LIBDIR=$(PREFIX)/lib
7+
8+
BUILD_SHARED=yes
9+
BUILD_STATIC=yes
10+
11+
# modules
12+
# include icmp dns ftp smtp
513
WITH_PROTOCOL=no
14+
615
WITH_EVPP=yes
716
WITH_HTTP=yes
817
WITH_HTTP_SERVER=yes
918
WITH_HTTP_CLIENT=yes
1019
WITH_MQTT=no
20+
21+
# features
22+
# base/hsocket.h: Unix Domain Socket
1123
ENABLE_UDS=no
24+
# base/RAII.cpp: Windows MiniDumpWriteDump
1225
ENABLE_WINDUMP=no
26+
# http/http_content.h: KeyValue,QueryParams,MultiPart
1327
USE_MULTIMAP=no
28+
29+
# dependencies
30+
# for http/client
1431
WITH_CURL=no
32+
# for http2
1533
WITH_NGHTTP2=no
34+
# for SSL/TLS
1635
WITH_OPENSSL=no
1736
WITH_GNUTLS=no
1837
WITH_MBEDTLS=no
38+
39+
# rudp
1940
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)