Upgrade to 1.46.0
[platform/upstream/nghttp2.git] / src / CMakeLists.txt
1 add_subdirectory(includes)
2
3 file(GLOB c_sources *.c)
4 set_source_files_properties(${c_sources} PROPERTIES
5   COMPILE_FLAGS "${WARNCFLAGS}")
6 file(GLOB cxx_sources *.cc)
7 set_source_files_properties(${cxx_sources} PROPERTIES
8   COMPILE_FLAGS "${WARNCXXFLAGS} ${CXX1XCXXFLAGS}")
9
10 include_directories(
11   "${CMAKE_CURRENT_SOURCE_DIR}/includes"
12   "${CMAKE_CURRENT_SOURCE_DIR}/../third-party"
13   "${CMAKE_CURRENT_SOURCE_DIR}/../third-party/llhttp/include"
14
15   ${JEMALLOC_INCLUDE_DIRS}
16   ${LIBXML2_INCLUDE_DIRS}
17   ${LIBEV_INCLUDE_DIRS}
18   ${LIBNGHTTP3_INCLUDE_DIRS}
19   ${LIBNGTCP2_INCLUDE_DIRS}
20   ${LIBNGTCP2_CRYPTO_OPENSSL_INCLUDE_DIRS}
21   ${OPENSSL_INCLUDE_DIRS}
22   ${LIBCARES_INCLUDE_DIRS}
23   ${JANSSON_INCLUDE_DIRS}
24   ${ZLIB_INCLUDE_DIRS}
25   ${LIBBPF_INCLUDE_DIRS}
26 )
27
28 # XXX per-target?
29 link_libraries(
30   nghttp2
31   ${JEMALLOC_LIBRARIES}
32   ${LIBXML2_LIBRARIES}
33   ${LIBEV_LIBRARIES}
34   ${LIBNGHTTP3_LIBRARIES}
35   ${LIBNGTCP2_LIBRARIES}
36   ${LIBNGTCP2_CRYPTO_OPENSSL_LIBRARIES}
37   ${OPENSSL_LIBRARIES}
38   ${LIBCARES_LIBRARIES}
39   ${JANSSON_LIBRARIES}
40   ${ZLIB_LIBRARIES}
41   ${APP_LIBRARIES}
42   ${LIBBPF_LIBRARIES}
43 )
44
45 if(ENABLE_APP)
46   set(HELPER_OBJECTS
47     util.cc
48     http2.cc timegm.c app_helper.cc nghttp2_gzip.c
49   )
50
51   # nghttp client
52   set(NGHTTP_SOURCES
53     ${HELPER_OBJECTS}
54     nghttp.cc
55     tls.cc
56   )
57   if(HAVE_LIBXML2)
58     list(APPEND NGHTTP_SOURCES HtmlParser.cc)
59   endif()
60
61   # nghttpd
62   set(NGHTTPD_SOURCES
63     ${HELPER_OBJECTS}
64     nghttpd.cc
65     tls.cc
66     HttpServer.cc
67   )
68
69   # h2load
70   set(H2LOAD_SOURCES
71     util.cc
72     http2.cc h2load.cc
73     timegm.c
74     tls.cc
75     h2load_http2_session.cc
76     h2load_http1_session.cc
77   )
78   if(ENABLE_HTTP3)
79     list(APPEND H2LOAD_SOURCES
80       h2load_http3_session.cc
81       h2load_quic.cc
82       quic.cc
83     )
84   endif()
85
86   # Common libnhttpx sources (used for nghttpx and unit tests)
87   set(NGHTTPX_SRCS
88     util.cc http2.cc timegm.c
89     app_helper.cc
90     tls.cc
91     shrpx_config.cc
92     shrpx_accept_handler.cc
93     shrpx_connection_handler.cc
94     shrpx_client_handler.cc
95     shrpx_http2_upstream.cc
96     shrpx_https_upstream.cc
97     shrpx_downstream.cc
98     shrpx_downstream_connection.cc
99     shrpx_http_downstream_connection.cc
100     shrpx_http2_downstream_connection.cc
101     shrpx_http2_session.cc
102     shrpx_downstream_queue.cc
103     shrpx_log.cc
104     shrpx_http.cc
105     shrpx_io_control.cc
106     shrpx_tls.cc
107     shrpx_worker.cc
108     shrpx_log_config.cc
109     shrpx_connect_blocker.cc
110     shrpx_live_check.cc
111     shrpx_downstream_connection_pool.cc
112     shrpx_rate_limit.cc
113     shrpx_connection.cc
114     shrpx_memcached_dispatcher.cc
115     shrpx_memcached_connection.cc
116     shrpx_worker_process.cc
117     shrpx_signal.cc
118     shrpx_router.cc
119     shrpx_api_downstream_connection.cc
120     shrpx_health_monitor_downstream_connection.cc
121     shrpx_null_downstream_connection.cc
122     shrpx_exec.cc
123     shrpx_dns_resolver.cc
124     shrpx_dual_dns_resolver.cc
125     shrpx_dns_tracker.cc
126     xsi_strerror.c
127   )
128   if(HAVE_MRUBY)
129     list(APPEND NGHTTPX_SRCS
130       shrpx_mruby.cc
131       shrpx_mruby_module.cc
132       shrpx_mruby_module_env.cc
133       shrpx_mruby_module_request.cc
134       shrpx_mruby_module_response.cc
135     )
136   endif()
137   if(ENABLE_HTTP3)
138     list(APPEND NGHTTPX_SRCS
139      shrpx_quic.cc
140      shrpx_quic_listener.cc
141      shrpx_quic_connection_handler.cc
142      shrpx_http3_upstream.cc
143      http3.cc
144      quic.cc
145     )
146   endif()
147   add_library(nghttpx_static STATIC ${NGHTTPX_SRCS})
148   set_target_properties(nghttpx_static PROPERTIES ARCHIVE_OUTPUT_NAME nghttpx)
149
150   set(NGHTTPX-bin_SOURCES
151     shrpx.cc
152   )
153
154   if(HAVE_SYSTEMD)
155     target_link_libraries(nghttpx_static ${SYSTEMD_LIBRARIES})
156     target_compile_definitions(nghttpx_static PUBLIC HAVE_LIBSYSTEMD)
157     target_include_directories(nghttpx_static PUBLIC ${SYSTEMD_INCLUDE_DIRS})
158   endif()
159
160   if(HAVE_MRUBY)
161     target_link_libraries(nghttpx_static mruby-lib)
162   endif()
163
164   if(HAVE_NEVERBLEED)
165     target_link_libraries(nghttpx_static neverbleed)
166   endif()
167
168
169   if(HAVE_CUNIT)
170     set(NGHTTPX_UNITTEST_SOURCES
171       shrpx-unittest.cc
172       shrpx_tls_test.cc
173       shrpx_downstream_test.cc
174       shrpx_config_test.cc
175       shrpx_worker_test.cc
176       shrpx_http_test.cc
177       shrpx_router_test.cc
178       http2_test.cc
179       util_test.cc
180       nghttp2_gzip_test.c
181       nghttp2_gzip.c
182       buffer_test.cc
183       memchunk_test.cc
184       template_test.cc
185       base64_test.cc
186     )
187     add_executable(nghttpx-unittest EXCLUDE_FROM_ALL
188       ${NGHTTPX_UNITTEST_SOURCES}
189       $<TARGET_OBJECTS:llhttp>
190       $<TARGET_OBJECTS:url-parser>
191     )
192     target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS})
193     target_compile_definitions(nghttpx-unittest
194       PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\""
195     )
196     target_link_libraries(nghttpx-unittest nghttpx_static ${CUNIT_LIBRARIES})
197     if(HAVE_MRUBY)
198       target_link_libraries(nghttpx-unittest mruby-lib)
199     endif()
200     if(HAVE_NEVERBLEED)
201       target_link_libraries(nghttpx-unittest neverbleed)
202     endif()
203
204     add_test(nghttpx-unittest nghttpx-unittest)
205     add_dependencies(check nghttpx-unittest)
206   endif()
207
208   add_executable(nghttp   ${NGHTTP_SOURCES}   $<TARGET_OBJECTS:llhttp>
209     $<TARGET_OBJECTS:url-parser>
210   )
211   add_executable(nghttpd  ${NGHTTPD_SOURCES}  $<TARGET_OBJECTS:llhttp>
212     $<TARGET_OBJECTS:url-parser>
213   )
214   add_executable(nghttpx  ${NGHTTPX-bin_SOURCES} $<TARGET_OBJECTS:llhttp>
215     $<TARGET_OBJECTS:url-parser>
216   )
217   target_compile_definitions(nghttpx PRIVATE
218     "-DPKGDATADIR=\"${PKGDATADIR}\""
219     "-DPKGLIBDIR=\"${PKGLIBDIR}\""
220   )
221   target_link_libraries(nghttpx nghttpx_static)
222   add_executable(h2load   ${H2LOAD_SOURCES}   $<TARGET_OBJECTS:llhttp>
223     $<TARGET_OBJECTS:url-parser>
224   )
225
226   install(TARGETS nghttp nghttpd nghttpx h2load
227     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
228 endif()
229
230 if(ENABLE_HPACK_TOOLS)
231   set(inflatehd_SOURCES
232     inflatehd.cc
233     comp_helper.c
234   )
235   set(deflatehd_SOURCES
236     deflatehd.cc
237     comp_helper.c
238   )
239   add_executable(inflatehd ${inflatehd_SOURCES})
240   add_executable(deflatehd ${deflatehd_SOURCES})
241   install(TARGETS inflatehd deflatehd
242     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
243 endif()
244
245 if(ENABLE_ASIO_LIB)
246   set(NGHTTP2_ASIO_SOURCES
247     util.cc http2.cc
248     tls.cc
249     timegm.c
250     asio_common.cc
251     asio_io_service_pool.cc
252     asio_server_http2.cc
253     asio_server_http2_impl.cc
254     asio_server.cc
255     asio_server_http2_handler.cc
256     asio_server_request.cc
257     asio_server_request_impl.cc
258     asio_server_response.cc
259     asio_server_response_impl.cc
260     asio_server_stream.cc
261     asio_server_serve_mux.cc
262     asio_server_request_handler.cc
263     asio_server_tls_context.cc
264     asio_client_session.cc
265     asio_client_session_impl.cc
266     asio_client_session_tcp_impl.cc
267     asio_client_session_tls_impl.cc
268     asio_client_response.cc
269     asio_client_response_impl.cc
270     asio_client_request.cc
271     asio_client_request_impl.cc
272     asio_client_stream.cc
273     asio_client_tls_context.cc
274   )
275
276   add_library(nghttp2_asio SHARED
277      ${NGHTTP2_ASIO_SOURCES}
278      $<TARGET_OBJECTS:llhttp>
279      $<TARGET_OBJECTS:url-parser>
280   )
281   target_include_directories(nghttp2_asio PRIVATE
282     ${OPENSSL_INCLUDE_DIRS}
283     ${Boost_INCLUDE_DIRS}
284   )
285   target_include_directories(nghttp2_asio INTERFACE
286     "${CMAKE_CURRENT_BINARY_DIR}/../lib/includes"
287     "${CMAKE_CURRENT_SOURCE_DIR}/../lib/includes"
288     "${CMAKE_CURRENT_SOURCE_DIR}/includes"
289   )
290   target_link_libraries(nghttp2_asio
291     nghttp2
292     ${OPENSSL_LIBRARIES}
293     ${Boost_LIBRARIES}
294   )
295   set_target_properties(nghttp2_asio PROPERTIES
296     VERSION 1.0.0 SOVERSION 1)
297
298   install(TARGETS nghttp2_asio
299     ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
300     LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
301     RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
302
303   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2_asio.pc"
304     DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
305 endif()