forked from kisli/vmime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1140 lines (876 loc) · 28 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 configuration file for VMime
#
# Usage:
#
# . 'cmake -LH' to list build settings variable
#
# . 'cmake -G <generator>' to generate makefiles for a build system
# eg. cmake -G "Unix Makefiles"
#
# For more information, please visit:
# http://www.cmake.org
#
CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
INCLUDE(cmake/Utils.cmake)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckIncludeFileCXX)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckTypeSize)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(GNUInstallDirs)
INCLUDE(cmake/HunterGate.cmake)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.19.121.tar.gz"
SHA1 "4cf307799ec543084dd5bada002feea066e8c203"
)
# CMake configuration
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build/lib)
SET(CMAKE_VERBOSE_MAKEFILE ON)
# Package version number
SET(VMIME_VERSION_MAJOR 0)
SET(VMIME_VERSION_MINOR 9)
SET(VMIME_VERSION_PATCH 2)
SET(VMIME_VERSION ${VMIME_VERSION_MAJOR}.${VMIME_VERSION_MINOR}.${VMIME_VERSION_PATCH})
# Project
PROJECT(VMIME VERSION ${VMIME_VERSION})
# Hunter package
hunter_add_package(OpenSSL)
SET(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
SET(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
SET(INCLUDE_INSTALL_DIR "include")
SET(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
SET(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
SET(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
SET(NAMESPACE "${PROJECT_NAME}::")
INCLUDE(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${VERSION_CONFIG}" COMPATIBILITY SameMajorVersion
)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in"
"${PROJECT_CONFIG}"
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
)
# API version number (libtool)
#
# Increment this number only immediately before a public release.
# This is independent from package version number.
#
# See: http://semver.org/
#
# . Implementation changed (eg. bug/security fix): REVISION++
# . Interfaces added/removed/changed: CURRENT++, REVISION=0
# . Interfaces added (upward-compatible changes): AGE++
# . Interfaces removed: AGE=0
SET(VMIME_API_VERSION_CURRENT 1)
SET(VMIME_API_VERSION_REVISION 0)
SET(VMIME_API_VERSION_AGE 0)
SET(VMIME_VERSION ${VMIME_VERSION_MAJOR}.${VMIME_VERSION_MINOR}.${VMIME_VERSION_MICRO})
SET(VMIME_API_VERSION ${VMIME_API_VERSION_CURRENT}.${VMIME_API_VERSION_REVISION}.${VMIME_API_VERSION_AGE})
##############################################################################
# VMime Library
# Set base name
SET(VMIME_LIBRARY_NAME vmime)
# Source files
FILE(
GLOB_RECURSE
VMIME_LIBRARY_SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/vmime/*.cpp
)
FILE(
GLOB_RECURSE
VMIME_LIBRARY_INCLUDE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/vmime/*.hpp
)
LIST(APPEND VMIME_LIBRARY_GENERATED_INCLUDE_FILES "${CMAKE_BINARY_DIR}/src/vmime/config.hpp")
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR} # for "contrib/"
${CMAKE_CURRENT_SOURCE_DIR}/src # for "vmime/
${CMAKE_BINARY_DIR}/src # for "config.hpp"
${CMAKE_BINARY_DIR}/src/vmime # for "config.hpp"
)
INCLUDE(GenerateExportHeader)
ADD_COMPILER_EXPORT_FLAGS()
# Shared library
OPTION(
VMIME_BUILD_SHARED_LIBRARY
"Build shared library"
ON
)
IF(VMIME_BUILD_SHARED_LIBRARY)
ADD_LIBRARY(
${VMIME_LIBRARY_NAME}
SHARED
${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
)
TARGET_INCLUDE_DIRECTORIES(${VMIME_LIBRARY_NAME} PUBLIC
$<INSTALL_INTERFACE:include>
)
GENERATE_EXPORT_HEADER(
${VMIME_LIBRARY_NAME}
BASE_NAME VMIME
STATIC_DEFINE VMIME_STATIC
EXPORT_FILE_NAME export-shared.hpp
)
FILE(
COPY
${CMAKE_CURRENT_BINARY_DIR}/export-shared.hpp
DESTINATION
${CMAKE_BINARY_DIR}/src/vmime
)
LIST(APPEND VMIME_LIBRARY_GENERATED_INCLUDE_FILES "${CMAKE_BINARY_DIR}/src/vmime/export-shared.hpp")
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}
PROPERTIES
VERSION "${VMIME_API_VERSION}"
SOVERSION "${VMIME_API_VERSION_CURRENT}"
COMPILE_FLAGS -DVMIME_SHARED
)
ENDIF()
# Static library
#
# Note: cannot have two targets with the same name so the static version has
# '-static' appended and then the name of the output file is set separately.
OPTION(
VMIME_BUILD_STATIC_LIBRARY
"Build static library"
ON
)
IF(VMIME_BUILD_STATIC_LIBRARY)
ADD_LIBRARY(
${VMIME_LIBRARY_NAME}-static
STATIC
${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
)
TARGET_INCLUDE_DIRECTORIES(${VMIME_LIBRARY_NAME}-static PUBLIC
$<INSTALL_INTERFACE:include>
)
GENERATE_EXPORT_HEADER(
${VMIME_LIBRARY_NAME}-static
BASE_NAME VMIME
STATIC_DEFINE VMIME_STATIC
EXPORT_FILE_NAME export-static.hpp
)
FILE(
COPY
${CMAKE_CURRENT_BINARY_DIR}/export-static.hpp
DESTINATION
${CMAKE_BINARY_DIR}/src/vmime
)
LIST(APPEND VMIME_LIBRARY_GENERATED_INCLUDE_FILES "${CMAKE_BINARY_DIR}/src/vmime/export-static.hpp")
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}-static
PROPERTIES
OUTPUT_NAME ${VMIME_LIBRARY_NAME}
COMPILE_FLAGS -DVMIME_STATIC
)
ENDIF()
# Ensure at least one type of library (either shared or static) is build
IF(NOT(VMIME_BUILD_SHARED_LIBRARY OR VMIME_BUILD_STATIC_LIBRARY))
MESSAGE(FATAL_ERROR "You should select at least one library to build (either VMIME_BUILD_SHARED_LIBRARY or VMIME_BUILD_STATIC_LIBRARY must be set to YES.")
ENDIF()
# These next two lines are required but it is unclear exactly what they do.
# The CMake FAQ mentions they are necessary and it does not work otherwise.
IF(VMIME_BUILD_SHARED_LIBRARY)
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()
IF(VMIME_BUILD_STATIC_LIBRARY)
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
# Installation of libraries
IF(VMIME_BUILD_SHARED_LIBRARY)
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
)
ENDIF()
IF(VMIME_BUILD_STATIC_LIBRARY)
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}-static
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
)
ENDIF()
# Installation of header files
INSTALL_HEADERS_WITH_DIRECTORY(VMIME_LIBRARY_INCLUDE_FILES headers "${CMAKE_CURRENT_SOURCE_DIR}/src/")
INSTALL_HEADERS_WITH_DIRECTORY(VMIME_LIBRARY_GENERATED_INCLUDE_FILES headers "${CMAKE_BINARY_DIR}/src")
#INSTALL(
# FILES ${VMIME_LIBRARY_INCLUDE_FILES}
# DESTINATION include
# COMPONENT headers
#)
INSTALL(
FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)
INSTALL(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${NAMESPACE}"
DESTINATION "${CONFIG_INSTALL_DIR}")
##############################################################################
# Tests
OPTION(
VMIME_BUILD_TESTS
"Build unit tests (this will create a 'run-tests' binary)"
OFF
)
IF(VMIME_BUILD_TESTS)
ENABLE_TESTING()
INCLUDE(cmake/FindCppUnit.cmake)
INCLUDE_DIRECTORIES(${CPPUNIT_INCLUDE_DIR})
FILE(
GLOB_RECURSE
VMIME_TESTS_SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/tests/*Test.cpp
)
ADD_LIBRARY(
test-runner
${CMAKE_CURRENT_SOURCE_DIR}/tests/testRunner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/testUtils.cpp
)
# Build one file for each test
FOREACH(VMIME_TEST_SRC_FILE ${VMIME_TESTS_SRC_FILES})
# "/path/to/vmime/tests/module/testFile.cpp" --> "module_testFile"
GET_FILENAME_COMPONENT(VMIME_TEST_SRC_PATH "${VMIME_TEST_SRC_FILE}" PATH)
STRING(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" VMIME_TEST_SRC_PATH "${VMIME_TEST_SRC_PATH}")
GET_FILENAME_COMPONENT(VMIME_TEST_NAME "${VMIME_TEST_SRC_FILE}" NAME_WE)
SET(VMIME_TEST_NAME "${VMIME_TEST_SRC_PATH}/${VMIME_TEST_NAME}")
STRING(REPLACE "/" "_" VMIME_TEST_NAME "${VMIME_TEST_NAME}")
STRING(REPLACE "_tests_" "" VMIME_TEST_NAME "${VMIME_TEST_NAME}")
ADD_EXECUTABLE(
${VMIME_TEST_NAME}
${VMIME_TEST_SRC_FILE}
)
TARGET_LINK_LIBRARIES(
${VMIME_TEST_NAME}
${VMIME_LIBRARY_NAME}
${CPPUNIT_LIBRARY} test-runner
)
ADD_DEPENDENCIES(
${VMIME_TEST_NAME}
${VMIME_LIBRARY_NAME}
)
ADD_TEST(
${VMIME_TEST_NAME}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${VMIME_TEST_NAME}
)
ENDFOREACH()
# Build one file for all tests
ADD_EXECUTABLE(
"run-tests"
${VMIME_TESTS_SRC_FILES}
)
TARGET_LINK_LIBRARIES(
"run-tests"
${VMIME_LIBRARY_NAME}
${CPPUNIT_LIBRARY} test-runner
)
ADD_DEPENDENCIES(
"run-tests"
${VMIME_LIBRARY_NAME}
)
ENDIF()
##############################################################################
# Examples
OPTION(
VMIME_BUILD_SAMPLES
"Build samples (in 'examples' directory)"
OFF
)
##############################################################################
# Packaging / Distribution
# Package information
SET(VMIME_PACKAGE_NAME ${VMIME_LIBRARY_NAME})
SET(VMIME_PACKAGE_VERSION ${VMIME_VERSION})
SET(VMIME_PACKAGE_CONTACT "Vincent Richard <[email protected]>")
SET(VMIME_PACKAGE_DESCRIPTION "VMime C++ Mail Library (http://www.vmime.org)")
SET(CPACK_PACKAGE_NAME "${VMIME_PACKAGE_NAME}")
SET(CPACK_PACKAGE_CONTACT "${VMIME_PACKAGE_CONTACT}")
SET(CPACK_PACKAGE_DESCRIPTION "${VMIME_PACKAGE_DESCRIPTION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION}")
SET(CPACK_PACKAGE_VERSION "${VMIME_PACKAGE_VERSION}")
# Package settings
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/COPYING)
IF(APPLE)
# CPack/PackageManager won't allow file without recognized extension
# to be used as license file.
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/COPYING" "${CMAKE_BINARY_DIR}/COPYING.txt" COPYONLY)
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING.txt")
ELSE()
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
ENDIF(APPLE)
SET(CPACK_SOURCE_GENERATOR TGZ)
SET(CPACK_SOURCE_IGNORE_FILES "\\\\.git;~$;build/")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
# Set components
SET(CPACK_COMPONENTS_ALL sharedlibs staticlibs headers)
SET(CPACK_COMPONENT_SHAREDLIBS_DISPLAY_NAME "Shared libraries")
SET(CPACK_COMPONENT_SHAREDLIBS_DESCRIPTION
"Shared library for general use.")
SET(CPACK_COMPONENT_STATICLIBS_DISPLAY_NAME "Static libraries")
SET(CPACK_COMPONENT_STATICLIBS_DESCRIPTION
"Static library, good if you want to embed VMime in your application.")
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C/C++ header files.")
SET(CPACK_COMPONENT_SHAREDLIBS_GROUP "Development")
SET(CPACK_COMPONENT_STATICLIBS_GROUP "Development")
SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "")
# Make a target "dist" to generate tarball
SET(ARCHIVE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
ADD_CUSTOM_TARGET(
dist
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
| bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
# PkgConfig
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
SET(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/vmime)
SET(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
SET(VMIME_PKGCONFIG_LIBS "")
SET(VMIME_PKGCONFIG_CFLAGS "")
SET(VMIME_PKGCONFIG_REQUIRES "")
##############################################################################
# Build type
IF(NOT CMAKE_BUILD_TYPE)
SET(
CMAKE_BUILD_TYPE
"Debug"
CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
ENDIF(NOT CMAKE_BUILD_TYPE)
# Set a default build type for single-configuration
# CMake generators if no build type is set.
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF()
# Debug build
MESSAGE("-- Build type: ${CMAKE_BUILD_TYPE}")
IF(${CMAKE_BUILD_TYPE} STREQUAL Debug)
ADD_DEFINITIONS(-DDEBUG)
ENDIF(${CMAKE_BUILD_TYPE} STREQUAL Debug)
IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
SET(VMIME_DEBUG 1)
ELSE()
SET(VMIME_DEBUG 0)
ENDIF()
##############################################################################
# Test endianness and basic type sizes
INCLUDE(TestBigEndian)
TEST_BIG_ENDIAN(BIGENDIAN)
IF(BIGENDIAN EQUAL 0)
set(VMIME_BYTE_ORDER_BIG_ENDIAN 0)
set(VMIME_BYTE_ORDER_LITTLE_ENDIAN 1)
ELSE(BIGENDIAN EQUAL 0)
SET(VMIME_BYTE_ORDER_BIG_ENDIAN 1)
SET(VMIME_BYTE_ORDER_LITTLE_ENDIAN 0)
ENDIF(BIGENDIAN EQUAL 0)
CHECK_INCLUDE_FILE_CXX(cstdint VMIME_HAVE_CSTDINT)
CHECK_TYPE_SIZE("char" SIZEOF_CHAR)
CHECK_TYPE_SIZE("short" SIZEOF_SHORT)
CHECK_TYPE_SIZE("int" SIZEOF_INT)
CHECK_TYPE_SIZE("long" SIZEOF_LONG)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
CHECK_TYPE_SIZE("__int64" SIZEOF___INT64)
SET(CMAKE_EXTRA_INCLUDE_FILES cstdint)
CHECK_TYPE_SIZE("int64_t" SIZEOF_INT64_T)
SET(CMAKE_EXTRA_INCLUDE_FILES)
IF(SIZEOF_CHAR EQUAL 1)
SET(VMIME_8BIT_TYPE "char")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 8-bit type")
ENDIF()
IF(SIZEOF_INT EQUAL 2)
SET(VMIME_16BIT_TYPE "int")
ELSE()
IF(SIZEOF_SHORT EQUAL 2)
SET(VMIME_16BIT_TYPE "short")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 16-bit type")
ENDIF()
ENDIF()
IF(SIZEOF_INT EQUAL 4)
SET(VMIME_32BIT_TYPE "int")
ELSE()
IF(SIZEOF_LONG EQUAL 4)
SET(VMIME_32BIT_TYPE "long")
ELSE()
IF(SIZEOF_LONG_LONG EQUAL 4)
SET(VMIME_32BIT_TYPE "long long")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 32-bit type")
ENDIF()
ENDIF()
ENDIF()
IF(SIZEOF_INT EQUAL 8)
SET(VMIME_64BIT_TYPE "int")
ELSE()
IF(SIZEOF_LONG EQUAL 8)
SET(VMIME_64BIT_TYPE "long")
ELSE()
IF(SIZEOF_LONG_LONG EQUAL 8)
SET(VMIME_64BIT_TYPE "long long")
ELSE()
IF(SIZEOF_INT64_T EQUAL 8)
SET(VMIME_64BIT_TYPE "int64_t")
ELSE()
IF(SIZEOF___INT64 EQUAL 8)
SET(VMIME_64BIT_TYPE "__int64")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 64-bit type")
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDIF()
CHECK_TYPE_SIZE(size_t VMIME_HAVE_SIZE_T)
##############################################################################
# Sendmail path
FOREACH (SENDMAIL_PATH /usr/sbin/sendmail /usr/lib/sendmail /usr/bin/sendmail /bin/sendmail /var/qmail/bin/qmail-inject /bin/cgimail)
IF(EXISTS ${SENDMAIL_PATH})
MESSAGE(STATUS "Sendmail binary found at ${SENDMAIL_PATH}")
SET(VMIME_DEFAULT_SENDMAIL_PATH ${SENDMAIL_PATH})
ENDIF()
ENDFOREACH(SENDMAIL_PATH)
SET(
VMIME_SENDMAIL_PATH
${VMIME_DEFAULT_SENDMAIL_PATH}
CACHE
STRING
"Specifies the path to sendmail binary"
)
##############################################################################
# Messaging features
# Module
OPTION(
VMIME_HAVE_MESSAGING_FEATURES
"Enable messaging features (connection to IMAP, POP3, SMTP...)"
ON
)
# Protocols
OPTION(
VMIME_HAVE_MESSAGING_PROTO_POP3
"Enable POP3 protocol"
ON
)
OPTION(
VMIME_HAVE_MESSAGING_PROTO_SMTP
"Enable SMTP protocol"
ON
)
OPTION(
VMIME_HAVE_MESSAGING_PROTO_IMAP
"Enable IMAP protocol"
ON
)
OPTION(
VMIME_HAVE_MESSAGING_PROTO_MAILDIR
"Enable Maildir protocol"
ON
)
OPTION(
VMIME_HAVE_MESSAGING_PROTO_SENDMAIL
"Enable Sendmail protocol"
ON
)
##############################################################################
# File-system features
OPTION(
VMIME_HAVE_FILESYSTEM_FEATURES
"Enable file-system features (required for file attachments and Maildir)"
ON
)
##############################################################################
# SASL support
INCLUDE(cmake/FindGSasl.cmake)
OPTION(
VMIME_HAVE_SASL_SUPPORT
"Enable SASL support (requires GNU SASL library)"
ON
)
IF(VMIME_HAVE_SASL_SUPPORT)
INCLUDE_DIRECTORIES(
${INCLUDE_DIRECTORIES}
${GSASL_INCLUDE_DIR}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GSASL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_REQUIRES "${VMIME_PKGCONFIG_REQUIRES} libgsasl")
ENDIF()
##############################################################################
# SSL/TLS support
INCLUDE(FindGnuTLS)
INCLUDE(FindOpenSSL)
SET(CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARY}")
CHECK_FUNCTION_EXISTS(gnutls_priority_set_direct VMIME_HAVE_GNUTLS_PRIORITY_FUNCS)
OPTION(
VMIME_HAVE_TLS_SUPPORT
"SSL/TLS support (requires either GNU TLS or OpenSSL library)"
ON
)
SET(
VMIME_TLS_SUPPORT_LIB
"gnutls"
CACHE
STRING
"Library to use for SSL/TLS conversion"
)
SET_PROPERTY(
CACHE
VMIME_TLS_SUPPORT_LIB
PROPERTY STRINGS gnutls openssl
)
IF(VMIME_HAVE_TLS_SUPPORT)
IF(VMIME_TLS_SUPPORT_LIB STREQUAL "gnutls")
INCLUDE_DIRECTORIES(
${INCLUDE_DIRECTORIES}
${GNUTLS_INCLUDE_DIR}
)
LINK_DIRECTORIES(
${LINK_DIRECTORIES}
${GNUTLS_LIBRARY_DIRS}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GNUTLS_LIBRARY}
)
ENDIF()
SET(VMIME_PKGCONFIG_REQUIRES "${VMIME_PKGCONFIG_REQUIRES} gnutls")
SET(VMIME_TLS_SUPPORT_LIB_IS_GNUTLS "ON")
SET(VMIME_TLS_SUPPORT_LIB_IS_OPENSSL "OFF")
ELSEIF(VMIME_TLS_SUPPORT_LIB STREQUAL "openssl")
INCLUDE_DIRECTORIES(
${INCLUDE_DIRECTORIES}
${OPENSSL_INCLUDE_DIR}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${OPENSSL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_REQUIRES "${VMIME_PKGCONFIG_REQUIRES} openssl")
SET(VMIME_TLS_SUPPORT_LIB_IS_GNUTLS "OFF")
SET(VMIME_TLS_SUPPORT_LIB_IS_OPENSSL "ON")
ELSE()
MESSAGE(FATAL_ERROR "TLS support is enabled, but no TLS/SSL library was selected/found")
ENDIF()
ENDIF(VMIME_HAVE_TLS_SUPPORT)
##############################################################################
# Charset conversion library
INCLUDE(cmake/FindIconv.cmake)
INCLUDE(cmake/FindICU.cmake)
FIND_PACKAGE(ICU QUIET)
IF(ICU_LIBRARIES)
SET(VMIME_CHARSETCONV_LIB_DETECTED "icu")
ELSEIF(ICONV_FOUND)
SET(VMIME_CHARSETCONV_LIB_DETECTED "iconv")
ELSEIF(WIN32)
SET(VMIME_CHARSETCONV_LIB_DETECTED "win")
ENDIF()
SET(
VMIME_CHARSETCONV_LIB
"${VMIME_CHARSETCONV_LIB_DETECTED}"
CACHE
STRING
"Library to use for charset conversion"
)
SET_PROPERTY(
CACHE
VMIME_CHARSETCONV_LIB
PROPERTY STRINGS win iconv icu
)
IF(VMIME_CHARSETCONV_LIB STREQUAL "iconv")
INCLUDE_DIRECTORIES(
${INCLUDE_DIRECTORIES}
${ICONV_INCLUDE_DIR}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${ICONV_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${ICONV_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} -I${ICONV_INCLUDE_DIR}")
SET(VMIME_CHARSETCONV_LIB_IS_ICONV "ON")
SET(VMIME_CHARSETCONV_LIB_IS_ICU "OFF")
SET(VMIME_CHARSETCONV_LIB_IS_WIN "OFF")
ELSEIF(VMIME_CHARSETCONV_LIB STREQUAL "icu")
INCLUDE_DIRECTORIES(
${INCLUDE_DIRECTORIES}
${ICU_INCLUDE_DIRS}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${ICU_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${ICU_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} -I${ICU_INCLUDE_DIRS}")
SET(VMIME_CHARSETCONV_LIB_IS_ICONV "OFF")
SET(VMIME_CHARSETCONV_LIB_IS_ICU "ON")
SET(VMIME_CHARSETCONV_LIB_IS_WIN "OFF")
ELSEIF(VMIME_CHARSETCONV_LIB STREQUAL "win")
MESSAGE(WARNING "*** ICU or iconv library should always be preferred"
" over MultiByteToWideChar/WideCharToMultiByte on Windows, as"
" error handling is very poor, and there is no streaming support.")
SET(VMIME_CHARSETCONV_LIB_IS_ICONV "OFF")
SET(VMIME_CHARSETCONV_LIB_IS_ICU "OFF")
SET(VMIME_CHARSETCONV_LIB_IS_WIN "ON")
ELSE()
MESSAGE(FATAL_ERROR "No charset conversion library was selected/found")
ENDIF()
##############################################################################
# Language features
# C++11
INCLUDE(cmake/cmake-cxx11/Modules/CheckCXX11Features.cmake)
# Smart pointers
#
# If a C++11-compliant compiler is available and supports std::shared_ptr<>,
# use the standard implementation. Else, use boost::shared_ptr<>.
# In any case, let the user override the choice with VMIME_SHARED_PTR_USE_CXX
# and VMIME_SHARED_PTR_USE_BOOST variables.
CHECK_CXX_SOURCE_COMPILES(
"
#include <memory>
struct A { int foo; };
int main() {
std::shared_ptr <A> a = std::make_shared <A>();
return 0;
}
"
VMIME_HAS_CXX11_SHARED_PTR
)
IF(NOT VMIME_SHARED_PTR_USE_CXX AND NOT VMIME_SHARED_PTR_USE_BOOST)
IF(CXX11_COMPILER_FLAGS AND VMIME_HAS_CXX11_SHARED_PTR)
# If std::shared_ptr<> is available, use it by default
SET(VMIME_SHARED_PTR_USE_CXX_DEFAULT ON)
SET(VMIME_SHARED_PTR_USE_BOOST_DEFAULT OFF)
ELSE()
# Else, set default to boost::shared_ptr<>
SET(VMIME_SHARED_PTR_USE_CXX_DEFAULT OFF)
SET(VMIME_SHARED_PTR_USE_BOOST_DEFAULT ON)
ENDIF()
ENDIF()
OPTION(
VMIME_SHARED_PTR_USE_CXX
"Use standard std::shared_ptr<> (requires a C++11 compiler)"
${VMIME_SHARED_PTR_USE_CXX_DEFAULT}
)
OPTION(
VMIME_SHARED_PTR_USE_BOOST
"Use boost::shared_ptr<> (requires Boost)"
${VMIME_SHARED_PTR_USE_BOOST_DEFAULT}
)
IF(VMIME_SHARED_PTR_USE_CXX AND VMIME_SHARED_PTR_USE_BOOST)
MESSAGE(FATAL_ERROR "Options VMIME_SHARED_PTR_USE_CXX and VMIME_SHARED_PTR_USE_BOOST are mutually exclusive (select one or the other, but not both!)")
ENDIF()
IF(VMIME_SHARED_PTR_USE_CXX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
ENDIF()
MESSAGE(STATUS "Checking support for shared_ptr<>: built-in (C++11)")
ELSEIF(VMIME_SHARED_PTR_USE_BOOST)
# Depends on Boost library if C++11 is not supported
FIND_PACKAGE(Boost)
IF(Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
ELSE()
MESSAGE(FATAL_ERROR "Boost library is required for shared_ptr<>, unless you compile using C++11")
ENDIF()
MESSAGE(STATUS "Checking support for shared_ptr<>: boost library")
ELSE()
MESSAGE(FATAL_ERROR "No implementation for shared_ptr<> was selected/found")
ENDIF()
##############################################################################
# Platform
SET(VMIME_PLATFORM_IS_POSIX OFF)
SET(VMIME_PLATFORM_IS_WINDOWS OFF)
IF(WIN32)
SET(VMIME_PLATFORM_IS_WINDOWS ON)
ELSE()
SET(VMIME_PLATFORM_IS_POSIX ON)
ENDIF()
##############################################################################
# Platform-specific checks
CHECK_FUNCTION_EXISTS(gmtime_s VMIME_HAVE_GMTIME_S)
CHECK_FUNCTION_EXISTS(gmtime_r VMIME_HAVE_GMTIME_R)
CHECK_FUNCTION_EXISTS(localtime_s VMIME_HAVE_LOCALTIME_S)
CHECK_FUNCTION_EXISTS(localtime_r VMIME_HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS(strcpy_s VMIME_HAVE_STRCPY_S)
##############################################################################
# Windows-specific checks
IF(WIN32)
# Winsock
CHECK_LIBRARY_EXISTS("ws2_32" getch "${CMAKE_LIBRARY_PATH}" VMIME_HAVE_LIBWS2_32)
IF(VMIME_HAVE_LIBWS2_32)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"ws2_32"
)
ELSE()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} -lws2_32")
ENDIF()
ENDIF()
# MLang
CHECK_INCLUDE_FILES(Mlang.h VMIME_HAVE_MLANG_H)
CHECK_LIBRARY_EXISTS("mlang" ConvertINetString "${CMAKE_LIBRARY_PATH}" VMIME_HAVE_MLANG_LIB)
IF(VMIME_HAVE_MLANG_H)
IF(VMIME_HAVE_MLANG_LIB)
SET(VMIME_HAVE_MLANG ON)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"mlang"
)
ENDIF()
ENDIF()
ENDIF()
ENDIF()
##############################################################################
# POSIX-specific checks
CHECK_FUNCTION_EXISTS(getaddrinfo VMIME_HAVE_GETADDRINFO)
CHECK_FUNCTION_EXISTS(getnameinfo VMIME_HAVE_GETNAMEINFO)
CHECK_FUNCTION_EXISTS(gettid VMIME_HAVE_GETTID)
CHECK_FUNCTION_EXISTS(syscall VMIME_HAVE_SYSCALL)
CHECK_SYMBOL_EXISTS(SYS_gettid sys/syscall.h VMIME_HAVE_SYSCALL_GETTID)
CHECK_SYMBOL_EXISTS(getthrid unistd.h VMIME_HAVE_GETTHRID)
CHECK_SYMBOL_EXISTS(SO_KEEPALIVE sys/socket.h VMIME_HAVE_SO_KEEPALIVE)
CHECK_SYMBOL_EXISTS(SO_NOSIGPIPE sys/socket.h VMIME_HAVE_SO_NOSIGPIPE)
CHECK_SYMBOL_EXISTS(MSG_NOSIGNAL sys/socket.h VMIME_HAVE_MSG_NOSIGNAL)
CHECK_SYMBOL_EXISTS(strerror_r string.h VMIME_HAVE_STRERROR_R)
FIND_PACKAGE(Threads)