forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zproject_cmake.gsl
1182 lines (1062 loc) · 38 KB
/
zproject_cmake.gsl
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
# Generate CMake project file for project
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/zeromq/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
register_target ("cmake", "CMake build system")
.macro target_cmake
.output "CMakeLists.txt"
$(project.GENERATED_WARNING_HEADER:)
########################################################################
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.12)
project($(project.name:c))
.if project.use_cxx
enable_language(CXX)
.else
enable_language(C)
.endif
enable_testing()
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Select flags
if(MSVC)
SET(CMAKE_C_FLAGS_RELEASE "/O2")
else()
SET(CMAKE_C_FLAGS_RELEASE "-O3")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
# 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 "")
########################################################################
# options
########################################################################
.if project.stable
if (NOT CMAKE_BUILD_TYPE)
if (EXISTS "${SOURCE_DIR}/.git")
set (CMAKE_BUILD_TYPE Debug)
else ()
# http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
# http://stackoverflow.com/questions/6797395/cmake-execute-process-always-fails-with-no-such-file-or-directory-when-i-cal
execute_process(
COMMAND git rev-parse --show-toplevel
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_root
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "git workspace root [${git_result}]: ${git_root}")
if ( "${git_result}" STREQUAL "0" )
set (CMAKE_BUILD_TYPE Debug)
else ()
set (CMAKE_BUILD_TYPE Release)
endif ()
endif ()
endif ()
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
else ()
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
endif ()
.else
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
.endif
IF (ENABLE_DRAFTS)
ADD_DEFINITIONS (-D$(PROJECT.PREFIX)_BUILD_DRAFT_API)
ENDIF (ENABLE_DRAFTS)
########################################################################
# platform.h
########################################################################
include(CheckIncludeFile)
CHECK_INCLUDE_FILE("linux/wireless.h" HAVE_LINUX_WIRELESS_H)
CHECK_INCLUDE_FILE("net/if_media.h" HAVE_NET_IF_MEDIA_H)
include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS("getifaddrs" HAVE_GETIFADDRS)
CHECK_FUNCTION_EXISTS("freeifaddrs" HAVE_FREEIFADDRS)
include(CheckIncludeFiles)
check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H)
if (NOT HAVE_NET_IF_H)
CHECK_INCLUDE_FILE("net/if.h" HAVE_NET_IF_H)
endif()
.for project.check_symbol_exists
. if first()
include(CheckSymbolExists)
. endif
check_symbol_exists($(symbol:) "$(header:)" HAVE_DECL_$(SYMBOL:c))
. if last()
. endif
.endfor
file(REMOVE "${SOURCE_DIR}/src/platform.h")
file(WRITE "${PROJECT_BINARY_DIR}/platform.h.in" "
#cmakedefine HAVE_LINUX_WIRELESS_H
#cmakedefine HAVE_NET_IF_H
#cmakedefine HAVE_NET_IF_MEDIA_H
#cmakedefine HAVE_GETIFADDRS
#cmakedefine HAVE_FREEIFADDRS
.for project.check_symbol_exists
#cmakedefine01 HAVE_DECL_$(SYMBOL:c)
.endfor
")
configure_file("${PROJECT_BINARY_DIR}/platform.h.in" "${PROJECT_BINARY_DIR}/platform.h")
if (WIN32)
#The MSVC C compiler is too out of date,
#so the sources have to be compiled as c++
if (MSVC AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
enable_language(CXX)
. if project.use_cxx
file(GLOB sources "${SOURCE_DIR}/src/*.$(project.source_ext)")
. else
file(GLOB sources "${SOURCE_DIR}/src/*.$(project.source_ext)")
. endif
set_source_files_properties(
${sources}
PROPERTIES LANGUAGE CXX
)
endif()
set(MORE_LIBRARIES ws2_32 Rpcrt4 Iphlpapi)
endif()
# specific case of windows UWP
if( "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore" AND "${CMAKE_SYSTEM_VERSION}" STREQUAL "10.0")
ADD_DEFINITIONS(-DZMQ_HAVE_WINDOWS_UWP)
ADD_DEFINITIONS(-D_WIN32_WINNT=_WIN32_WINNT_WIN10)
endif()
# required libraries for mingw
if (MINGW)
set(MORE_LIBRARIES -lws2_32 -lrpcrt4 -liphlpapi)
endif()
# required libraries for cygwin
if (CYGWIN)
set(MORE_LIBRARIES)
endif()
list(APPEND CMAKE_MODULE_PATH "${SOURCE_DIR}")
set(OPTIONAL_LIBRARIES)
set(OPTIONAL_LIBRARIES_STATIC)
.for use where !(implied & private)
########################################################################
# $(USE.PROJECT) dependency
########################################################################
.if use.optional = 0
find_package($(use.project) REQUIRED)
IF ($(USE.PROJECT)_FOUND)
.else
find_package($(use.project))
option($(PROJECT.PREFIX)_WITH_$(USE.PROJECT) "Build $(project.linkname) with $(use.project)" ${$(USE.PROJECT)_FOUND})
IF ($(PROJECT.PREFIX)_WITH_$(USE.PROJECT) AND $(USE.PROJECT)_FOUND)
.endif
.if use.libname ?<> ""
include_directories(${$(USE.PROJECT)_INCLUDE_DIRS})
list(APPEND MORE_LIBRARIES ${$(USE.PROJECT)_LIBRARIES})
IF (PC_$(USE.PROJECT)_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} $(use.libname)\
. if (use.min_version <> '0.0.0')
>= $(use.min_version)\
. endif
. if defined(use.max_version) | defined(use.next_incompatible_version)
. if (use.min_version = '0.0.0')
>= 0.0.0
. endif
. if defined(use.max_version)
$(use.libname) <= $(use.max_version)\
. endif
. if defined(use.next_incompatible_version)
$(use.libname) < $(use.next_incompatible_version)\
. endif
. endif
")
list(APPEND OPTIONAL_LIBRARIES_STATIC ${PC_$(USE.PROJECT)_STATIC_LDFLAGS})
ELSE (PC_$(USE.PROJECT)_FOUND)
set(pkg_config_libs_private "${pkg_config_libs_private} -l$(use.linkname)")
ENDIF (PC_$(USE.PROJECT)_FOUND)
.if use.optional = 1
add_definitions(-DHAVE_$(USE.LIBNAME))
list(APPEND OPTIONAL_LIBRARIES ${$(USE.PROJECT)_LIBRARIES})
.endif
.endif
. if defined (use.description)
set_feature_info($(use.project) "$(use.description:)")
. endif
.if use.optional = 0
ELSE ($(USE.PROJECT)_FOUND)
message( FATAL_ERROR "$(use.project) not found." )
ENDIF ($(USE.PROJECT)_FOUND)
.else
ENDIF ($(PROJECT.PREFIX)_WITH_$(USE.PROJECT) AND $(USE.PROJECT)_FOUND)
.endif
.endfor
########################################################################
# version
########################################################################
.if defined (project->version)
set($(PROJECT.PREFIX)_VERSION_MAJOR $(project->version.major))
set($(PROJECT.PREFIX)_VERSION_MINOR $(project->version.minor))
set($(PROJECT.PREFIX)_VERSION_PATCH $(project->version.patch))
.else
set($(PROJECT.PREFIX)_VERSION_MAJOR "0")
set($(PROJECT.PREFIX)_VERSION_MINOR "0")
set($(PROJECT.PREFIX)_VERSION_PATCH "0")
.endif
set($(PROJECT.PREFIX)_VERSION "${$(PROJECT.PREFIX)_VERSION_MAJOR}.${$(PROJECT.PREFIX)_VERSION_MINOR}.${$(PROJECT.PREFIX)_VERSION_PATCH}")
message(STATUS "Detected $(PROJECT.PREFIX) Version - ${$(PROJECT.PREFIX)_VERSION}")
########################################################################
# includes
########################################################################
set ($(project.prefix)_headers
.if count (project.class)
include/$(project.prefix)_library.$(project.header_ext)
. if file.exists ("include/$(project.prelude)")
include/$(project.prelude)
. endif
. if count (class, class.name = project.name) = 0
include/$(project.header:)
. endif
.endif
.for header where scope = "public"
include/$(name:$(project.filename_prettyprint)).$(project.header_ext)
.endfor
.for class where scope = "public" & !draft
include/$(name:$(project.filename_prettyprint)).$(project.header_ext)
.endfor
.for class where scope = "private"
src/$(name:$(project.filename_prettyprint)).$(project.header_ext)
.endfor
.for extra
src/$(name)
.endfor
)
.if count (class, scope = "public" & draft)
IF (ENABLE_DRAFTS)
list(APPEND $(project.prefix)_headers
. for class where scope = "public" & draft
include/$(name:$(project.filename_prettyprint)).$(project.header_ext)
. endfor
)
ENDIF (ENABLE_DRAFTS)
. endif
source_group ("Header Files" FILES ${$(project.prefix)_headers})
install(FILES ${$(project.prefix)_headers} DESTINATION include)
.if count (project.class)
########################################################################
# library
########################################################################
include_directories("${SOURCE_DIR}/src" "${SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}")
set ($(project.linkname)_sources
.for class where !draft
. if project.use_cxx
src/$(name:$(project.filename_prettyprint)).$(project.source_ext)
. else
src/$(name:$(project.filename_prettyprint)).$(project.source_ext)
. endif
.endfor
)
.if count (class, draft)
IF (ENABLE_DRAFTS)
list (APPEND $(project.linkname)_sources
. for class where draft
. if project.use_cxx
src/$(name:$(project.filename_prettyprint)).$(project.source_ext)
. else
src/$(name:$(project.filename_prettyprint)).$(project.source_ext)
. endif
. endfor
)
ENDIF (ENABLE_DRAFTS)
.endif
.if count (class)
IF (ENABLE_DRAFTS)
list (APPEND $(project.linkname)_sources
. if project.use_cxx
src/$(project.prefix)_private_selftest.$(project.source_ext)
. else
src/$(project.prefix)_private_selftest.$(project.source_ext)
. endif
)
ENDIF (ENABLE_DRAFTS)
.endif
source_group("Source Files" FILES ${$(project.linkname)_sources})
option($(PROJECT.PREFIX)_BUILD_SHARED "Whether or not to build the shared object" ON)
option($(PROJECT.PREFIX)_BUILD_STATIC "Whether or not to build the static archive" ON)
if (NOT $(PROJECT.PREFIX)_BUILD_SHARED AND NOT $(PROJECT.PREFIX)_BUILD_STATIC)
message(FATAL_ERROR "Neither static nor shared library build enabled")
endif()
IF (NOT MSVC)
# avoid building everything twice for shared + static
# only on *nix, as Windows needs different preprocessor defines in static builds
add_library ($(project.linkname)_objects OBJECT ${$(project.linkname)_sources})
set_property(TARGET $(project.linkname)_objects PROPERTY POSITION_INDEPENDENT_CODE ON)
ENDIF (NOT MSVC)
# shared
if ($(PROJECT.PREFIX)_BUILD_SHARED)
IF (APPLE)
add_library($(project.linkname) SHARED ${$(project.linkname)_sources})
ELSE (APPLE)
IF (MSVC)
add_library($(project.linkname) SHARED ${$(project.linkname)_sources})
ELSE (MSVC)
add_library($(project.linkname) SHARED $<TARGET_OBJECTS:$(project.linkname)_objects>)
ENDIF (MSVC)
ENDIF(APPLE)
set_target_properties ($(project.linkname) PROPERTIES
PUBLIC_HEADER "${public_headers}"
DEFINE_SYMBOL "$(PROJECT.PREFIX)_EXPORTS"
.if defined (project->abi)
SOVERSION "$(project->abi.current - project->abi.age)"
.else
SOVERSION "0"
.endif
VERSION "${$(PROJECT.PREFIX)_VERSION}"
COMPILE_DEFINITIONS "DLL_EXPORT"
OUTPUT_NAME "$(project.linkname)"
PREFIX "lib"
)
target_link_libraries($(project.linkname)
PUBLIC ${MORE_LIBRARIES}
)
install(TARGETS $(project.linkname)
EXPORT $(project.linkname)-targets
LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
RUNTIME DESTINATION bin # .dll file
)
target_include_directories($(project.linkname)
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
endif()
# static
if ($(PROJECT.PREFIX)_BUILD_STATIC)
IF (APPLE)
add_library($(project.linkname)-static STATIC ${$(project.linkname)_sources})
ELSE (APPLE)
IF (MSVC)
add_library($(project.linkname)-static STATIC ${$(project.linkname)_sources})
ELSE (MSVC)
add_library($(project.linkname)-static STATIC $<TARGET_OBJECTS:$(project.linkname)_objects>)
ENDIF (MSVC)
ENDIF (APPLE)
set_target_properties($(project.linkname)-static PROPERTIES
PUBLIC_HEADER "${public_headers}"
COMPILE_DEFINITIONS "$(PROJECT.PREFIX)_STATIC"
OUTPUT_NAME "$(project.linkname)"
PREFIX "lib"
)
target_link_libraries($(project.linkname)-static
PUBLIC ${MORE_LIBRARIES}
)
install(TARGETS $(project.linkname)-static
EXPORT $(project.linkname)-targets
LIBRARY DESTINATION "lib${LIB_SUFFIX}" # .so file
ARCHIVE DESTINATION "lib${LIB_SUFFIX}" # .lib file
RUNTIME DESTINATION bin # .dll file
)
target_include_directories($(project.linkname)-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions($(project.linkname)-static
PUBLIC $(PROJECT.PREFIX)_STATIC
)
endif()
.if file.exists ("src/CMakeLists-local.txt")
include(${CMAKE_CURRENT_SOURCE_DIR}/src/CMakeLists-local.txt) # Optional project-local hook
.endif
########################################################################
# pkgconfig
########################################################################
set (VERSION "$(->version.major).$(->version.minor).$(->version.patch)")
set (prefix "${CMAKE_INSTALL_PREFIX}")
set (exec_prefix "\\${prefix}")
set (libdir "\\${prefix}/lib${LIB_SUFFIX}")
set (includedir "\\${prefix}/include")
IF (ENABLE_DRAFTS)
set (pkg_config_defines "-D$(PROJECT.PREFIX)_BUILD_DRAFT_API=1")
ELSE (ENABLE_DRAFTS)
set (pkg_config_defines "")
ENDIF (ENABLE_DRAFTS)
configure_file(
"${SOURCE_DIR}/src/$(project.libname).pc.in"
"${SOURCE_DIR}/src/$(project.libname).pc"
@ONLY)
install(
FILES "${SOURCE_DIR}/src/$(project.libname).pc"
DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
)
########################################################################
# installer
########################################################################
include(CMakePackageConfigHelpers)
if (WIN32)
set(CMAKECONFIG_INSTALL_DIR "CMake" CACHE STRING "install path for $(project.linkname)Config.cmake")
else()
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
set(CMAKECONFIG_INSTALL_DIR "share/cmake/$(project.linkname)" CACHE STRING "install path for $(project.linkname)Config.cmake")
endif()
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
export(EXPORT $(project.linkname)-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/$(project.linkname)Targets.cmake")
endif()
configure_package_config_file(builds/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/$(project.linkname)Config.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/$(project.linkname)ConfigVersion.cmake
VERSION ${$(PROJECT.PREFIX)_VERSION}
COMPATIBILITY AnyNewerVersion)
install(EXPORT $(project.linkname)-targets
FILE $(project.linkname)Targets.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$(project.linkname)Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/$(project.linkname)ConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
.endif
########################################################################
# executables
########################################################################
.for project.main
add_executable(
$(main.name)
. if project.use_cxx
"${SOURCE_DIR}/src/$(name).$(project.source_ext)"
. else
"${SOURCE_DIR}/src/$(name).$(project.source_ext)"
. endif
)
if (TARGET $(project.linkname))
target_link_libraries(
$(main.name)
.if count (project.class)
$(project.linkname)
.endif
.for project.use where !(implied & private)
.if use.optional = 0
${$(USE.PROJECT)_LIBRARIES}
.endif
.endfor
${OPTIONAL_LIBRARIES}
)
endif()
if (NOT TARGET $(project.linkname) AND TARGET $(project.linkname)-static)
target_link_libraries(
$(main.name)
.if count (project.class)
$(project.linkname)-static
.endif
.for project.use where !(implied & private)
.if use.optional = 0
${$(USE.PROJECT)_LIBRARIES}
.endif
.endfor
${OPTIONAL_LIBRARIES}
${OPTIONAL_LIBRARIES_STATIC}
)
endif()
. if main.scope = "public"
install(TARGETS $(main.name)
RUNTIME DESTINATION bin
)
. endif
.endfor
########################################################################
# tests
########################################################################
set(CLASSTEST_TIMEOUT 60 CACHE STRING "Timeout of the selftest of a class")
set(TOTAL_TIMEOUT 600 CACHE STRING "Timout of the total testsuite")
if(UNIX)
find_program(MEMORYCHECK_COMMAND valgrind)
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-reachable=yes
--error-exitcode=1
--suppressions=src/.valgrind.supp")
endif()
set(TEST_CLASSES
.for class where !draft & private ?<> 1
$(name:c)
.endfor
)
.if count (class, draft & private ?<> 1)
IF (ENABLE_DRAFTS)
list (APPEND TEST_CLASSES
. for class where draft & private ?<> 1
$(name:c)
. endfor
)
ENDIF (ENABLE_DRAFTS)
.endif
.if count (class, private ?<> 0)
IF (ENABLE_DRAFTS)
list (APPEND TEST_CLASSES
private_classes
)
ENDIF (ENABLE_DRAFTS)
.endif
if (NOT TARGET copy-selftest-ro)
add_custom_target(
copy-selftest-ro ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/src/selftest-ro ${PROJECT_BINARY_DIR}/src/selftest-ro
)
endif()
if (NOT TARGET make-selftest-rw)
add_custom_target(
make-selftest-rw ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/src/selftest-rw
)
endif()
.insert_snippet ("CMakeLists_custom_targets")
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_BINARY_DIR}/src/selftest-ro;${PROJECT_BINARY_DIR}/src/selftest-rw"
)
foreach(TEST_CLASS ${TEST_CLASSES})
add_test(
NAME ${TEST_CLASS}
COMMAND $(project.prefix)_selftest --continue --verbose --test ${TEST_CLASS}
)
IF (WIN32 AND CMAKE_PREFIX_PATH)
file(TO_NATIVE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH_WIN)
set_tests_properties(
${TEST_CLASS}
PROPERTIES ENVIRONMENT "PATH=%PATH%\\;${CMAKE_PREFIX_PATH_WIN}\\\\bin"
)
ENDIF (WIN32 AND CMAKE_PREFIX_PATH)
set_tests_properties(
${TEST_CLASS}
PROPERTIES TIMEOUT ${CLASSTEST_TIMEOUT}
)
set_tests_properties(
${TEST_CLASS}
PROPERTIES DEPENDS "copy-selftest-ro;make-selftest-rw"
)
endforeach(TEST_CLASS)
include(CTest)
########################################################################
# cleanup
########################################################################
if (NOT TARGET distclean)
add_custom_target (distclean @echo Cleaning for source distribution)
endif()
set(cmake_generated ${PROJECT_BINARY_DIR}/CMakeCache.txt
${PROJECT_BINARY_DIR}/cmake_install.cmake
${PROJECT_BINARY_DIR}/Makefile
${PROJECT_BINARY_DIR}/CMakeFiles
${PROJECT_BINARY_DIR}/CTestTestfile.cmake
${PROJECT_BINARY_DIR}/DartConfiguration.tcl
${PROJECT_BINARY_DIR}/Testing
${PROJECT_BINARY_DIR}/compile_commands.json
${PROJECT_BINARY_DIR}/platform.h
${PROJECT_BINARY_DIR}/src/$(project.libname).pc
${PROJECT_BINARY_DIR}/src/$(project.libname).so
${PROJECT_BINARY_DIR}/src/$(project.name)_selftest
.for project.main
${PROJECT_BINARY_DIR}/src/$(main.name)
.endfor
)
add_custom_command(
DEPENDS clean
COMMENT "distribution clean"
COMMAND rm
ARGS -rf CMakeTmp ${cmake_generated}
TARGET distclean
)
include(ClangFormat OPTIONAL)
########################################################################
# summary
########################################################################
message ("")
message (STATUS "******************* Configuration Summary *******************")
message (STATUS "General:")
message (STATUS " Version : ${VERSION}")
message (STATUS " System : ${CMAKE_SYSTEM_NAME}")
message (STATUS " C compiler : ${CMAKE_C_COMPILER}")
message (STATUS " Debug C flags : ${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS}")
message (STATUS " Release C flags : ${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS}")
message (STATUS " Build type : ${CMAKE_BUILD_TYPE}")
message (STATUS " Static build : ${$(PROJECT.PREFIX)_BUILD_STATIC}")
message (STATUS " Shared build : ${$(PROJECT.PREFIX)_BUILD_SHARED}")
IF (ENABLE_DRAFTS)
message (STATUS " Draft API : Yes")
ELSE (ENABLE_DRAFTS)
message (STATUS " Draft API : No")
ENDIF (ENABLE_DRAFTS)
message (STATUS "")
message (STATUS "Dependencies:")
include(FeatureSummary)
feature_summary (WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
message (STATUS "")
message (STATUS "Install:")
message (STATUS " Install prefix :" "${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "************************* Options ***************************")
message (STATUS "Options:")
message (STATUS " Use the Draft API (default = yes):")
message (STATUS " -DENABLE-DRAFTS=[yes|no]")
message (STATUS "")
message (STATUS "*************************************************************")
message (STATUS "Configuration complete! Now procced with:")
message (STATUS " 'make' compile the project")
message (STATUS " 'make test' run the project's selftest")
message (STATUS " 'make install' install the project to ${CMAKE_INSTALL_PREFIX}")
message (STATUS "")
message (STATUS "Further options are:")
message (STATUS " 'ctest -V run test with verbose logging")
message (STATUS " 'ctest -R <test_name>' run a specific test")
message (STATUS " 'ctest -T memcheck' run the project's selftest with")
message (STATUS " valgrind to check for memory leaks")
message (STATUS "")
$(project.GENERATED_WARNING_HEADER:)
.
.for use where !(implied & private)
.output "Find$(use.project:c).cmake"
$(project.GENERATED_WARNING_HEADER:)
. if use.libname ?<> ""
if (NOT MSVC)
include(FindPkgConfig)
pkg_check_modules(PC_$(USE.PROJECT) "$(use.libname)")
if (PC_$(USE.PROJECT)_FOUND)
# add CFLAGS from pkg-config file, e.g. draft api.
add_definitions(${PC_$(USE.PROJECT)_CFLAGS} ${PC_$(USE.PROJECT)_CFLAGS_OTHER})
# some libraries install the headers is a subdirectory of the include dir
# returned by pkg-config, so use a wildcard match to improve chances of finding
# headers and SOs.
set(PC_$(USE.PROJECT)_INCLUDE_HINTS ${PC_$(USE.PROJECT)_INCLUDE_DIRS} ${PC_$(USE.PROJECT)_INCLUDE_DIRS}/*)
set(PC_$(USE.PROJECT)_LIBRARY_HINTS ${PC_$(USE.PROJECT)_LIBRARY_DIRS} ${PC_$(USE.PROJECT)_LIBRARY_DIRS}/*)
endif(PC_$(USE.PROJECT)_FOUND)
endif (NOT MSVC)
find_path (
$(USE.PROJECT)_INCLUDE_DIRS
NAMES $(use.header:)
HINTS ${PC_$(USE.PROJECT)_INCLUDE_HINTS}
)
. if use.libname ?= "libzmq"
if (MSVC)
# libzmq dll/lib built with MSVC is named using the Boost convention.
# https://github.com/zeromq/czmq/issues/577
# https://github.com/zeromq/czmq/issues/1972
if (MSVC_IDE)
set(MSVC_TOOLSET "-${CMAKE_VS_PLATFORM_TOOLSET}")
else ()
set(MSVC_TOOLSET "")
endif ()
# Retrieve ZeroMQ version number from zmq.h
file(STRINGS "${LIBZMQ_INCLUDE_DIRS}/zmq.h" zmq_version_defines
REGEX "#define ZMQ_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${zmq_version_defines})
if(ver MATCHES "#define ZMQ_VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
set(ZMQ_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(_zmq_version ${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH})
set(_zmq_debug_names
"libzmq${MSVC_TOOLSET}-mt-gd-${_zmq_version}" # Debug, BUILD_SHARED
"libzmq${MSVC_TOOLSET}-mt-sgd-${_zmq_version}" # Debug, BUILD_STATIC
"libzmq-mt-gd-${_zmq_version}" # Debug, BUILD_SHARED
"libzmq-mt-sgd-${_zmq_version}" # Debug, BUILD_STATIC
)
set(_zmq_release_names
"libzmq${MSVC_TOOLSET}-mt-${_zmq_version}" # Release|RelWithDebInfo|MinSizeRel, BUILD_SHARED
"libzmq${MSVC_TOOLSET}-mt-s-${_zmq_version}" # Release|RelWithDebInfo|MinSizeRel, BUILD_STATIC
"libzmq-mt-${_zmq_version}" # Release|RelWithDebInfo|MinSizeRel, BUILD_SHARED
"libzmq-mt-s-${_zmq_version}" # Release|RelWithDebInfo|MinSizeRel, BUILD_STATIC
)
find_library (LIBZMQ_LIBRARY_DEBUG
NAMES ${_zmq_debug_names}
)
find_library (LIBZMQ_LIBRARY_RELEASE
NAMES ${_zmq_release_names}
)
include(SelectLibraryConfigurations)
select_library_configurations(LIBZMQ)
endif ()
if (NOT LIBZMQ_LIBRARIES)
find_library (
LIBZMQ_LIBRARIES
NAMES libzmq zmq
HINTS ${PC_LIBZMQ_LIBRARY_HINTS}
)
endif ()
. else
find_library (
$(USE.PROJECT)_LIBRARIES
. if use.libname ?<> use.linkname
NAMES $(use.libname) $(use.linkname)
. else
NAMES $(use.linkname)
. endif
HINTS ${PC_$(USE.PROJECT)_LIBRARY_HINTS}
)
. endif
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
$(USE.PROJECT)
REQUIRED_VARS $(USE.PROJECT)_LIBRARIES $(USE.PROJECT)_INCLUDE_DIRS
)
mark_as_advanced(
$(USE.PROJECT)_FOUND
$(USE.PROJECT)_LIBRARIES $(USE.PROJECT)_INCLUDE_DIRS
)
. else
find_program (
$(USE.PROJECT)_BIN
$(use.project)
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
$(USE.PROJECT)
REQUIRED_VARS $(USE.PROJECT)_BIN
)
mark_as_advanced(
$(USE.PROJECT)_FOUND
)
. endif
$(project.GENERATED_WARNING_HEADER:)
.endfor
.close
.
.# CI testing for using cmake
.directory.create ('builds/cmake')
.output "builds/cmake/ci_build.sh"
#!/usr/bin/env bash
set -e
# Set this to enable verbose profiling
[ -n "${CI_TIME-}" ] || CI_TIME=""
case "$CI_TIME" in
[Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
CI_TIME="time -p " ;;
[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
CI_TIME="" ;;
esac
configure_tracing() {
# Set this to enable verbose tracing
[ -n "${CI_TRACE-}" ] || CI_TRACE="no"
case "$CI_TRACE" in
[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
set +x ;;
[Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
set -x ;;
esac
}
configure_tracing
fold_start() {
set +x
echo -e "travis_fold:start:$1\\033[33;1m$2\\033[0m"
configure_tracing
}
fold_end() {
set +x
echo -e "\\ntravis_fold:end:$1\\r"
configure_tracing
}
LANG=C
LC_ALL=C
export LANG LC_ALL
if [ -d "./tmp" ]; then
# Proto installation area for this project and its deps
rm -rf ./tmp
fi
if [ -d "./tmp-deps" ]; then
# Checkout/unpack and build area for dependencies
rm -rf ./tmp-deps
fi
mkdir -p tmp tmp-deps
BUILD_PREFIX=$PWD/tmp
# Use tools from prerequisites we might have built
PATH="${BUILD_PREFIX}/sbin:${BUILD_PREFIX}/bin:${PATH}"
export PATH
CONFIG_OPTS=()
CONFIG_OPTS+=("CFLAGS=-I${BUILD_PREFIX}/include")
CONFIG_OPTS+=("CPPFLAGS=-I${BUILD_PREFIX}/include")
CONFIG_OPTS+=("CXXFLAGS=-I${BUILD_PREFIX}/include")
CONFIG_OPTS+=("LDFLAGS=-L${BUILD_PREFIX}/lib")
CONFIG_OPTS+=("PKG_CONFIG_PATH=${BUILD_PREFIX}/lib/pkgconfig")
CONFIG_OPTS+=("--prefix=${BUILD_PREFIX}")
CONFIG_OPTS+=("--with-docs=no")
if [ -z "${CI_CONFIG_QUIET-}" ] || [ "${CI_CONFIG_QUIET-}" = yes ] || [ "${CI_CONFIG_QUIET-}" = true ]; then
CONFIG_OPTS+=("--quiet")
fi
CMAKE_OPTS=()
CMAKE_OPTS+=("-DCMAKE_INSTALL_PREFIX:PATH=${BUILD_PREFIX}")
CMAKE_OPTS+=("-DCMAKE_PREFIX_PATH:PATH=${BUILD_PREFIX}")
CMAKE_OPTS+=("-DCMAKE_LIBRARY_PATH:PATH=${BUILD_PREFIX}/lib")
CMAKE_OPTS+=("-DCMAKE_INCLUDE_PATH:PATH=${BUILD_PREFIX}/include")
if [ "$CLANG_FORMAT" != "" ] ; then
CMAKE_OPTS+=("-DCLANG_FORMAT=${CLANG_FORMAT}")
fi
# Clone and build dependencies, if not yet installed to Travis env as DEBs
# or MacOS packages; other OSes are not currently supported by Travis cloud
[ -z "$CI_TIME" ] || echo "`date`: Starting build of dependencies (if any)..."
.for use where defined (use.tarball)
# Start of recipe for dependency: $(use.project)
fold_start dependency.$(use.project) "Install dependency $(use.project)"
if \
. if defined (use.debian_name)
. if !(use.debian_name = '')
\! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.debian_name) >/dev/null 2>&1) || \\
. endif
. elsif defined (use.libname)
\! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.libname)-dev >/dev/null 2>&1) || \\
. else
\! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.project)-dev >/dev/null 2>&1) || \\
. endif
(command -v brew >/dev/null 2>&1 && brew ls --versions $(use.project) >/dev/null 2>&1)) \\
; then
BASE_PWD=${PWD}
cd tmp-deps
wget $(use.tarball)
tar -xzf \$(basename "$(use.tarball)")
cd \$(basename "$(use.tarball)" .tar.gz) || exit \$?
. if defined (use.builddir)
cd ./$(use.builddir)
. endif
CCACHE_BASEDIR=${PWD}
export CCACHE_BASEDIR
if [ -e autogen.sh ]; then
$CI_TIME ./autogen.sh 2> /dev/null
fi
if [ -e buildconf ]; then
$CI_TIME ./buildconf 2> /dev/null
fi
if [ ! -e autogen.sh ] && [ ! -e buildconf ] && [ ! -e ./configure ] && [ -s ./configure.ac ]; then
$CI_TIME libtoolize --copy --force && \\
$CI_TIME aclocal -I . && \\
$CI_TIME autoheader && \\
$CI_TIME automake --add-missing --copy && \\
$CI_TIME autoconf || \\
$CI_TIME autoreconf -fiv
fi
. if count(use.add_config_opts) > 0
( # Custom additional options for $(use.project)
. for use.add_config_opts as add_cfgopt
CONFIG_OPTS+=("$(add_cfgopt)")
. endfor
$CI_TIME ./configure "${CONFIG_OPTS[@]}"
)
. else
if [ -e ./configure ]; then
$CI_TIME ./configure "${CONFIG_OPTS[@]}"
else
mkdir build
cd build
$CI_TIME cmake .. -DCMAKE_INSTALL_PREFIX=$BUILD_PREFIX -DCMAKE_PREFIX_PATH=$BUILD_PREFIX
fi
. endif
if [ -e ./configure ]; then
$CI_TIME make -j4
$CI_TIME make install
else
$CI_TIME cmake --build . --config Release --target install
fi
cd "${BASE_PWD}"
. if use.optional
CONFIG_OPTS+=("--with-$(use.libname)=yes")
. endif
fi
fold_end dependency.$(use.project)
.endfor
.for use where defined (use.repository) & ! defined (use.tarball)
# Start of recipe for dependency: $(use.project)
fold_start dependency.$(use.project) "Install dependency $(use.project)"
. if defined (use.debian_name)
if ! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.debian_name) >/dev/null 2>&1) || \\
. elsif defined (use.libname)
if ! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.libname)-dev >/dev/null 2>&1) || \\
. else
if ! ((command -v dpkg >/dev/null 2>&1 && dpkg -s $(use.project)-dev >/dev/null 2>&1) || \\
. endif
(command -v brew >/dev/null 2>&1 && brew ls --versions $(use.project) >/dev/null 2>&1)); then
BASE_PWD=${PWD}
cd tmp-deps
. if defined (use.release)
$CI_TIME git clone --quiet --depth 1 -b $(use.release:) $(use.repository) $(use.project)
. else
$CI_TIME git clone --quiet --depth 1 $(use.repository) $(use.project)
. endif
. if defined (use.builddir)
cd $(use.project)/$(use.builddir)
. else
cd $(use.project)
. endif
CCACHE_BASEDIR=${PWD}
export CCACHE_BASEDIR
git --no-pager log --oneline -n1
if [ -e autogen.sh ]; then
$CI_TIME ./autogen.sh 2> /dev/null
fi
if [ -e buildconf ]; then
$CI_TIME ./buildconf 2> /dev/null
fi
if [ ! -e autogen.sh ] && [ ! -e buildconf ] && [ ! -e ./configure ] && [ -s ./configure.ac ]; then
$CI_TIME libtoolize --copy --force && \\
$CI_TIME aclocal -I . && \\
$CI_TIME autoheader && \\
$CI_TIME automake --add-missing --copy && \\
$CI_TIME autoconf || \\