hewei.it 5 anos atrás
pai
commit
30f751e7d3
9 arquivos alterados com 40 adições e 43 exclusões
  1. 0 3
      .gitignore
  2. 5 3
      CMakeLists.txt
  3. 4 4
      Makefile
  4. 5 8
      README.md
  5. 15 13
      examples/CMakeLists.txt
  6. 2 2
      hconfig.h
  7. 2 2
      hexport.h
  8. 5 8
      readme_cn.md
  9. 2 0
      unittest/CMakeLists.txt

+ 0 - 3
.gitignore

@@ -58,6 +58,3 @@ build
 *.vcxproj.*
 Debug
 Release
-
-# other
-hconfig.h

+ 5 - 3
CMakeLists.txt

@@ -39,7 +39,9 @@ check_header("fcntl.h")
 check_header("pthread.h")
 
 # Checks for functions
-set(CMAKE_REQUIRED_LIBRARIES "pthread")
+if(NOT MSVC)
+    set(CMAKE_REQUIRED_LIBRARIES "pthread")
+endif()
 check_function("gettid" "unistd.h")
 check_function("strlcpy" "string.h")
 check_function("strlcat" "string.h")
@@ -154,7 +156,7 @@ if(BUILD_SHARED)
     target_compile_definitions(hv PRIVATE HV_EXPORTS)
     target_include_directories(hv PRIVATE ${LIBHV_SRCDIRS})
     target_link_libraries(hv ${LIBS})
-    install(TARGETS hv)
+    install(TARGETS hv LIBRARY DESTINATION lib)
     add_custom_target(libhv DEPENDS hv)
 endif()
 
@@ -162,7 +164,7 @@ if(BUILD_STATIC)
     add_library(hv_static STATIC ${LIBHV_SRCS})
     target_compile_definitions(hv_static PRIVATE HV_STATICLIB)
     target_include_directories(hv_static PRIVATE ${LIBHV_SRCDIRS})
-    install(TARGETS hv_static)
+    install(TARGETS hv_static ARCHIVE DESTINATION lib)
     add_custom_target(libhv_static DEPENDS hv_static)
 endif()
 

+ 4 - 4
Makefile

