summaryrefslogtreecommitdiffstats
path: root/src/CMakeLists.txt
blob: 6583324ed0804ba005b12fca8c5fc6f175c5da9c (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
file(GLOB c_sources *.c)
set_source_files_properties(${c_sources} PROPERTIES
  COMPILE_FLAGS "${WARNCFLAGS}")
file(GLOB cxx_sources *.cc)
set_source_files_properties(${cxx_sources} PROPERTIES
  COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}")

include_directories(
  "${CMAKE_CURRENT_SOURCE_DIR}/includes"
  "${CMAKE_CURRENT_SOURCE_DIR}/../third-party"
  "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/llhttp/include"

  ${JEMALLOC_INCLUDE_DIRS}
  ${LIBXML2_INCLUDE_DIRS}
  ${LIBEV_INCLUDE_DIRS}
  ${LIBNGHTTP3_INCLUDE_DIRS}
  ${LIBNGTCP2_INCLUDE_DIRS}
  ${LIBNGTCP2_CRYPTO_QUICTLS_INCLUDE_DIRS}
  ${OPENSSL_INCLUDE_DIRS}
  ${LIBCARES_INCLUDE_DIRS}
  ${JANSSON_INCLUDE_DIRS}
  ${ZLIB_INCLUDE_DIRS}
  ${LIBBPF_INCLUDE_DIRS}
  ${LIBBROTLIENC_INCLUDE_DIRS}
  ${LIBBROTLIDEC_INCLUDE_DIRS}
)

# XXX per-target?
link_libraries(
  nghttp2
  ${JEMALLOC_LIBRARIES}
  ${LIBXML2_LIBRARIES}
  ${LIBEV_LIBRARIES}
  ${LIBNGHTTP3_LIBRARIES}
  ${LIBNGTCP2_LIBRARIES}
  ${LIBNGTCP2_CRYPTO_QUICTLS_LIBRARIES}
  ${OPENSSL_LIBRARIES}
  ${LIBCARES_LIBRARIES}
  ${JANSSON_LIBRARIES}
  ${ZLIB_LIBRARIES}
  ${APP_LIBRARIES}
  ${LIBBPF_LIBRARIES}
  ${LIBBROTLIENC_LIBRARIES}
  ${LIBBROTLIDEC_LIBRARIES}
)

if(ENABLE_APP)
  set(HELPER_OBJECTS
    util.cc
    http2.cc timegm.c app_helper.cc nghttp2_gzip.c
  )

  # nghttp client
  set(NGHTTP_SOURCES
    ${HELPER_OBJECTS}
    nghttp.cc
    tls.cc
  )
  if(HAVE_LIBXML2)
    list(APPEND NGHTTP_SOURCES HtmlParser.cc)
  endif()

  # nghttpd
  set(NGHTTPD_SOURCES
    ${HELPER_OBJECTS}
    nghttpd.cc
    tls.cc
    HttpServer.cc
  )

  # h2load
  set(H2LOAD_SOURCES
    util.cc
    http2.cc h2load.cc
    timegm.c
    tls.cc
    h2load_http2_session.cc
    h2load_http1_session.cc
  )
  if(ENABLE_HTTP3)
    list(APPEND H2LOAD_SOURCES
      h2load_http3_session.cc
      h2load_quic.cc
      quic.cc
    )
  endif()

  # Common libnhttpx sources (used for nghttpx and unit tests)
  set(NGHTTPX_SRCS
    util.cc http2.cc timegm.c
    app_helper.cc
    tls.cc
    shrpx_config.cc
    shrpx_accept_handler.cc
    shrpx_connection_handler.cc
    shrpx_client_handler.cc
    shrpx_http2_upstream.cc
    shrpx_https_upstream.cc
    shrpx_downstream.cc
    shrpx_downstream_connection.cc
    shrpx_http_downstream_connection.cc
    shrpx_http2_downstream_connection.cc
    shrpx_http2_session.cc
    shrpx_downstream_queue.cc
    shrpx_log.cc
    shrpx_http.cc
    shrpx_io_control.cc
    shrpx_tls.cc
    shrpx_worker.cc
    shrpx_log_config.cc
    shrpx_connect_blocker.cc
    shrpx_live_check.cc
    shrpx_downstream_connection_pool.cc
    shrpx_rate_limit.cc
    shrpx_connection.cc
    shrpx_memcached_dispatcher.cc
    shrpx_memcached_connection.cc
    shrpx_worker_process.cc
    shrpx_signal.cc
    shrpx_router.cc
    shrpx_api_downstream_connection.cc
    shrpx_health_monitor_downstream_connection.cc
    shrpx_null_downstream_connection.cc
    shrpx_exec.cc
    shrpx_dns_resolver.cc
    shrpx_dual_dns_resolver.cc
    shrpx_dns_tracker.cc
    xsi_strerror.c
  )
  if(HAVE_MRUBY)
    list(APPEND NGHTTPX_SRCS
      shrpx_mruby.cc
      shrpx_mruby_module.cc
      shrpx_mruby_module_env.cc
      shrpx_mruby_module_request.cc
      shrpx_mruby_module_response.cc
    )
  endif()
  if(ENABLE_HTTP3)
    list(APPEND NGHTTPX_SRCS
     shrpx_quic.cc
     shrpx_quic_listener.cc
     shrpx_quic_connection_handler.cc
     shrpx_http3_upstream.cc
     http3.cc
     quic.cc
    )
  endif()
  add_library(nghttpx_static STATIC ${NGHTTPX_SRCS})
  set_target_properties(nghttpx_static PROPERTIES ARCHIVE_OUTPUT_NAME nghttpx)

  set(NGHTTPX-bin_SOURCES
    shrpx.cc
  )

  if(HAVE_SYSTEMD)
    target_link_libraries(nghttpx_static ${SYSTEMD_LIBRARIES})
    target_compile_definitions(nghttpx_static PUBLIC HAVE_LIBSYSTEMD)
    target_include_directories(nghttpx_static PUBLIC ${SYSTEMD_INCLUDE_DIRS})
  endif()

  if(HAVE_MRUBY)
    target_link_libraries(nghttpx_static mruby-lib)
  endif()

  if(HAVE_NEVERBLEED)
    target_link_libraries(nghttpx_static neverbleed)
  endif()

  set(NGHTTPX_UNITTEST_SOURCES
    shrpx-unittest.cc
    shrpx_tls_test.cc
    shrpx_downstream_test.cc
    shrpx_config_test.cc
    shrpx_worker_test.cc
    shrpx_http_test.cc
    shrpx_router_test.cc
    http2_test.cc
    util_test.cc
    nghttp2_gzip_test.c
    nghttp2_gzip.c
    buffer_test.cc
    memchunk_test.cc
    template_test.cc
    base64_test.cc
    ${CMAKE_SOURCE_DIR}/tests/munit/munit.c
  )
  add_executable(nghttpx-unittest EXCLUDE_FROM_ALL
    ${NGHTTPX_UNITTEST_SOURCES}
    $<TARGET_OBJECTS:llhttp>
    $<TARGET_OBJECTS:url-parser>
    )
  target_include_directories(nghttpx-unittest PRIVATE
    ${CMAKE_SOURCE_DIR}/tests/munit
  )
  target_compile_definitions(nghttpx-unittest
    PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\""
  )
  target_link_libraries(nghttpx-unittest nghttpx_static)
  if(HAVE_MRUBY)
    target_link_libraries(nghttpx-unittest mruby-lib)
  endif()
  if(HAVE_NEVERBLEED)
    target_link_libraries(nghttpx-unittest neverbleed)
  endif()

  add_test(nghttpx-unittest nghttpx-unittest)
  add_dependencies(check nghttpx-unittest)

  add_executable(nghttp   ${NGHTTP_SOURCES}   $<TARGET_OBJECTS:llhttp>
    $<TARGET_OBJECTS:url-parser>
  )
  add_executable(nghttpd  ${NGHTTPD_SOURCES}  $<TARGET_OBJECTS:llhttp>
    $<TARGET_OBJECTS:url-parser>
  )
  add_executable(nghttpx  ${NGHTTPX-bin_SOURCES} $<TARGET_OBJECTS:llhttp>
    $<TARGET_OBJECTS:url-parser>
  )
  target_compile_definitions(nghttpx PRIVATE
    "-DPKGDATADIR=\"${PKGDATADIR}\""
    "-DPKGLIBDIR=\"${PKGLIBDIR}\""
  )
  target_link_libraries(nghttpx nghttpx_static)
  add_executable(h2load   ${H2LOAD_SOURCES}   $<TARGET_OBJECTS:llhttp>
    $<TARGET_OBJECTS:url-parser>
  )

  install(TARGETS nghttp nghttpd nghttpx h2load)
endif()

if(ENABLE_HPACK_TOOLS)
  set(inflatehd_SOURCES
    inflatehd.cc
    comp_helper.c
  )
  set(deflatehd_SOURCES
    deflatehd.cc
    comp_helper.c
    util.cc
    timegm.c
  )
  add_executable(inflatehd ${inflatehd_SOURCES})
  add_executable(deflatehd ${deflatehd_SOURCES})
  install(TARGETS inflatehd deflatehd)
endif()