Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ if(BUILD_STATIC)
target_include_directories(hv_static PRIVATE ${LIBHV_SRCDIRS}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_link_libraries(hv_static ${LIBS})
set_target_properties(hv_static PROPERTIES OUTPUT_NAME hv)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows with MSVC, setting OUTPUT_NAME hv on the static target will cause a naming conflict when both BUILD_SHARED and BUILD_STATIC are enabled (the default). The shared library hv already produces an import library hv.lib, and now the static library hv_static will also produce hv.lib in the same output directory, causing one to overwrite the other.

A common solution is to also set ARCHIVE_OUTPUT_NAME to a different name (e.g., hv_static) on the static target only when BUILD_SHARED is also enabled, or alternatively to use the CMAKE_STATIC_LIBRARY_SUFFIX workaround. Another approach is to guard this property with a condition like if(NOT BUILD_SHARED OR NOT WIN32).

Copilot uses AI. Check for mistakes.
install(TARGETS hv_static
EXPORT libhvConfig
ARCHIVE DESTINATION lib)
Expand Down
45 changes: 37 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ifeq ($(WITH_KCP), yes)
CORE_SRCDIRS += event/kcp
endif

BUILD_SHARED ?= yes
BUILD_STATIC ?= yes

LIBHV_SRCDIRS = $(CORE_SRCDIRS) util
LIBHV_HEADERS = hv.h hconfig.h hexport.h
LIBHV_HEADERS += $(BASE_HEADERS) $(SSL_HEADERS) $(EVENT_HEADERS) $(UTIL_HEADERS)
Expand Down Expand Up @@ -52,8 +55,8 @@ default: all
all: libhv examples
@echo "make all done, please enjoy libhv."

examples: hmain_test htimer_test hloop_test pipe_test \
nc nmap tinyhttpd tinyproxyd httpd curl wget wrk consul \
EXAMPLES = hmain_test htimer_test hloop_test pipe_test \
nc tinyhttpd tinyproxyd \
tcp_client_test \
tcp_echo_server \
tcp_chat_server \
Expand All @@ -64,13 +67,29 @@ examples: hmain_test htimer_test hloop_test pipe_test \
multi-acceptor-processes \
multi-acceptor-threads \
one-acceptor-multi-workers \
http_server_test http_client_test \
websocket_server_test \
websocket_client_test \
mqtt_sub \
mqtt_pub \
mqtt_client_test \
jsonrpc

ifeq ($(WITH_EVPP), yes)
EXAMPLES += nmap
ifeq ($(WITH_HTTP), yes)
EXAMPLES += wrk
ifeq ($(WITH_HTTP_SERVER), yes)
EXAMPLES += http_server_test websocket_server_test
endif
ifeq ($(WITH_HTTP_CLIENT), yes)
EXAMPLES += curl wget consul http_client_test websocket_client_test
ifeq ($(WITH_HTTP_SERVER), yes)
EXAMPLES += httpd
endif
endif
endif
endif

ifeq ($(WITH_MQTT), yes)
EXAMPLES += mqtt_sub mqtt_pub mqtt_client_test
endif

examples: $(EXAMPLES)
@echo "make examples done."

clean:
Expand All @@ -84,7 +103,17 @@ prepare:

libhv:
$(MKDIR) lib
ifeq ($(BUILD_SHARED), yes)
ifeq ($(BUILD_STATIC), yes)
$(MAKEF) TARGET=$@ TARGET_TYPE="SHARED|STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
else
$(MAKEF) TARGET=$@ TARGET_TYPE="SHARED" SRCDIRS="$(LIBHV_SRCDIRS)"
endif
else
ifeq ($(BUILD_STATIC), yes)
$(MAKEF) TARGET=$@ TARGET_TYPE="STATIC" SRCDIRS="$(LIBHV_SRCDIRS)"
endif
endif
$(MKDIR) include/hv
$(CP) $(LIBHV_HEADERS) include/hv
@echo "make libhv done."
Expand Down
3 changes: 3 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ PREFIX=/usr/local
INSTALL_INCDIR=$(PREFIX)/include/hv
INSTALL_LIBDIR=$(PREFIX)/lib

BUILD_SHARED=yes
BUILD_STATIC=yes

# modules
# include icmp dns ftp smtp
WITH_PROTOCOL=no
Expand Down
22 changes: 21 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# Don't modify this file, you should modify config.mk or
# run ./configure --with-MODULE --enable-FEATURE
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Don't modify this file, you should modify config.mk" is self-referential when placed in config.mk itself. This comment was originally intended for config.ini (the template). In config.mk, the comment should either be removed or changed to something like "# This file is generated by ./configure. Edit config.ini or run ./configure to change settings."

Copilot uses AI. Check for mistakes.

PREFIX=/usr/local
INSTALL_INCDIR=$(PREFIX)/include/hv
INSTALL_LIBDIR=$(PREFIX)/lib

BUILD_SHARED=yes
BUILD_STATIC=yes

# modules
# include icmp dns ftp smtp
WITH_PROTOCOL=no

WITH_EVPP=yes
WITH_HTTP=yes
WITH_HTTP_SERVER=yes
WITH_HTTP_CLIENT=yes
WITH_MQTT=no

# features
# base/hsocket.h: Unix Domain Socket
ENABLE_UDS=no
# base/RAII.cpp: Windows MiniDumpWriteDump
ENABLE_WINDUMP=no
# http/http_content.h: KeyValue,QueryParams,MultiPart
USE_MULTIMAP=no

# dependencies
# for http/client
WITH_CURL=no
# for http2
WITH_NGHTTP2=no
# for SSL/TLS
WITH_OPENSSL=no
WITH_GNUTLS=no
WITH_MBEDTLS=no

# rudp
WITH_KCP=no
CONFIG_DATE=20220224
20 changes: 20 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ options:
--enable-FEATURE
--disable-FEATURE

build:
--enable-shared build shared library? (DEFAULT: $BUILD_SHARED)
--disable-shared do not build shared library
--enable-static build static library? (DEFAULT: $BUILD_STATIC)
--disable-static do not build static library

modules:
--with-protocol compile protocol module? (DEFAULT: $WITH_PROTOCOL)
--with-evpp compile evpp module? (DEFAULT: $WITH_EVPP)
Expand Down Expand Up @@ -65,6 +71,20 @@ do
KEY="INSTALL_LIBDIR"
VAL=${opt:9}
;;
--enable-shared)
KEY="BUILD_SHARED"
;;
--disable-shared)
KEY="BUILD_SHARED"
VAL=no
;;
--enable-static)
KEY="BUILD_STATIC"
;;
--disable-static)
KEY="BUILD_STATIC"
VAL=no
;;
--with-*)
KEY="WITH_${opt:7}"
;;
Expand Down
12 changes: 12 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ list(APPEND EXAMPLES
udp_echo_server
udp_proxy_server
socks5_proxy_server
multi-acceptor-processes
multi-acceptor-threads
one-acceptor-multi-workers
jsonrpc_client
jsonrpc_server
)
Expand Down Expand Up @@ -57,6 +60,15 @@ target_link_libraries(udp_proxy_server ${HV_LIBRARIES})
add_executable(socks5_proxy_server socks5_proxy_server.c)
target_link_libraries(socks5_proxy_server ${HV_LIBRARIES})

add_executable(multi-acceptor-processes multi-thread/multi-acceptor-processes.c)
target_link_libraries(multi-acceptor-processes ${HV_LIBRARIES})

add_executable(multi-acceptor-threads multi-thread/multi-acceptor-threads.c)
target_link_libraries(multi-acceptor-threads ${HV_LIBRARIES})

add_executable(one-acceptor-multi-workers multi-thread/one-acceptor-multi-workers.c)
target_link_libraries(one-acceptor-multi-workers ${HV_LIBRARIES})

add_executable(jsonrpc_client jsonrpc/jsonrpc_client.c jsonrpc/cJSON.c)
target_compile_definitions(jsonrpc_client PRIVATE CJSON_HIDE_SYMBOLS)
target_link_libraries(jsonrpc_client ${HV_LIBRARIES})
Expand Down
Loading