forked from i-rinat/nginx-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
3000 lines (2404 loc) · 82.5 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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# CMake adaptation of Nginx 1.11.6 build scripts. Targeting Linux, so any code
# obviously related to other platforms is omitted.
# Configurables.
set(NGX_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE STRING "nginx install prefix")
set(NGX_SBIN_PATH "${NGX_PREFIX}/bin/nginx" CACHE STRING "")
set(NGX_MODULES_PATH "${NGX_PREFIX}/modules" CACHE STRING "")
set(NGX_CONF_PATH "${NGX_PREFIX}/conf/nginx.conf" CACHE STRING "")
set(NGX_ERROR_LOG_PATH "${NGX_PREFIX}/logs/error.log" CACHE STRING "")
set(NGX_PID_PATH "${NGX_PREFIX}/logs/nginx.pid" CACHE STRING "")
set(NGX_LOCK_PATH "${NGX_PREFIX}/logs/nginx.lock" CACHE STRING "")
set(NGX_USER "nobody" CACHE STRING "nginx user")
set(NGX_GROUP "nogroup" CACHE STRING "nginx group")
set(NGX_PLATFORM "" CACHE STRING "NGX platform to build for")
set(NGX_BUILD "")
set(EVENT_SELECT "NO")
set(EVENT_POLL "NO")
set(USE_THREADS "NO")
set(NGX_FILE_AIO "NO")
set(HTTP "YES")
set(HTTP_CACHE "YES")
set(NGX_HTTP_LOG_PATH "logs/access.log" CACHE STRING "")
set(NGX_HTTP_CLIENT_TEMP_PATH "temp/client_body" CACHE STRING "")
set(NGX_HTTP_PROXY_TEMP_PATH "temp/proxy" CACHE STRING "")
set(NGX_HTTP_FASTCGI_TEMP_PATH "temp/fastcgi" CACHE STRING "")
set(NGX_HTTP_UWSGI_TEMP_PATH "temp/uwsgi" CACHE STRING "")
set(NGX_HTTP_SCGI_TEMP_PATH "temp/scgi" CACHE STRING "")
set(HTTP_SSL "NO")
set(HTTP_V2 "NO")
set(HTTP_REALIP "NO")
set(HTTP_ADDITION "NO")
set(HTTP_XSLT "NO")
set(HTTP_IMAGE_FILTER "NO")
set(HTTP_GEOIP "NO")
set(HTTP_SUB "NO")
set(HTTP_DAV "NO")
set(HTTP_FLV "NO")
set(HTTP_MP4 "NO")
set(HTTP_GUNZIP "NO")
set(HTTP_GZIP_STATIC "NO")
set(HTTP_AUTH_REQUEST "NO")
set(HTTP_RANDOM_INDEX "NO")
set(HTTP_SECURE_LINK "NO")
set(HTTP_DEGRADATION "NO")
set(HTTP_SLICE "NO")
set(HTTP_CHARSET "YES")
set(HTTP_GZIP "YES")
set(HTTP_SSI "YES")
set(HTTP_USERID "YES")
set(HTTP_ACCESS "YES")
set(HTTP_AUTH_BASIC "YES")
set(HTTP_AUTOINDEX "YES")
set(HTTP_GEO "YES")
set(HTTP_MAP "YES")
set(HTTP_SPLIT_CLIENTS "YES")
set(HTTP_REFERER "YES")
set(HTTP_REWRITE "YES")
set(HTTP_PROXY "YES")
set(HTTP_FASTCGI "YES")
set(HTTP_UWSGI "YES")
set(HTTP_SCGI "YES")
set(HTTP_MEMCACHED "YES")
set(HTTP_LIMIT_CONN "YES")
set(HTTP_LIMIT_REQ "YES")
set(HTTP_EMPTY_GIF "YES")
set(HTTP_BROWSER "YES")
set(HTTP_UPSTREAM_HASH "YES")
set(HTTP_UPSTREAM_IP_HASH "YES")
set(HTTP_UPSTREAM_LEAST_CONN "YES")
set(HTTP_UPSTREAM_KEEPALIVE "YES")
set(HTTP_UPSTREAM_ZONE "YES")
set(HTTP_PERL "NO")
set(HTTP_STUB_STATUS "NO")
set(MAIL "NO")
set(MAIL_SSL "NO")
set(MAIL_POP3 "YES")
set(MAIL_IMAP "YES")
set(MAIL_SMTP "YES")
set(STREAM "NO")
set(STREAM_SSL "NO")
set(STREAM_REALIP "NO")
set(STREAM_GEOIP "NO")
set(STREAM_SSL_PREREAD "NO")
set(STREAM_LIMIT_CONN "YES")
set(STREAM_ACCESS "YES")
set(STREAM_GEO "YES")
set(STREAM_MAP "YES")
set(STREAM_SPLIT_CLIENTS "YES")
set(STREAM_RETURN "YES")
set(STREAM_UPSTREAM_HASH "YES")
set(STREAM_UPSTREAM_LEAST_CONN "YES")
set(STREAM_UPSTREAM_ZONE "YES")
set(NGX_GOOGLE_PERFTOOLS "NO")
set(NGX_CPP_TEST "NO")
set(NGX_COMPAT "NO")
set(NGX_DEBUG "NO" CACHE STRING "enable nginx debug")
# end of configurables
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckTypeSize)
include(TestBigEndian)
# ngx: auto/options script
set(USE_PCRE "NO")
set(EVENT_FOUND "NO")
set(HTTP_POSTPONE "NO")
set(DYNAMIC_MODULES "")
set(USE_OPENSSL "NO")
set(USE_ZLIB "NO")
set(USE_PERL "NO")
set(NGX_PERL "perl")
set(USE_LIBXSLT "NO")
set(USE_LIBGD "NO")
set(USE_GEOIP "NO")
set(NGX_LIBATOMIC "NO")
set(NGX_CONFIGURE "")
set(NGX_TEST_BUILD_EPOLL "NO")
if (HTTP STREQUAL "NO")
set(HTTP_CHARSET "NO")
set(HTTP_GZIP "NO")
set(HTTP_SSI "NO")
set(HTTP_USERID "NO")
set(HTTP_ACCESS "NO")
set(HTTP_REWRITE "NO")
set(HTTP_PROXY "NO")
set(HTTP_FASTCGI "NO")
endif()
get_filename_component(NGX_CONF_PREFIX "${NGX_CONF_PATH}" DIRECTORY)
# ngx: auto/init script
set(AUTOGENERATED_DIR "${CMAKE_BINARY_DIR}/autogenerated")
file(MAKE_DIRECTORY "${AUTOGENERATED_DIR}")
set(NGX_MODULES_C_NAME "${AUTOGENERATED_DIR}/ngx_modules.c")
set(NGX_AUTO_HEADERS_H_NAME "${AUTOGENERATED_DIR}/ngx_auto_headers.h")
set(NGX_AUTO_CONFIG_H_NAME "${AUTOGENERATED_DIR}/ngx_auto_config.h")
# ngx: auto/sources script
set(CORE_MODULES ngx_core_module ngx_errlog_module ngx_conf_module)
set(CORE_SRCS
src/core/nginx.c
src/core/ngx_log.c
src/core/ngx_palloc.c
src/core/ngx_array.c
src/core/ngx_list.c
src/core/ngx_hash.c
src/core/ngx_buf.c
src/core/ngx_queue.c
src/core/ngx_output_chain.c
src/core/ngx_string.c
src/core/ngx_parse.c
src/core/ngx_parse_time.c
src/core/ngx_inet.c
src/core/ngx_file.c
src/core/ngx_crc32.c
src/core/ngx_murmurhash.c
src/core/ngx_md5.c
src/core/ngx_sha1.c
src/core/ngx_rbtree.c
src/core/ngx_radix_tree.c
src/core/ngx_slab.c
src/core/ngx_times.c
src/core/ngx_shmtx.c
src/core/ngx_connection.c
src/core/ngx_cycle.c
src/core/ngx_spinlock.c
src/core/ngx_rwlock.c
src/core/ngx_cpuinfo.c
src/core/ngx_conf_file.c
src/core/ngx_module.c
src/core/ngx_resolver.c
src/core/ngx_open_file_cache.c
src/core/ngx_crypt.c
src/core/ngx_proxy_protocol.c
src/core/ngx_syslog.c
)
set(EVENT_MODULES ngx_events_module ngx_event_core_module)
set(EVENT_SRCS
src/event/ngx_event.c
src/event/ngx_event_timer.c
src/event/ngx_event_posted.c
src/event/ngx_event_accept.c
src/event/ngx_event_connect.c
src/event/ngx_event_pipe.c
)
set(SELECT_MODULE ngx_select_module)
set(SELECT_SRCS src/event/modules/ngx_select_module.c)
set(POLL_MODULE ngx_poll_module)
set(POLL_SRCS src/event/modules/ngx_poll_module.c)
set(EPOLL_MODULE ngx_epoll_module)
set(EPOLL_SRCS src/event/modules/ngx_epoll_module.c)
set(FILE_AIO_SRCS src/os/unix/ngx_file_aio_read.c)
set(LINUX_AIO_SRCS src/os/unix/ngx_linux_aio_read.c)
set(UNIX_SRCS
${CORE_SRCS} ${EVENT_SRCS}
src/os/unix/ngx_time.c
src/os/unix/ngx_errno.c
src/os/unix/ngx_alloc.c
src/os/unix/ngx_files.c
src/os/unix/ngx_socket.c
src/os/unix/ngx_recv.c
src/os/unix/ngx_readv_chain.c
src/os/unix/ngx_udp_recv.c
src/os/unix/ngx_send.c
src/os/unix/ngx_writev_chain.c
src/os/unix/ngx_udp_send.c
src/os/unix/ngx_udp_sendmsg_chain.c
src/os/unix/ngx_channel.c
src/os/unix/ngx_shmem.c
src/os/unix/ngx_process.c
src/os/unix/ngx_daemon.c
src/os/unix/ngx_setaffinity.c
src/os/unix/ngx_setproctitle.c
src/os/unix/ngx_posix_init.c
src/os/unix/ngx_user.c
src/os/unix/ngx_dlopen.c
src/os/unix/ngx_process_cycle.c
)
set(THREAD_POOL_MODULE ngx_thread_pool_module)
set(THREAD_POOL_SRCS
src/core/ngx_thread_pool.c
src/os/unix/ngx_thread_cond.c
src/os/unix/ngx_thread_mutex.c
src/os/unix/ngx_thread_id.c
)
set(LINUX_SRCS src/os/unix/ngx_linux_init.c)
set(LINUX_SENDFILE_SRCS src/os/unix/ngx_linux_sendfile_chain.c)
set(HTTP_FILE_CACHE_SRCS src/http/ngx_http_file_cache.c)
# ngx: configure script
# clear autogenerated files
file(WRITE "${NGX_AUTO_CONFIG_H_NAME}" "")
file(WRITE "${NGX_AUTO_HEADERS_H_NAME}" "\n")
file(WRITE "${NGX_MODULES_C_NAME}" "")
function(ngx_auto_have option_name)
set(A "\n")
set(A "${A}#ifndef ${option_name}\n")
set(A "${A}#define ${option_name} 1\n")
set(A "${A}#endif\n\n")
file(APPEND "${NGX_AUTO_CONFIG_H_NAME}" "${A}")
endfunction()
function(ngx_auto_nohave option_name)
set(A "\n")
set(A "${A}#ifndef ${option_name}\n")
set(A "${A}#define ${option_name} 0\n")
set(A "${A}#endif\n\n")
file(APPEND "${NGX_AUTO_CONFIG_H_NAME}" "${A}")
endfunction()
function(ngx_auto_define option_name option_value)
set(A "\n")
set(A "${A}#ifndef ${option_name}\n")
set(A "${A}#define ${option_name} ${option_value}\n")
set(A "${A}#endif\n\n")
file(APPEND "${NGX_AUTO_CONFIG_H_NAME}" "${A}")
endfunction()
function(ngx_auto_have_headers option_name)
set(A "\n")
set(A "${A}#ifndef ${option_name}\n")
set(A "${A}#define ${option_name} 1\n")
set(A "${A}#endif\n\n")
file(APPEND "${NGX_AUTO_HEADERS_H_NAME}" "${A}")
endfunction()
function(ngx_append_auto_config str)
file(APPEND "${NGX_AUTO_CONFIG_H_NAME}" "${str}\n")
endfunction()
ngx_append_auto_config("#define NGX_CONFIGURE \"${NGX_CONFIGURE}\"")
if (NGX_DEBUG STREQUAL "YES")
ngx_auto_have("NGX_DEBUG")
endif()
if (NGX_PLATFORM STREQUAL "")
message(STATUS "ngx: checking for OS")
execute_process(COMMAND uname -s
OUTPUT_VARIABLE NGX_SYSTEM
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -r
OUTPUT_VARIABLE NGX_RELEASE
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND uname -s
OUTPUT_VARIABLE NGX_MACHINE
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "ngx: + ${NGX_SYSTEM} ${NGX_RELEASE} ${NGX_MACHINE}")
set(NGX_PLATFORM "${NGX_SYSTEM}:${NGX_RELEASE}:${NGX_MACHINE}")
else()
message(STATUS "ngx: building for ${NGX_PLATFORM}")
endif()
ngx_auto_define("NGX_COMPILER" "\"unknown\"")
function(ngx_auto_feature)
if (NOT ngx_feature_name STREQUAL "")
string(TOUPPER ngx_feature_name ngx_have_feature)
endif()
set(B "")
foreach(entry ${ngx_feature_incs})
set(B "${B}${entry}\n")
endforeach()
set(ngx_feature_incs "${B}")
set(B "")
foreach(entry ${ngx_feature_test})
set(B "${B}${entry}\n")
endforeach()
set(ngx_feature_test "${B}")
set(A "")
set(A "${A}#include <sys/types.h>\n")
set(A "${A}${NGX_INCLUDE_UNISTD_H}\n")
set(A "${A}${ngx_feature_incs}\n")
set(A "${A}\n")
set(A "${A}int main(void) {\n")
set(A "${A} ${ngx_feature_test};\n")
set(A "${A} return 0;\n")
set(A "${A}}\n")
# message(STATUS "A = \n${A}\n")
set(CMAKE_REQUIRED_INCLUDES ${ngx_feature_path})
set(CMAKE_REQUIRED_LIBRARIES ${ngx_feature_libs})
set(CMAKE_REQUIRED_QUIET "YES")
unset(ngx_found)
unset(ngx_found CACHE)
unset(ngx_found PARENT_SCOPE)
if ("${ngx_feature_run}" STREQUAL "yes")
CHECK_C_SOURCE_RUNS("${A}" ngx_found)
elseif ("${ngx_feature_run}" STREQUAL "no")
CHECK_C_SOURCE_COMPILES("${A}" ngx_found)
elseif ("${ngx_feature_run}" STREQUAL "value")
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-Dngx_found ${CMAKE_REQUIRED_FLAGS}")
# prepare link directories list
if (CMAKE_REQUIRED_LIBRARIES)
set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
else()
set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES)
endif()
if (CMAKE_REQUIRED_INCLUDES)
set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
else()
set(CHECK_C_SOURCE_COMPILES_ADD_INCLUDES)
endif()
set(tmp_src_name
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c")
file(WRITE "${tmp_src_name}" "${A}\n")
try_run(ngx_found_EXITCODE ngx_found_COMPILED
"${CMAKE_BINARY_DIR}"
"${tmp_src_name}"
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
-DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
"${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
COMPILE_OUTPUT_VARIABLE OUTPUT
RUN_OUTPUT_VARIABLE RUN_OUTPUT)
# if it did not compile make the return value fail code of 1
if (NOT ngx_found_COMPILED)
set(ngx_found_EXITCODE 1)
endif()
if ("${ngx_found_EXITCODE}" EQUAL 0)
set(ngx_found 1 CACHE INTERNAL "Test ngx_found")
else()
set(ngx_found "" CACHE INTERNAL "Test ngx_found")
endif()
else()
message(FATAL_ERROR "ngx_feature_run should be 'yes', 'no', or 'value'")
# do nothing
endif()
if (ngx_found EQUAL 1)
set(ngx_found "yes" PARENT_SCOPE)
if ("${ngx_feature_run}" STREQUAL "value")
message(STATUS "ngx: checking for ${ngx_feature} ... ${RUN_OUTPUT}")
ngx_auto_define("${ngx_feature_name}" "${RUN_OUTPUT}")
else()
message(STATUS "ngx: checking for ${ngx_feature} ... found")
if (NOT "${ngx_feature_name}" STREQUAL "")
ngx_auto_have("${ngx_feature_name}")
endif()
endif()
else()
set(ngx_found "no" PARENT_SCOPE)
message(STATUS "ngx: checking for ${ngx_feature} ... not found")
endif()
endfunction()
# ngx: auto/cc/conf script
# TODO: is it required? Looks wrong
set(ngx_feature "-Wl,-E switch")
set(ngx_feature_name "")
set(ngx_feature_run "no")
set(ngx_feature_incs "")
set(ngx_feature_path "")
set(ngx_feature_libs "-Wl,-E")
set(ngx_feature_test "")
ngx_auto_feature()
if (${ngx_found} STREQUAL "yes")
set(MAIN_LINK "-Wl,-E")
endif()
set(ngx_feature "gcc builtin atomic operations")
set(ngx_feature_name "NGX_HAVE_GCC_ATOMIC")
set(ngx_feature_run "yes")
set(ngx_feature_incs "")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"long n = 0\;"
"if (!__sync_bool_compare_and_swap(&n, 0, 1))"
" return 1\;"
"if (__sync_fetch_and_add(&n, 1) != 1)"
" return 1\;"
"if (n != 2)"
" return 1\;"
"__sync_synchronize()\;")
ngx_auto_feature()
set(ngx_feature "C99 variadic macros")
set(ngx_feature_name "NGX_HAVE_C99_VARIADIC_MACROS")
set(ngx_feature_run "yes")
set(ngx_feature_incs
"#include <stdio.h>"
"#define var(dummy, ...) sprintf(__VA_ARGS__)")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"char buf[30]\; buf[0] = '0'\;"
"var(0, buf, \"%d\", 1)\;"
"if (buf[0] != '1') return 1")
ngx_auto_feature()
set(ngx_feature "gcc variadic macros")
set(ngx_feature_name "NGX_HAVE_GCC_VARIADIC_MACROS")
set(ngx_feature_run "yes")
set(ngx_feature_incs
"#include <stdio.h>"
"#define var(dummy, args...) sprintf(args)")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"char buf[30]\; buf[0] = '0'\;"
"var(0, buf, \"%d\", 1)\;"
"if (buf[0] != '1') return 1")
ngx_auto_feature()
set(ngx_feature "gcc builtin 64 bit byteswap")
set(ngx_feature_name "NGX_HAVE_GCC_BSWAP64")
set(ngx_feature_run "no")
set(ngx_feature_incs "")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "if (__builtin_bswap64(0)) return 1")
ngx_auto_feature()
# ngx: auto/headers script
function(ngx_auto_check_include ngx_include)
unset(ngx_found)
unset(ngx_found CACHE)
unset(ngx_found PARENT_SCOPE)
set(A "")
set(A "${A}${NGX_INCLUDE_SYS_PARAM_H}\n")
set(A "${A}#include <${ngx_include}>\n")
set(A "${A}int main(void) {\n")
set(A "${A} return 0;\n")
set(A "${A}}\n")
set(CMAKE_REQUIRED_QUIET "YES")
CHECK_C_SOURCE_COMPILES("${A}" ngx_found)
if (ngx_found EQUAL 1)
message(STATUS "ngx: checking for ${ngx_include} ... found")
string(TOUPPER "${ngx_include}" tmp1)
string(REPLACE "/" "_" tmp2 "${tmp1}")
string(REPLACE "." "_" tmp3 "${tmp2}")
set(ngx_name "${tmp3}")
ngx_auto_have_headers("NGX_HAVE_${ngx_name}")
set(NGX_INCLUDE_${ngx_name} "#include <${ngx_include}>\n" PARENT_SCOPE)
else()
message(STATUS "ngx: checking for ${ngx_include} ... not found")
endif()
endfunction()
ngx_auto_check_include("unistd.h")
ngx_auto_check_include("inttypes.h")
ngx_auto_check_include("limits.h")
ngx_auto_check_include("sys/filio.h")
ngx_auto_check_include("sys/param.h")
ngx_auto_check_include("sys/mount.h")
ngx_auto_check_include("sys/statvfs.h")
ngx_auto_check_include("crypt.h")
# ngx: auto/os/conf with immediately auto/os/linux script
add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64)
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64")
ngx_auto_have_headers("NGX_LINUX")
set(CORE_SRCS ${UNIX_SRCS} ${LINUX_SRCS})
# posix_fadvise64() had been implemented in 2.5.60
if ("${NGX_RELEASE}" VERSION_LESS "2.5.60")
ngx_auto_nohave("NGX_HAVE_POSIX_FADVISE")
endif()
# epoll, EPOLLET version
set(ngx_feature "epoll")
set(ngx_feature_name "NGX_HAVE_EPOLL")
set(ngx_feature_run "yes")
set(ngx_feature_incs "#include <sys/epoll.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int efd = 0\;"
"struct epoll_event ee\;"
"ee.events = EPOLLIN|EPOLLOUT|EPOLLET\;"
"ee.data.ptr = NULL\;"
"(void) ee\;"
"efd = epoll_create(100)\;"
"if (efd == -1) return 1\;")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes")
ngx_auto_have("NGX_HAVE_CLEAR_EVENT")
set(CORE_SRCS ${CORE_SRCS} ${EPOLL_SRCS})
set(EVENT_MODULES ${EVENT_MODULES} ${EPOLL_MODULE})
set(EVENT_FOUND "YES")
# EPOLLRDHUP appeared in Linux 2.6.17, glibc 2.8
set(ngx_feature "EPOLLRDHUP")
set(ngx_feature_name "NGX_HAVE_EPOLLRDHUP")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/epoll.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int efd = 0, fd = 0\;"
"struct epoll_event ee\;"
"ee.events = EPOLLIN|EPOLLRDHUP|EPOLLET\;"
"ee.data.ptr = NULL\;"
"epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ee)")
ngx_auto_feature()
# EPOLLEXCLUSIVE appeared in Linux 4.5, glibc 2.24
set(ngx_feature "EPOLLEXCLUSIVE")
set(ngx_feature_name "NGX_HAVE_EPOLLEXCLUSIVE")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/epoll.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int efd = 0, fd = 0\;"
"struct epoll_event ee\;"
"ee.events = EPOLLIN|EPOLLEXCLUSIVE\;"
"ee.data.ptr = NULL\;"
"epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ee)")
ngx_auto_feature()
endif()
# O_PATH and AT_EMPTY_PATH were introduced in 2.6.39, glibc 2.14
set(ngx_feature "O_PATH")
set(ngx_feature_name "NGX_HAVE_O_PATH")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/types.h>"
"#include <sys/stat.h>"
"#include <fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int fd\; struct stat sb\;"
"fd = openat(AT_FDCWD, \".\", O_PATH|O_DIRECTORY|O_NOFOLLOW)\;"
"if (fstatat(fd, \"\", &sb, AT_EMPTY_PATH) != 0) return 1")
ngx_auto_feature()
# sendfile()
set(ngx_feature "sendfile()")
set(ngx_feature_name "NGX_HAVE_SENDFILE")
set(ngx_feature_run "yes")
set(ngx_feature_incs
"#include <sys/sendfile.h>"
"#include <errno.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int s = 0, fd = 1\;"
"ssize_t n\; off_t off = 0\;"
"n = sendfile(s, fd, &off, 1)\;"
"if (n == -1 && errno == ENOSYS) return 1")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes")
set(CORE_SRCS ${CORE_SRCS} ${LINUX_SENDFILE_SRCS})
endif()
# sendfile64()
set(ngx_feature "sendfile64()")
set(ngx_feature_name "NGX_HAVE_SENDFILE64")
set(ngx_feature_run "yes")
set(ngx_feature_incs
"#include <sys/sendfile.h>"
"#include <errno.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int s = 0, fd = 1\;"
"ssize_t n\; off_t off = 0\;"
"n = sendfile(s, fd, &off, 1)\;"
"if (n == -1 && errno == ENOSYS) return 1")
ngx_auto_feature()
ngx_auto_check_include("sys/prctl.h")
# prctl(PR_SET_DUMPABLE)
set(ngx_feature "prctl(PR_SET_DUMPABLE)")
set(ngx_feature_name "NGX_HAVE_PR_SET_DUMPABLE")
set(ngx_feature_run "yes")
set(ngx_feature_incs "#include <sys/prctl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) return 1")
ngx_auto_feature()
# sched_setaffinity()
set(ngx_feature "sched_setaffinity()")
set(ngx_feature_name "NGX_HAVE_SCHED_SETAFFINITY")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sched.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"cpu_set_t mask\;"
"CPU_ZERO(&mask)\;"
"sched_setaffinity(0, sizeof(cpu_set_t), &mask)")
ngx_auto_feature()
# crypt_r()
set(ngx_feature "crypt_r()")
set(ngx_feature_name "NGX_HAVE_GNU_CRYPT_R")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <crypt.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "-lcrypt")
set(ngx_feature_test
"struct crypt_data cd\;"
"crypt_r(\"key\", \"salt\", &cd)\;")
ngx_auto_feature()
ngx_auto_check_include("sys/vfs.h")
# ngx: back to auto/os/conf script
# XXX: targeting x86 which have nonaligned access
ngx_auto_have("NGX_HAVE_NONALIGNED")
# XXX: NGX_CPU_CACHE_LINE is hardcoded to 64
set(NGX_CPU_CACHE_LINE 64)
ngx_auto_define("NGX_CPU_CACHE_LINE" "${NGX_CPU_CACHE_LINE}")
# ngx: auto/unix script
set(ngx_feature "poll()")
set(ngx_feature_name "")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <poll.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"int n\; struct pollfd pl\;"
"pl.fd = 0\;"
"pl.events = 0\;"
"pl.revents = 0\;"
"n = poll(&pl, 1, 0)\;"
"if (n == -1) return 1")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "no")
set(EVENT_POLL "NONE")
endif()
ngx_append_auto_config("#define NGX_KQUEUE_UDATA_T (void *)")
set(ngx_feature "crypt()")
set(ngx_feature_name "")
set(ngx_feature_run "no")
set(ngx_feature_incs "")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "crypt(\"test\", \"salt\")\;")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "no")
set(ngx_feature "crypt() in libcrypt")
set(ngx_feature_name "")
set(ngx_feature_run "no")
set(ngx_feature_incs "")
set(ngx_feature_path "")
set(ngx_feature_libs "-lcrypt")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes")
set(CRYPT_LIB "-lcrypt")
endif()
endif()
set(ngx_feature "F_READAHEAD")
set(ngx_feature_name "NGX_HAVE_F_READAHEAD")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "fcntl(0, F_READAHEAD, 1)\;")
ngx_auto_feature()
set(ngx_feature "posix_fadvise()")
set(ngx_feature_name "NGX_HAVE_POSIX_FADVISE")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL)\;")
ngx_auto_feature()
set(ngx_feature "O_DIRECT")
set(ngx_feature_name "NGX_HAVE_O_DIRECT")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "fcntl(0, F_SETFL, O_DIRECT)\;")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes") # and system is Linux
ngx_auto_have("NGX_HAVE_ALIGNED_DIRECTIO")
endif()
set(ngx_feature "F_NOCACHE")
set(ngx_feature_name "NGX_HAVE_F_NOCACHE")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "fcntl(0, F_NOCACHE, 1)\;")
ngx_auto_feature()
set(ngx_feature "directio()")
set(ngx_feature_name "NGX_HAVE_DIRECTIO")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/types.h>"
"#include <sys/fcntl.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "directio(0, DIRECTIO_ON)\;")
ngx_auto_feature()
set(ngx_feature "statfs()")
set(ngx_feature_name "NGX_HAVE_STATFS")
set(ngx_feature_run "no")
set(ngx_feature_incs
"${NGX_INCLUDE_SYS_PARAM_H}"
"${NGX_INCLUDE_SYS_MOUNT_H}"
"${NGX_INCLUDE_SYS_VFS_H}")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"struct statfs fs\;"
"statfs(\".\", &fs)\;")
ngx_auto_feature()
set(ngx_feature "statvfs()")
set(ngx_feature_name "NGX_HAVE_STATVFS")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/types.h>"
"#include <sys/statvfs.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"struct statvfs fs\;"
"statvfs(\".\", &fs)\;")
ngx_auto_feature()
set(ngx_feature "dlopen()")
set(ngx_feature_name "NGX_HAVE_DLOPEN")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <dlfcn.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"dlopen(NULL, RTLD_NOW | RTLD_GLOBAL)\; dlsym(NULL, \"\")")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "no")
set(ngx_feature "dlopen() in libdl")
set(ngx_feature_libs "-ldl")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes")
set(CORE_LIBS ${CORE_LIBS} "-ldl")
set(NGX_LIBDL "-ldl")
endif()
endif()
set(ngx_feature "sched_yield()")
set(ngx_feature_name "NGX_HAVE_SCHED_YIELD")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sched.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "sched_yield()")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "no")
set(ngx_feature "sched_yield() in librt")
set(ngx_feature_libs "-lrt")
ngx_auto_feature()
if ("${ngx_found}" STREQUAL "yes")
set(CORE_LIBS ${CORE_LIBS} -lrt)
endif()
endif()
set(ngx_feature "SO_SETFIB")
set(ngx_feature_name "NGX_HAVE_SETFIB")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/socket.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 0)")
ngx_auto_feature()
set(ngx_feature "SO_REUSEPORT")
set(ngx_feature_name "NGX_HAVE_REUSEPORT")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/socket.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, SOL_SOCKET, SO_REUSEPORT, NULL, 0)")
ngx_auto_feature()
set(ngx_feature "SO_ACCEPTFILTER")
set(ngx_feature_name "NGX_HAVE_DEFERRED_ACCEPT")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/socket.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0)")
ngx_auto_feature()
# NetBSD bind to any address for transparent proxying
set(ngx_feature "SO_BINDANY")
set(ngx_feature_name "NGX_HAVE_TRANSPARENT_PROXY")
set(ngx_feature_run "no")
set(ngx_feature_incs "#include <sys/socket.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, SOL_SOCKET, SO_BINDANY, NULL, 0)")
ngx_auto_feature()
# Linux IP_BIND_ADDRESS_NO_PORT
set(ngx_feature "IP_BIND_ADDRESS_NO_PORT")
set(ngx_feature_name "NGX_HAVE_IP_BIND_ADDRESS_NO_PORT")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/socket.h>"
"#include <netinet/in.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test
"setsockopt(0, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, NULL, 0)")
ngx_auto_feature()
# Linux transparent proxying
set(ngx_feature "IP_TRANSPARENT")
set(ngx_feature_name "NGX_HAVE_TRANSPARENT_PROXY")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/socket.h>"
"#include <netinet/in.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, IPPROTO_IP, IP_TRANSPARENT, NULL, 0)")
ngx_auto_feature()
# FreeBSD bind to any address for transparent proxying
set(ngx_feature "IP_BINDANY")
set(ngx_feature_name "NGX_HAVE_TRANSPARENT_PROXY")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/socket.h>"
"#include <netinet/in.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, IPPROTO_IP, IP_BINDANY, NULL, 0)")
ngx_auto_feature()
# BSD way to get IPv4 datagram destination address
set(ngx_feature "IP_RECVDSTADDR")
set(ngx_feature_name "NGX_HAVE_IP_RECVDSTADDR")
set(ngx_feature_run "no")
set(ngx_feature_incs
"#include <sys/socket.h>"
"#include <netinet/in.h>")
set(ngx_feature_path "")
set(ngx_feature_libs "")
set(ngx_feature_test "setsockopt(0, IPPROTO_IP, IP_RECVDSTADDR, NULL, 0)")
ngx_auto_feature()
# Linux way to get IPv4 datagram destination address
set(ngx_feature "IP_PKTINFO")