forked from yedf2/handy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
110 lines (96 loc) · 4.25 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
cmake_minimum_required(VERSION 3.2)
project(handy)
set(CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)
find_package(Threads REQUIRED)
list(APPEND HANDY_SRCS
${PROJECT_SOURCE_DIR}/handy/daemon.cc
${PROJECT_SOURCE_DIR}/handy/net.cc
${PROJECT_SOURCE_DIR}/handy/codec.cc
${PROJECT_SOURCE_DIR}/handy/http.cc
${PROJECT_SOURCE_DIR}/handy/conn.cc
${PROJECT_SOURCE_DIR}/handy/poller.cc
${PROJECT_SOURCE_DIR}/handy/udp.cc
${PROJECT_SOURCE_DIR}/handy/threads.cc
${PROJECT_SOURCE_DIR}/handy/file.cc
${PROJECT_SOURCE_DIR}/handy/util.cc
${PROJECT_SOURCE_DIR}/handy/conf.cc
${PROJECT_SOURCE_DIR}/handy/stat-svr.cc
${PROJECT_SOURCE_DIR}/handy/port_posix.cc
${PROJECT_SOURCE_DIR}/handy/event_base.cc
${PROJECT_SOURCE_DIR}/handy/logging.cc)
if(CMAKE_HOST_APPLE)
add_definitions(-DOS_MACOSX)
elseif(CMAKE_HOST_UNIX)
add_definitions(-DOS_LINUX)
else(CMAKE_HOST_APPLE)
message(FATAL_ERROR "Platform not supported")
endif(CMAKE_HOST_APPLE)
option(BUILD_HANDY_SHARED_LIBRARY "Build Handy Shared Library" OFF)
option(BUILD_HANDY_STATIC_LIBRARY "Build Handy Shared Library" ON)
option(BUILD_HANDY_EXAMPLES "Build Handy Examples" OFF)
##Handy Shared Library
if(BUILD_HANDY_SHARED_LIBRARY)
add_library(handy SHARED ${HANDY_SRCS})
target_include_directories(handy PUBLIC ${PROJECT_SOURCE_DIR}/handy)
target_link_libraries(handy Threads::Threads)
install(TARGETS handy DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(BUILD_HANDY_SHARED_LIBRARY)
#Handy Static library
if(BUILD_HANDY_STATIC_LIBRARY)
add_library(handy_s STATIC ${HANDY_SRCS})
target_include_directories(handy_s PUBLIC ${PROJECT_SOURCE_DIR}/handy/)
target_link_libraries(handy_s Threads::Threads)
install(TARGETS handy_s DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(BUILD_HANDY_STATIC_LIBRARY)
if(BUILD_HANDY_SHARED_LIBRARY OR BUILD_HANDY_STATIC_LIBRARY)
install(FILES
${PROJECT_SOURCE_DIR}/handy/codec.h
${PROJECT_SOURCE_DIR}/handy/conf.h
${PROJECT_SOURCE_DIR}/handy/conn.h
${PROJECT_SOURCE_DIR}/handy/daemon.h
${PROJECT_SOURCE_DIR}/handy/event_base.h
${PROJECT_SOURCE_DIR}/handy/file.h
${PROJECT_SOURCE_DIR}/handy/handy.h
${PROJECT_SOURCE_DIR}/handy/handy-imp.h
${PROJECT_SOURCE_DIR}/handy/http.h
${PROJECT_SOURCE_DIR}/handy/logging.h
${PROJECT_SOURCE_DIR}/handy/net.h
${PROJECT_SOURCE_DIR}/handy/poller.h
${PROJECT_SOURCE_DIR}/handy/port_posix.h
${PROJECT_SOURCE_DIR}/handy/slice.h
${PROJECT_SOURCE_DIR}/handy/stat-svr.h
${PROJECT_SOURCE_DIR}/handy/status.h
${PROJECT_SOURCE_DIR}/handy/threads.h
${PROJECT_SOURCE_DIR}/handy/udp.h
${PROJECT_SOURCE_DIR}/handy/util.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/handy)
endif(BUILD_HANDY_SHARED_LIBRARY OR BUILD_HANDY_STATIC_LIBRARY)
function(add_handy_executable EXECUTABLE_NAME EXECUTABLE_SOURCES)
add_executable(${EXECUTABLE_NAME} ${EXECUTABLE_SOURCES})
target_link_libraries(${EXECUTABLE_NAME} handy_s)
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
install(TARGETS ${EXECUTABLE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction(add_handy_executable)
if(BUILD_HANDY_EXAMPLES)
add_handy_executable(codec-cli examples/codec-cli.cc)
add_handy_executable(codec-svr examples/codec-svr.cc)
add_handy_executable(daemon examples/daemon.cc)
add_handy_executable(echo examples/echo.cc)
add_handy_executable(hsha examples/hsha.cc)
add_handy_executable(http-hello examples/http-hello.cc)
add_handy_executable(idle-close examples/idle-close.cc)
add_handy_executable(reconnect examples/reconnect.cc)
add_handy_executable(safe-close examples/safe-close.cc)
add_handy_executable(stat examples/stat.cc)
add_handy_executable(timer examples/timer.cc)
add_handy_executable(udp-cli examples/udp-cli.cc)
add_handy_executable(udp-hsha examples/udp-hsha.cc)
add_handy_executable(udp-svr examples/udp-svr.cc)
add_handy_executable(write-on-empty examples/write-on-empty.cc)
add_handy_executable(10m-cli 10m/10m-cli.cc)
add_handy_executable(10m-svr 10m/10m-svr.cc)
if(CMAKE_HOST_APPLE)
add_handy_executable(kqueue raw-examples/kqueue.cc)
endif(CMAKE_HOST_APPLE)
endif(BUILD_HANDY_EXAMPLES)