@@ -52,13 +52,13 @@ install:
 	$(CP) include/hv/* $(INSTALL_INCDIR)
 	$(CP) lib/libhv.a lib/libhv.so $(INSTALL_LIBDIR)
 
-test: prepare
+hmain_test: prepare
 	$(MAKEF) TARGET=$@ SRCDIRS=". base utils" SRCS="examples/hmain_test.cpp"
 
-timer: prepare
+htimer_test: prepare
 	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/htimer_test.c"
 
-loop: prepare
+hloop_test: prepare
 	$(MAKEF) TARGET=$@ SRCDIRS=". base event" SRCS="examples/hloop_test.c"
 
 tcp: prepare
@@ -120,4 +120,4 @@ echo-servers:
 	$(CXX) -g -Wall -std=c++11 -o bin/poco_echo     echo-servers/poco_echo.cpp   -lPocoNet -lPocoUtil -lPocoFoundation
 	$(CXX) -g -Wall -std=c++11 -o bin/muduo_echo    echo-servers/muduo_echo.cpp  -lmuduo_net -lmuduo_base -lpthread
 
-.PHONY: clean prepare libhv install examples test timer loop tcp udp nc nmap httpd curl consul_cli unittest webbench echo-servers
+.PHONY: clean prepare libhv install examples hmain_test htimer_test hloop_test tcp udp nc nmap httpd curl consul_cli unittest webbench echo-servers

+ 5 - 8
README.md

@@ -176,15 +176,12 @@ bin/nc 127.0.0.1 10514
 
 ### examples
 - make examples
-    - make test # master-workers model
-    - make timer # timer add/del/reset
-    - make loop # event-loop(include idle, timer, io)
-    - make tcp  # tcp server
-    - make udp  # udp server
-    - make nc   # network client
-    - make nmap # host discovery
+    - make tcp   # tcp server
+    - make udp   # udp server
+    - make nc    # network client
+    - make nmap  # host discovery
     - make httpd # http server
-    - make curl # http client
+    - make curl  # http client
 
 ### unittest
 - make unittest

+ 15 - 13
examples/CMakeLists.txt

@@ -1,3 +1,5 @@
+add_definitions(-DHV_SOURCE=1)
+
 aux_source_directory(../base        BASE_SRCS)
 aux_source_directory(../utils       UTILS_SRCS)
 aux_source_directory(../event       EVENT_SRCS)
@@ -7,17 +9,17 @@ aux_source_directory(../http/server HTTP_SERVER_SRCS)
 aux_source_directory(../consul      CONSUL_SRCS)
 aux_source_directory(httpd          HTTPD_SRCS)
 
-add_executable(test hmain_test.cpp ${BASE_SRCS} ${UTILS_SRCS})
-target_include_directories(test PRIVATE .. ../base ../utils)
-target_link_libraries(test ${LIBS})
+add_executable(hmain_test hmain_test.cpp ${BASE_SRCS} ${UTILS_SRCS})
+target_include_directories(hmain_test PRIVATE .. ../base ../utils)
+target_link_libraries(hmain_test ${LIBS})
 
-add_executable(timer htimer_test.c ${BASE_SRCS} ${EVENT_SRCS})
-target_include_directories(timer PRIVATE .. ../base ../event)
-target_link_libraries(timer ${LIBS})
+add_executable(htimer_test htimer_test.c ${BASE_SRCS} ${EVENT_SRCS})
+target_include_directories(htimer_test PRIVATE .. ../base ../event)
+target_link_libraries(htimer_test ${LIBS})
 
-add_executable(loop hloop_test.c ${BASE_SRCS} ${EVENT_SRCS})
-target_include_directories(loop PRIVATE .. ../base ../event)
-target_link_libraries(loop ${LIBS})
+add_executable(hloop_test hloop_test.c ${BASE_SRCS} ${EVENT_SRCS})
+target_include_directories(hloop_test PRIVATE .. ../base ../event)
+target_link_libraries(hloop_test ${LIBS})
 
 add_executable(tcp tcp.c ${BASE_SRCS} ${EVENT_SRCS})
 target_include_directories(tcp PRIVATE .. ../base ../event)
@@ -46,14 +48,14 @@ target_include_directories(curl PRIVATE .. ../base ../utils ../http ../http/clie
 target_link_libraries(curl ${LIBS})
 
 add_executable(consul_cli consul_cli.cpp ${BASE_SRCS} ${UTILS_SRCS} ${HTTP_SRCS} ${HTTP_CLIENT_SRCS} ${CONSUL_SRCS})
-target_compile_definitions(consul_cli PRIVATE -DPRINT_DEBUG)
+target_compile_definitions(consul_cli PRIVATE PRINT_DEBUG)
 target_include_directories(consul_cli PRIVATE .. ../base ../utils ../http ../http/client ../consul)
 target_link_libraries(consul_cli ${LIBS})
 
 add_custom_target(examples DEPENDS
-    test
-    timer
-    loop
+    hmain_test
+    htimer_test
+    hloop_test
     tcp
     udp
     nc

+ 2 - 2
hconfig.h

@@ -34,11 +34,11 @@
 #endif
 
 #ifndef HAVE_STRLCPY
-#define HAVE_STRLCPY 0
+#define HAVE_STRLCPY 1
 #endif
 
 #ifndef HAVE_STRLCAT
-#define HAVE_STRLCAT 0
+#define HAVE_STRLCAT 1
 #endif
 
 #ifndef HAVE_CLOCK_GETTIME

+ 2 - 2
hexport.h

@@ -2,9 +2,9 @@
 #define HV_EXPORT_H_
 
 // HV_EXPORT
-#ifdef HV_STATICLIB
+#if defined(HV_STATICLIB) || defined(HV_SOURCE)
     #define HV_EXPORT
-#elif defined(_WIN32)
+#elif defined(_MSC_VER)
     #if defined(HV_EXPORTS) || defined(hv_EXPORTS)
         #define HV_EXPORT  __declspec(dllexport)
     #else

+ 5 - 8
readme_cn.md

@@ -175,15 +175,12 @@ bin/nc 127.0.0.1 10514
 
 ### 示例
 - make examples
-    - make test # master-workers model
-    - make timer # timer add/del/reset
-    - make loop # event-loop(include idle, timer, io)
-    - make tcp  # tcp server
-    - make udp  # udp server
-    - make nc   # network client
-    - make nmap # host discovery
+    - make tcp   # tcp server
+    - make udp   # udp server
+    - make nc    # network client
+    - make nmap  # host discovery
     - make httpd # http server
-    - make curl # http client
+    - make curl  # http client
 
 ### 单元测试
 - make unittest

+ 2 - 0
unittest/CMakeLists.txt

@@ -1,3 +1,5 @@
+add_definitions(-DHV_SOURCE=1)
+
 add_executable(mkdir_p mkdir_test.c ../base/hbase.c)
 target_include_directories(mkdir_p PRIVATE .. ../base)