forked from zeromq/libzmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1547 lines (1363 loc) · 48.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 build script for ZeroMQ
project(ZeroMQ)
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
cmake_minimum_required(VERSION 3.0.2)
else()
cmake_minimum_required(VERSION 2.8.12)
endif()
include(CheckIncludeFiles)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckLibraryExists)
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CMakeDependentOption)
include(CheckCXXSymbolExists)
include(CheckTypeSize)
include(FindThreads)
include(GNUInstallDirs)
include(CheckTypeSize)
include(CMakePackageConfigHelpers)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}")
set(ZMQ_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${ZMQ_CMAKE_MODULES_DIR})
include(TestZMQVersion)
include(ZMQSourceRunChecks)
include(ZMQSupportMacros)
option(ENABLE_ASAN "Build with address sanitizer" OFF)
if(ENABLE_ASAN)
message(STATUS "Instrumenting with Address Sanitizer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
endif()
option (ENABLE_INTRINSICS "Build using compiler intrinsics for atomic ops" OFF)
if (ENABLE_INTRINSICS)
message(STATUS "Using compiler intrinsics for atomic ops")
add_definitions(-DZMQ_HAVE_ATOMIC_INTRINSICS)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
# Find more information: https://cmake.org/Wiki/CMake_RPATH_handling
# Apply CMP0042: MACOSX_RPATH is enabled by default
cmake_policy(SET CMP0042 NEW)
# Add an install rpath if it is not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
# Add linker search paths pointing to external dependencies
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
endif()
check_cxx_compiler_flag("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
endif()
check_c_compiler_flag("-std=gnu11" COMPILER_SUPPORTS_C11)
if(COMPILER_SUPPORTS_C11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
endif()
if(NOT MSVC)
# clang 6 has a warning that does not make sense on multi-platform code
check_cxx_compiler_flag("-Wno-tautological-constant-compare" CXX_HAS_TAUT_WARNING)
if(CXX_HAS_TAUT_WARNING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-constant-compare")
endif()
check_c_compiler_flag("-Wno-tautological-constant-compare" CC_HAS_TAUT_WARNING)
if(CC_HAS_TAUT_WARNING)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-tautological-constant-compare")
endif()
endif()
# Will be used to add flags to pkg-config useful when apps want to statically link
set(pkg_config_libs_private "")
set(pkg_config_names_private "")
option(WITH_OPENPGM "Build with support for OpenPGM" OFF)
option(WITH_VMCI "Build with support for VMware VMCI socket" OFF)
if(APPLE)
option(ZMQ_BUILD_FRAMEWORK "Build as OS X framework" OFF)
endif()
# Select curve encryption library, defaults to tweetnacl
# To use libsodium instead, use --with-libsodium(must be installed)
# To disable curve, use --disable-curve
option(WITH_LIBSODIUM "Use libsodium instead of built-in tweetnacl" OFF)
option(ENABLE_CURVE "Enable CURVE security" ON)
if(NOT ENABLE_CURVE)
message(STATUS "CURVE security is disabled")
elseif(WITH_LIBSODIUM)
find_package(Sodium)
if(SODIUM_FOUND)
message(STATUS "Using libsodium for CURVE security")
include_directories(${SODIUM_INCLUDE_DIRS})
set(ZMQ_USE_LIBSODIUM 1)
set(ZMQ_HAVE_CURVE 1)
else()
message(FATAL_ERROR
"libsodium is not installed. Install it, then run CMake again")
endif()
else()
message(STATUS "Using tweetnacl for CURVE security")
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/tweetnacl.c)
set(ZMQ_USE_TWEETNACL 1)
set(ZMQ_HAVE_CURVE 1)
endif()
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
if(EXISTS "${SOURCE_DIR}/.git")
option(ENABLE_DRAFTS "Build and install draft classes and methods" ON)
else()
option(ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
endif()
if(ENABLE_DRAFTS)
option (ENABLE_RADIX_TREE "Use radix tree implementation to manage subscriptions" ON)
add_definitions(-DZMQ_BUILD_DRAFT_API)
set(pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
else()
option (ENABLE_RADIX_TREE "Use radix tree implementation to manage subscriptions" OFF)
set(pkg_config_defines "")
endif()
if (ENABLE_RADIX_TREE)
message(STATUS "Using radix tree implementation to manage subscriptions")
add_definitions(-DZMQ_USE_RADIX_TREE)
endif()
option(WITH_MILITANT "Enable militant assertions" OFF)
if(WITH_MILITANT)
add_definitions(-DZMQ_ACT_MILITANT)
endif()
set(API_POLLER "" CACHE STRING "Choose polling system for zmq_poll(er)_*. valid values are
poll or select [default=poll unless POLLER=select]")
set(POLLER "" CACHE STRING "Choose polling system for I/O threads. valid values are
kqueue, epoll, devpoll, pollset, poll or select [default=autodetect]")
if(NOT MSVC)
if(POLLER STREQUAL "")
check_cxx_symbol_exists(kqueue sys/event.h HAVE_KQUEUE)
if(HAVE_KQUEUE)
set(POLLER "kqueue")
endif()
endif()
if(POLLER STREQUAL "")
check_cxx_symbol_exists(epoll_create sys/epoll.h HAVE_EPOLL)
if(HAVE_EPOLL)
set(POLLER "epoll")
check_cxx_symbol_exists(epoll_create1 sys/epoll.h HAVE_EPOLL_CLOEXEC)
if(HAVE_EPOLL_CLOEXEC)
set(ZMQ_IOTHREAD_POLLER_USE_EPOLL_CLOEXEC 1)
endif()
endif()
endif()
if(POLLER STREQUAL "")
set(CMAKE_EXTRA_INCLUDE_FILES sys/devpoll.h)
check_type_size("struct pollfd" DEVPOLL)
set(CMAKE_EXTRA_INCLUDE_FILES)
if(HAVE_DEVPOLL)
set(POLLER "devpoll")
endif()
endif()
if(POLLER STREQUAL "")
check_cxx_symbol_exists(pollset_create sys/pollset.h HAVE_POLLSET)
if(HAVE_POLLSET)
set(POLLER "pollset")
endif()
endif()
if(POLLER STREQUAL "")
check_cxx_symbol_exists(poll poll.h HAVE_POLL)
if(HAVE_POLL)
set(POLLER "poll")
endif()
endif()
endif()
if(POLLER STREQUAL "")
if(WIN32)
set(HAVE_SELECT 1)
else()
check_cxx_symbol_exists(select sys/select.h HAVE_SELECT)
endif()
if(HAVE_SELECT)
set(POLLER "select")
else()
message(FATAL_ERROR
"Could not autodetect polling method")
endif()
endif()
if(POLLER STREQUAL "kqueue"
OR POLLER STREQUAL "epoll"
OR POLLER STREQUAL "devpoll"
OR POLLER STREQUAL "pollset"
OR POLLER STREQUAL "poll"
OR POLLER STREQUAL "select")
message(STATUS "Using polling method in I/O threads: ${POLLER}")
string(TOUPPER ${POLLER} UPPER_POLLER)
set(ZMQ_IOTHREAD_POLLER_USE_${UPPER_POLLER} 1)
else()
message(FATAL_ERROR "Invalid polling method")
endif()
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/external/sha1/sha1.c ${CMAKE_CURRENT_SOURCE_DIR}/external/sha1/sha1.h)
if(POLLER STREQUAL "epoll" AND WIN32)
message(STATUS "Including wepoll")
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/external/wepoll/wepoll.c ${CMAKE_CURRENT_SOURCE_DIR}/external/wepoll/wepoll.h)
endif()
if(API_POLLER STREQUAL "")
if(POLLER STREQUAL "select")
set(API_POLLER "select")
else()
set(API_POLLER "poll")
endif()
endif()
message(STATUS "Using polling method in zmq_poll(er)_* API: ${API_POLLER}")
string(TOUPPER ${API_POLLER} UPPER_API_POLLER)
set(ZMQ_POLL_BASED_ON_${UPPER_API_POLLER} 1)
execute_process(COMMAND getconf LEVEL1_DCACHE_LINESIZE OUTPUT_VARIABLE CACHELINE_SIZE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CACHELINE_SIZE STREQUAL "" OR CACHELINE_SIZE EQUAL 0 OR CACHELINE_SIZE EQUAL -1)
set(ZMQ_CACHELINE_SIZE 64)
else()
set(ZMQ_CACHELINE_SIZE ${CACHELINE_SIZE})
endif()
message(STATUS "Using ${ZMQ_CACHELINE_SIZE} bytes alignment for lock-free data structures")
if(NOT CYGWIN)
# TODO cannot we simply do 'if(WIN32) set(ZMQ_HAVE_WINDOWS ON)' or similar?
check_include_files(windows.h ZMQ_HAVE_WINDOWS)
endif()
if (WIN32)
# from https://stackoverflow.com/a/40217291/2019765
macro(get_WIN32_WINNT version)
if (CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if ("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif ("${verMajor}" MATCHES "10")
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif(CMAKE_SYSTEM_VERSION)
endmacro(get_WIN32_WINNT)
get_WIN32_WINNT(ZMQ_WIN32_WINNT_DEFAULT)
message(STATUS "Detected _WIN32_WINNT from CMAKE_SYSTEM_VERSION: ${ZMQ_WIN32_WINNT_DEFAULT}")
# TODO limit _WIN32_WINNT to the actual Windows SDK version, which might be different from the default version installed with Visual Studio
if(MSVC_VERSION STREQUAL "1500" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.0")
set(ZMQ_WIN32_WINNT_LIMIT "0x0600")
elseif(MSVC_VERSION STREQUAL "1600" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.1")
set(ZMQ_WIN32_WINNT_LIMIT "0x0601")
elseif(MSVC_VERSION STREQUAL "1700" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.1")
set(ZMQ_WIN32_WINNT_LIMIT "0x0601")
elseif(MSVC_VERSION STREQUAL "1800" AND CMAKE_SYSTEM_VERSION VERSION_GREATER "6.2")
set(ZMQ_WIN32_WINNT_LIMIT "0x0602")
endif()
if(ZMQ_WIN32_WINNT_LIMIT)
message(STATUS "Mismatch of Visual Studio Version (${MSVC_VERSION}) and CMAKE_SYSTEM_VERSION (${CMAKE_SYSTEM_VERSION}), limiting _WIN32_WINNT to ${ZMQ_WIN32_WINNT_LIMIT}, you may override this by setting ZMQ_WIN32_WINNT")
set(ZMQ_WIN32_WINNT_DEFAULT "${ZMQ_WIN32_WINNT_LIMIT}")
endif()
set(ZMQ_WIN32_WINNT "${ZMQ_WIN32_WINNT_DEFAULT}" CACHE STRING "Value to set _WIN32_WINNT to for building [default=autodetect from build environment]")
add_definitions(-D_WIN32_WINNT=${ZMQ_WIN32_WINNT})
endif(WIN32)
###################### BEGIN condition_variable_t selection
if(NOT ZMQ_CV_IMPL)
# prefer C++11 STL std::condition_variable implementation, if available
check_include_files(condition_variable ZMQ_HAVE_STL_CONDITION_VARIABLE LANGUAGE CXX)
if (ZMQ_HAVE_STL_CONDITION_VARIABLE)
set(ZMQ_CV_IMPL_DEFAULT "stl11")
else()
if(WIN32 AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS "6.0")
# Win32API CONDITION_VARIABLE is supported from Windows Vista only
set(ZMQ_CV_IMPL_DEFAULT "win32api")
elseif(CMAKE_USE_PTHREADS_INIT)
set(ZMQ_CV_IMPL_DEFAULT "pthreads")
else()
set(ZMQ_CV_IMPL_DEFAULT "none")
endif()
endif()
# TODO a vxworks implementation also exists, but vxworks is not currently supported with cmake at all
set(ZMQ_CV_IMPL "${ZMQ_CV_IMPL_DEFAULT}" CACHE STRING "Choose condition_variable_t implementation. Valid values are
stl11, win32api, pthreads, none [default=autodetect]")
endif()
message(STATUS "Using condition_variable_t implementation: ${ZMQ_CV_IMPL}")
if(ZMQ_CV_IMPL STREQUAL "stl11")
set(ZMQ_USE_CV_IMPL_STL11 1)
elseif(ZMQ_CV_IMPL STREQUAL "win32api")
set(ZMQ_USE_CV_IMPL_WIN32API 1)
elseif(ZMQ_CV_IMPL STREQUAL "pthreads")
set(ZMQ_USE_CV_IMPL_PTHREADS 1)
elseif(ZMQ_CV_IMPL STREQUAL "none")
set(ZMQ_USE_CV_IMPL_NONE 1)
else()
message(ERROR "Unknown value for ZMQ_CV_IMPL: ${ZMQ_CV_IMPL}")
endif()
###################### END condition_variable_t selection
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND CMAKE_SYSTEM_VERSION STREQUAL "10.0")
set(ZMQ_HAVE_WINDOWS_UWP ON)
endif()
if(NOT MSVC)
check_include_files(ifaddrs.h ZMQ_HAVE_IFADDRS)
check_include_files(sys/uio.h ZMQ_HAVE_UIO)
check_include_files(sys/eventfd.h ZMQ_HAVE_EVENTFD)
if(ZMQ_HAVE_EVENTFD AND NOT CMAKE_CROSSCOMPILING)
zmq_check_efd_cloexec()
endif()
endif()
if(ZMQ_HAVE_WINDOWS)
# Cannot use check_library_exists because the symbol is always declared as char(*)(void)
set(CMAKE_REQUIRED_LIBRARIES "ws2_32.lib")
check_cxx_symbol_exists(WSAStartup "winsock2.h" HAVE_WS2_32)
set(CMAKE_REQUIRED_LIBRARIES "rpcrt4.lib")
check_cxx_symbol_exists(UuidCreateSequential "rpc.h" HAVE_RPCRT4)
set(CMAKE_REQUIRED_LIBRARIES "iphlpapi.lib")
check_cxx_symbol_exists(GetAdaptersAddresses "winsock2.h;iphlpapi.h" HAVE_IPHLAPI)
set(CMAKE_REQUIRED_LIBRARIES "")
# TODO: This not the symbol we're looking for. What is the symbol?
check_library_exists(ws2 fopen "" HAVE_WS2)
else()
check_cxx_symbol_exists(SO_PEERCRED sys/socket.h ZMQ_HAVE_SO_PEERCRED)
check_cxx_symbol_exists(LOCAL_PEERCRED sys/socket.h ZMQ_HAVE_LOCAL_PEERCRED)
endif()
if(NOT MINGW)
find_library(RT_LIBRARY rt)
if(RT_LIBRARY)
set(pkg_config_libs_private "${pkg_config_libs_private} -lrt")
endif()
endif()
find_package(Threads)
if(WIN32 AND NOT CYGWIN)
if(NOT HAVE_WS2_32 AND NOT HAVE_WS2)
message(FATAL_ERROR "Cannot link to ws2_32 or ws2")
endif()
if(NOT HAVE_RPCRT4)
message(FATAL_ERROR "Cannot link to rpcrt4")
endif()
if(NOT HAVE_IPHLAPI)
message(FATAL_ERROR "Cannot link to iphlapi")
endif()
endif()
if(NOT MSVC)
set(CMAKE_REQUIRED_LIBRARIES rt)
check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
set(CMAKE_REQUIRED_LIBRARIES)
check_cxx_symbol_exists(fork unistd.h HAVE_FORK)
check_cxx_symbol_exists(gethrtimei sys/time.h HAVE_GETHRTIME)
check_cxx_symbol_exists(mkdtemp stdlib.h HAVE_MKDTEMP)
check_cxx_symbol_exists(accept4 sys/socket.h HAVE_ACCEPT4)
check_cxx_symbol_exists(strnlen string.h HAVE_STRNLEN)
endif()
add_definitions(-D_REENTRANT -D_THREAD_SAFE)
add_definitions(-DZMQ_CUSTOM_PLATFORM_HPP)
option(ENABLE_EVENTFD "Enable/disable eventfd" ZMQ_HAVE_EVENTFD)
macro(zmq_check_cxx_flag_prepend flag)
check_cxx_compiler_flag("${flag}" HAVE_FLAG_${flag})
if(HAVE_FLAG_${flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()
option(ENABLE_ANALYSIS "Build with static analysis(make take very long)" OFF)
if(MSVC)
if(ENABLE_ANALYSIS)
zmq_check_cxx_flag_prepend("/W4")
zmq_check_cxx_flag_prepend("/analyze")
# C++11/14/17-specific, but maybe possible via conditional defines
zmq_check_cxx_flag_prepend("/wd26440") # Function '...' can be declared 'noexcept'
zmq_check_cxx_flag_prepend("/wd26432") # If you define or delete any default operation in the type '...', define or delete them all
zmq_check_cxx_flag_prepend("/wd26439") # This kind of function may not throw. Declare it 'noexcept'
zmq_check_cxx_flag_prepend("/wd26447") # The function is declared 'noexcept' but calls function '...' which may throw exceptions
zmq_check_cxx_flag_prepend("/wd26433") # Function '...' should be marked with 'override'
zmq_check_cxx_flag_prepend("/wd26409") # Avoid calling new and delete explicitly, use std::make_unique<T> instead
# Requires GSL
zmq_check_cxx_flag_prepend("/wd26429") # Symbol '...' is never tested for nullness, it can be marked as not_null
zmq_check_cxx_flag_prepend("/wd26446") # Prefer to use gsl::at()
zmq_check_cxx_flag_prepend("/wd26481") # Don't use pointer arithmetic. Use span instead
zmq_check_cxx_flag_prepend("/wd26472") # Don't use a static_cast for arithmetic conversions. Use brace initialization, gsl::narrow_cast or gsl::narow
zmq_check_cxx_flag_prepend("/wd26448") # Consider using gsl::finally if final action is intended
zmq_check_cxx_flag_prepend("/wd26400") # Do not assign the result of an allocation or a function call with an owner<T> return value to a raw pointer, use owner<T> instead
zmq_check_cxx_flag_prepend("/wd26485") # Expression '...': No array to pointer decay(bounds.3)
else()
zmq_check_cxx_flag_prepend("/W3")
endif()
if(MSVC_IDE)
set(MSVC_TOOLSET "-${CMAKE_VS_PLATFORM_TOOLSET}")
else()
set(MSVC_TOOLSET "")
endif()
else()
zmq_check_cxx_flag_prepend("-Wall")
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
zmq_check_cxx_flag_prepend("-Wextra")
endif()
option(LIBZMQ_PEDANTIC "" ON)
option(LIBZMQ_WERROR "" OFF)
# TODO: why is -Wno-long-long defined differently than in configure.ac?
if(NOT MSVC)
zmq_check_cxx_flag_prepend("-Wno-long-long")
zmq_check_cxx_flag_prepend("-Wno-uninitialized")
if(LIBZMQ_PEDANTIC)
zmq_check_cxx_flag_prepend("-pedantic")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Intel")
zmq_check_cxx_flag_prepend("-strict-ansi")
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
zmq_check_cxx_flag_prepend("-compat=5")
endif()
endif()
endif()
if(LIBZMQ_WERROR)
if(MSVC)
zmq_check_cxx_flag_prepend("/WX")
else()
zmq_check_cxx_flag_prepend("-Werror")
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
zmq_check_cxx_flag_prepend("-errwarn=%all")
endif()
endif()
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
zmq_check_cxx_flag_prepend("-mcpu=v9")
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
zmq_check_cxx_flag_prepend("-features=zla")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "SunOS" OR CMAKE_SYSTEM_NAME MATCHES "NetBSD" OR CMAKE_SYSTEM_NAME MATCHES "QNX")
message(STATUS "Checking whether atomic operations can be used")
check_c_source_compiles(
"\
#include <atomic.h> \
\
int main() \
{ \
uint32_t value; \
atomic_cas_32(&value, 0, 0); \
return 0; \
} \
"
HAVE_ATOMIC_H)
if(NOT HAVE_ATOMIC_H)
set(ZMQ_FORCE_MUTEXES 1)
endif()
endif()
if(NOT ANDROID)
zmq_check_noexcept()
endif()
#-----------------------------------------------------------------------------
if(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
zmq_check_sock_cloexec()
zmq_check_o_cloexec()
zmq_check_so_bindtodevice()
zmq_check_so_keepalive()
zmq_check_tcp_keepcnt()
zmq_check_tcp_keepidle()
zmq_check_tcp_keepintvl()
zmq_check_tcp_keepalive()
zmq_check_tcp_tipc()
zmq_check_pthread_setname()
zmq_check_pthread_setaffinity()
zmq_check_getrandom()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux"
OR CMAKE_SYSTEM_NAME MATCHES "GNU/kFreeBSD"
OR CMAKE_SYSTEM_NAME MATCHES "GNU/Hurd"
OR CYGWIN)
add_definitions(-D_GNU_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
add_definitions(-D__BSD_VISIBLE)
elseif(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
add_definitions(-D_NETBSD_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
add_definitions(-D_OPENBSD_SOURCE)
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
add_definitions(-D_PTHREADS)
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
add_definitions(-D_POSIX_C_SOURCE=200112L)
zmq_check_cxx_flag_prepend(-Ae)
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_definitions(-D_DARWIN_C_SOURCE)
endif()
find_package(AsciiDoc)
cmake_dependent_option(WITH_DOC "Build Reference Guide documentation(requires DocBook)" ON
"ASCIIDOC_FOUND;NOT WIN32" OFF) # Do not build docs on Windows due to issues with symlinks
if(MSVC)
if(WITH_OPENPGM)
#set(OPENPGM_ROOT "" CACHE PATH "Location of OpenPGM")
set(OPENPGM_VERSION_MAJOR 5)
set(OPENPGM_VERSION_MINOR 2)
set(OPENPGM_VERSION_MICRO 122)
if(CMAKE_CL_64)
find_path(OPENPGM_ROOT include/pgm/pgm.h
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
NO_DEFAULT_PATH)
message(STATUS "OpenPGM x64 detected - ${OPENPGM_ROOT}")
else()
find_path(OPENPGM_ROOT include/pgm/pgm.h
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Miru\\OpenPGM ${OPENPGM_VERSION_MAJOR}.${OPENPGM_VERSION_MINOR}.${OPENPGM_VERSION_MICRO}]"
NO_DEFAULT_PATH)
message(STATUS "OpenPGM x86 detected - ${OPENPGM_ROOT}")
endif()
set(OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include)
set(OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib)
set(OPENPGM_LIBRARIES
optimized libpgm${MSVC_TOOLSET}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib
debug libpgm${MSVC_TOOLSET}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib)
endif()
else()
if(WITH_OPENPGM)
# message(FATAL_ERROR "WITH_OPENPGM not implemented")
if(NOT OPENPGM_PKGCONFIG_NAME)
set(OPENPGM_PKGCONFIG_NAME "openpgm-5.2")
endif()
set(OPENPGM_PKGCONFIG_NAME ${OPENPGM_PKGCONFIG_NAME} CACHE STRING
"Name pkg-config shall use to find openpgm libraries and include paths"
FORCE)
find_package(PkgConfig)
pkg_check_modules(OPENPGM ${OPENPGM_PKGCONFIG_NAME})
if(OPENPGM_FOUND)
message(STATUS ${OPENPGM_PKGCONFIG_NAME}" found")
set(pkg_config_names_private "${pkg_config_names_private} ${OPENPGM_PKGCONFIG_NAME}")
else()
message(FATAL_ERROR
${OPENPGM_PKGCONFIG_NAME}" not found. openpgm is searchd via `pkg-config ${OPENPGM_PKGCONFIG_NAME}`. Consider providing a valid OPENPGM_PKGCONFIG_NAME")
endif()
# DSO symbol visibility for openpgm
if(HAVE_FLAG_VISIBILITY_HIDDEN)
elseif(HAVE_FLAG_LDSCOPE_HIDDEN)
endif()
endif()
endif()
#-----------------------------------------------------------------------------
# force off-tree build
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
message(FATAL_ERROR "CMake generation is not allowed within the source directory! \
Remove the CMakeCache.txt file and try again from another folder, e.g.: \
\
rm CMakeCache.txt \
mkdir cmake-make \
cd cmake-make \
cmake ..")
endif()
#-----------------------------------------------------------------------------
# default to Release build
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# CMAKE_BUILD_TYPE is not used for multi-configuration generators like Visual Studio/XCode
# which instead use CMAKE_CONFIGURATION_TYPES
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
#-----------------------------------------------------------------------------
# output directories
zmq_set_with_default(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/bin")
if(UNIX)
set(zmq_library_directory "lib")
else()
set(zmq_library_directory "bin")
endif()
zmq_set_with_default(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/${zmq_library_directory}")
zmq_set_with_default(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${ZeroMQ_BINARY_DIR}/lib")
#-----------------------------------------------------------------------------
# platform specifics
if(WIN32)
# Socket limit is 16K(can be raised arbitrarily)
add_definitions(-DFD_SETSIZE=16384)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
if(MSVC)
# Parallel make.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
# Compile the static lib with debug information included
# note: we assume here that the default flags contain some /Z flag
string(REGEX REPLACE "/Z." "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REGEX REPLACE "/Z." "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# Optimization flags.
# http://msdn.microsoft.com/en-us/magazine/cc301698.aspx
if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /LTCG")
endif()
endif()
#-----------------------------------------------------------------------------
# source files
set(cxx-sources
precompiled.cpp
address.cpp
client.cpp
clock.cpp
ctx.cpp
curve_mechanism_base.cpp
curve_client.cpp
curve_server.cpp
dealer.cpp
devpoll.cpp
dgram.cpp
dist.cpp
endpoint.cpp
epoll.cpp
err.cpp
fq.cpp
io_object.cpp
io_thread.cpp
ip.cpp
ipc_address.cpp
ipc_connecter.cpp
ipc_listener.cpp
kqueue.cpp
lb.cpp
mailbox.cpp
mailbox_safe.cpp
mechanism.cpp
mechanism_base.cpp
metadata.cpp
msg.cpp
mtrie.cpp
norm_engine.cpp
object.cpp
options.cpp
own.cpp
null_mechanism.cpp
pair.cpp
pgm_receiver.cpp
pgm_sender.cpp
pgm_socket.cpp
pipe.cpp
plain_client.cpp
plain_server.cpp
poll.cpp
poller_base.cpp
polling_util.cpp
pollset.cpp
proxy.cpp
pub.cpp
pull.cpp
push.cpp
random.cpp
raw_encoder.cpp
raw_decoder.cpp
raw_engine.cpp
reaper.cpp
rep.cpp
req.cpp
router.cpp
select.cpp
server.cpp
session_base.cpp
signaler.cpp
socket_base.cpp
socks.cpp
socks_connecter.cpp
stream.cpp
stream_engine_base.cpp
sub.cpp
tcp.cpp
tcp_address.cpp
tcp_connecter.cpp
tcp_listener.cpp
thread.cpp
trie.cpp
radix_tree.cpp
v1_decoder.cpp
v1_encoder.cpp
v2_decoder.cpp
v2_encoder.cpp
xpub.cpp
xsub.cpp
zmq.cpp
zmq_utils.cpp
decoder_allocators.cpp
socket_poller.cpp
timers.cpp
config.hpp
radio.cpp
dish.cpp
udp_engine.cpp
udp_address.cpp
scatter.cpp
gather.cpp
ip_resolver.cpp
zap_client.cpp
ws_connecter.cpp
ws_decoder.cpp
ws_encoder.cpp
ws_engine.cpp
ws_listener.cpp
zmtp_engine.cpp
# at least for VS, the header files must also be listed
address.hpp
array.hpp
atomic_counter.hpp
atomic_ptr.hpp
blob.hpp
client.hpp
clock.hpp
command.hpp
condition_variable.hpp
config.hpp
ctx.hpp
curve_client.hpp
curve_client_tools.hpp
curve_mechanism_base.hpp
curve_server.hpp
dbuffer.hpp
dealer.hpp
decoder.hpp
decoder_allocators.hpp
devpoll.hpp
dgram.hpp
dish.hpp
dist.hpp
encoder.hpp
endpoint.hpp
epoll.hpp
err.hpp
fd.hpp
fq.hpp
gather.hpp
generic_mtrie.hpp
generic_mtrie_impl.hpp
gssapi_client.hpp
gssapi_mechanism_base.hpp
gssapi_server.hpp
i_decoder.hpp
i_encoder.hpp
i_engine.hpp
i_mailbox.hpp
i_poll_events.hpp
io_object.hpp
io_thread.hpp
ip.hpp
ipc_address.hpp
ipc_connecter.hpp
ipc_listener.hpp
kqueue.hpp
lb.hpp
likely.hpp
macros.hpp
mailbox.hpp
mailbox_safe.hpp
mechanism.hpp
mechanism_base.hpp
metadata.hpp
msg.hpp
mtrie.hpp
mutex.hpp
norm_engine.hpp
null_mechanism.hpp
object.hpp
options.hpp
own.hpp
pair.hpp
pgm_receiver.hpp
pgm_sender.hpp
pgm_socket.hpp
pipe.hpp
plain_client.hpp
plain_common.hpp
plain_server.hpp
poll.hpp
poller.hpp
poller_base.hpp
polling_util.hpp
pollset.hpp
precompiled.hpp
proxy.hpp
pub.hpp
pull.hpp
push.hpp
radio.hpp
random.hpp
raw_decoder.hpp
raw_encoder.hpp
raw_engine.hpp
reaper.hpp
rep.hpp
req.hpp
router.hpp
scatter.hpp
secure_allocator.hpp
select.hpp
server.hpp
session_base.hpp
signaler.hpp
socket_base.hpp
socket_poller.hpp
socks.hpp
socks_connecter.hpp
stdint.hpp
stream.hpp
stream_engine_base.hpp
stream_connecter_base.hpp
stream_connecter_base.cpp
stream_listener_base.hpp
stream_listener_base.cpp
sub.hpp
tcp.hpp
tcp_address.hpp
tcp_connecter.hpp
tcp_listener.hpp
thread.hpp
timers.hpp
tipc_address.hpp
tipc_connecter.hpp
tipc_listener.hpp
trie.hpp
udp_address.hpp
udp_engine.hpp
v1_decoder.hpp
v1_encoder.hpp
v2_decoder.hpp
v2_encoder.hpp
v2_protocol.hpp
vmci.hpp
vmci_address.hpp
vmci_connecter.hpp
vmci_listener.hpp
windows.hpp
wire.hpp
ws_connecter.hpp
ws_decoder.hpp
ws_encoder.hpp
ws_engine.hpp
ws_listener.hpp
ws_protocol.hpp
xpub.hpp
xsub.hpp
ypipe.hpp
ypipe_base.hpp
ypipe_conflate.hpp
yqueue.hpp
zap_client.hpp
zmtp_engine.hpp
)
if(MINGW)
# Generate the right type when using -m32 or -m64
macro(set_rc_arch rc_target)
set(CMAKE_RC_COMPILER_INIT windres)
enable_language(RC)
set(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> <FLAGS> -O coff --target=${rc_target} <DEFINES> -i <SOURCE> -o <OBJECT>")
endmacro()
if(NOT CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
# Also happens on x86_64 systems...what a worthless variable
if(CMAKE_SYSTEM_PROCESSOR MATCHES "i386"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "i486"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "i586"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set_rc_arch("pe-x86-64")
else()
set_rc_arch("pe-i386")
endif()
endif()
endif()
set(public_headers
include/zmq.h
include/zmq_utils.h)
set(readme-docs
AUTHORS
COPYING
COPYING.LESSER
NEWS)
#-----------------------------------------------------------------------------
# optional modules
if(WITH_OPENPGM)
add_definitions(-DZMQ_HAVE_OPENPGM)
include_directories(${OPENPGM_INCLUDE_DIRS})
link_directories(${OPENPGM_LIBRARY_DIRS})
set(OPTIONAL_LIBRARIES ${OPENPGM_LIBRARIES})
endif()
if(WITH_VMCI)
add_definitions(-DZMQ_HAVE_VMCI)
include_directories(${VMCI_INCLUDE_DIRS})
list(APPEND cxx-sources vmci_address.cpp vmci_connecter.cpp vmci_listener.cpp vmci.cpp)
endif()
if(ZMQ_HAVE_TIPC)
add_definitions(-DZMQ_HAVE_TIPC)
list(APPEND cxx-sources tipc_address.cpp tipc_connecter.cpp tipc_listener.cpp)
endif()