-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathCMakeLists.txt
152 lines (123 loc) · 3.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
project(WebUdp)
cmake_minimum_required(VERSION 3.7)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
if (${OPENSSL_VERSION} VERSION_LESS "1.0.2")
message(FATAL_ERROR "Invalid OpenSSL version ${OPENSSL_VERSION}")
endif()
option(WITH_NODE "Build Node bindings" OFF)
option(WITH_TESTS "Build tests" OFF)
set(EXAMPLES_DIR ${CMAKE_CURRENT_BINARY_DIR}/examples)
add_library(Wu
CRC32.cpp
Wu.cpp
WuArena.cpp
WuPool.cpp
WuSctp.cpp
WuSdp.cpp
WuString.cpp
WuStun.cpp
WuCrypto.cpp
WuRng.cpp
WuQueue.cpp
)
if (UNIX AND NOT APPLE)
add_library(WuHost
WuHostEpoll.cpp
WuNetwork.cpp
picohttpparser.c
)
else ()
message(WARNING "Unsupported platform, defaulting to null (no-op) implementation")
add_library(WuHost
WuHostNull.cpp
)
endif()
target_include_directories(Wu
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
PRIVATE OpenSSL::SSL
)
target_include_directories(WuHost
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(Wu
PRIVATE OpenSSL::SSL
PRIVATE OpenSSL::Crypto
PRIVATE Threads::Threads
)
target_link_libraries(WuHost Wu)
target_compile_options(Wu
PRIVATE
-Wall
-fPIC
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)
target_compile_options(WuHost
PRIVATE
-Wall
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)
install(TARGETS Wu WuHost EXPORT WuTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
PUBLIC_HEADER DESTINATION include
)
install(FILES Wu.h WuHost.h DESTINATION include)
install(EXPORT WuTargets
FILE WuTargets.cmake
NAMESPACE Wu::
DESTINATION lib/cmake/Wu
)
add_executable(EchoServer examples/EchoServer.c)
target_link_libraries(EchoServer WuHost)
set_target_properties(Wu WuHost EchoServer PROPERTIES
CXX_STANDARD 11
RUNTIME_OUTPUT_DIRECTORY ${EXAMPLES_DIR}
)
file(MAKE_DIRECTORY ${EXAMPLES_DIR})
file(COPY examples/client DESTINATION ${EXAMPLES_DIR})
if (WITH_NODE)
find_program(NPM npm)
if (NPM)
cmake_policy(SET CMP0070 NEW)
file (GENERATE OUTPUT binding.gyp
INPUT ${CMAKE_CURRENT_SOURCE_DIR}/binding.gyp.in
)
file (GENERATE OUTPUT package.json
INPUT ${CMAKE_CURRENT_SOURCE_DIR}/package.json
)
add_custom_target(node ALL
COMMAND npm install
COMMAND npm run configure
COMMAND npm run build
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_command(TARGET node POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy ${CMAKE_CURRENT_BINARY_DIR}/build/Release/WebUDP.node ${EXAMPLES_DIR}
)
add_dependencies(node Wu)
file(COPY examples/EchoServer.js DESTINATION ${EXAMPLES_DIR})
else()
message(WARNING "npm not found, skipping Node bindings")
endif()
endif()
if (WITH_TESTS)
set(TESTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/tests)
file(MAKE_DIRECTORY ${TESTS_DIR})
add_executable(FuzzSdp test/FuzzSdp.cpp)
add_executable(FuzzSctp test/FuzzSctp.cpp)
add_executable(FuzzStun test/FuzzStun.cpp)
target_link_libraries(FuzzSdp Wu)
target_link_libraries(FuzzSctp Wu)
target_link_libraries(FuzzStun Wu)
file(COPY test/data DESTINATION ${TESTS_DIR})
endif()