forked from noloader/cryptopp-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1322 lines (1137 loc) · 54.7 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
# Please ensure your changes or patch meets minimum requirements.
# The minimum requirements are 2.8.6. It roughly equates to
# Ubuntu 14.05 LTS or Solaris 11.3. Please do not check in something
# for 3.5.0 or higher because it will break LTS operating systems
# and a number of developer boards used for testing. To test your
# changes, please set up a Ubuntu 14.05 LTS system.
# Should we be setting things like this? We are not a C project
# so nothing should be done with the C compiler. But there is
# no reliable way to tell CMake we are C++.
# Cannot set this... Breaks Linux PowerPC with Clang:
# SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
# # error "The CMAKE_C_COMPILER is set to a C++ compiler"
if(NOT DEFINED cryptopp_DISPLAY_CMAKE_SUPPORT_WARNING)
set(cryptopp_DISPLAY_CMAKE_SUPPORT_WARNING 1)
endif()
if(cryptopp_DISPLAY_CMAKE_SUPPORT_WARNING)
message( STATUS
"*************************************************************************\n"
"The Crypto++ library does not officially support CMake. CMake support is a\n"
"community effort, and the library works with the folks using CMake to help\n"
"improve it. If you find an issue then please fix it or report it at\n"
"https://github.com/noloader/cryptopp-cmake.\n"
"-- *************************************************************************"
)
endif()
# Print useful information
message( STATUS "CMake version ${CMAKE_VERSION}" )
message( STATUS "System ${CMAKE_SYSTEM_NAME}" )
message( STATUS "Processor ${CMAKE_SYSTEM_PROCESSOR}" )
cmake_minimum_required(VERSION 2.8.6)
if (${CMAKE_VERSION} VERSION_LESS "3.0.0")
project(cryptopp)
set(cryptopp_VERSION_MAJOR 8)
set(cryptopp_VERSION_MINOR 6)
set(cryptopp_VERSION_PATCH 0)
else ()
cmake_policy(SET CMP0048 NEW)
project(cryptopp VERSION 8.6.0)
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.1.0")
cmake_policy(SET CMP0054 NEW)
endif ()
endif ()
# Need to set SRC_DIR manually after removing the Python library code.
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Make RelWithDebInfo the default (it does e.g. add '-O2 -g -DNDEBUG' for GNU)
# If not in multi-configuration environments, no explicit build type or CXX
# flags are set by the user and if we are the root CMakeLists.txt file.
if (NOT CMAKE_CONFIGURATION_TYPES AND
NOT CMAKE_NO_BUILD_TYPE AND
NOT CMAKE_BUILD_TYPE AND
NOT CMAKE_CXX_FLAGS AND
CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif ()
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
# We now carry around test programs. test_cxx.cpp is the default C++ one.
# Also see https://github.com/weidai11/cryptopp/issues/741.
set(TEST_PROG_DIR ${SRC_DIR}/TestPrograms)
set(TEST_CXX_FILE ${TEST_PROG_DIR}/test_cxx.cpp)
#============================================================================
# Settable options
#============================================================================
option(BUILD_STATIC "Build static library" ON)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_TESTING "Build library tests" ON)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
option(USE_INTERMEDIATE_OBJECTS_TARGET "Use a common intermediate objects target for the static and shared library targets" ON)
if (${CMAKE_VERSION} VERSION_GREATER "3.1")
option(USE_OPENMP "Enable OpenMP to parallelize some of the algorithms. Note that this isn't always faster, see https://www.cryptopp.com/wiki/OpenMP" OFF)
endif()
# These are IA-32 options.
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_SSE4 "Disable SSE4" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
option(DISABLE_CLMUL "Disable CLMUL" OFF)
option(DISABLE_SHA "Disable SHA" OFF)
option(DISABLE_AVX "Disable AVX" OFF)
option(DISABLE_AVX2 "Disable AVX2" OFF)
# These are ARM A-32 options
option(DISABLE_ARM_NEON "Disable NEON" OFF)
# These are Aarch64 options
option(DISABLE_ARM_AES "Disable ASIMD" OFF)
option(DISABLE_ARM_AES "Disable AES" OFF)
option(DISABLE_ARM_PMULL "Disable PMULL" OFF)
option(DISABLE_ARM_SHA "Disable SHA" OFF)
# These are PowerPC options
option(DISABLE_ALTIVEC "Disable Altivec" OFF)
option(DISABLE_POWER7 "Disable POWER7" OFF)
option(DISABLE_POWER8 "Disable POWER8" OFF)
option(DISABLE_POWER9 "Disable POWER9" OFF)
set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory")
#============================================================================
# Compiler options
#============================================================================
set(CRYPTOPP_COMPILE_DEFINITIONS)
set(CRYPTOPP_COMPILE_OPTIONS)
# Stop hiding the damn output...
# set(CMAKE_VERBOSE_MAKEFILE ON)
# Stop CMake complaining...
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(MACOSX_RPATH FALSE)
endif()
# Always 1 ahead in Master. Also see http://groups.google.com/forum/#!topic/cryptopp-users/SFhqLDTQPG4
set(LIB_VER ${cryptopp_VERSION_MAJOR}${cryptopp_VERSION_MINOR}${cryptopp_VERSION_PATCH})
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
list(APPEND CRYPTOPP_COMPILE_OPTIONS -wd68 -wd186 -wd279 -wd327 -wd161 -wd3180)
endif ()
# Also see http://github.com/weidai11/cryptopp/issues/395
if (DISABLE_ASM)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ASM)
endif ()
if (DISABLE_SSSE3)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_SSSE3)
endif ()
if (DISABLE_SSE4)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_SSSE4)
endif ()
if (DISABLE_CLMUL)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_CLMUL)
endif ()
if (DISABLE_AESNI)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_AESNI)
endif ()
if (DISABLE_RDRAND)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_RDRAND)
endif ()
if (DISABLE_RDSEED)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_RDSEED)
endif ()
if (DISABLE_AVX)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_AVX)
endif ()
if (DISABLE_AVX2)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_AVX2)
endif ()
if (DISABLE_SHA)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_SHA)
endif ()
if (DISABLE_ARM_NEON)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ARM_NEON)
endif ()
if (DISABLE_ARM_ASIMD)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ARM_ASIMD)
endif ()
if (DISABLE_ARM_AES)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ARM_AES)
endif ()
if (DISABLE_ARM_PMULL)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ARM_PMULL)
endif ()
if (DISABLE_ARM_SHA)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ARM_SHA)
endif ()
if (DISABLE_ALTIVEC)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_ALTIVEC)
endif ()
if (DISABLE_POWER7)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_POWER7)
endif ()
if (DISABLE_POWER8)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_POWER8)
endif ()
if (DISABLE_POWER9)
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS CRYPTOPP_DISABLE_POWER9)
endif ()
if (NOT CRYPTOPP_DATA_DIR STREQUAL "")
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS "CRYPTOPP_DATA_DIR=${CRYPTOPP_DATA_DIR}")
endif ()
###############################################################################
# Try to find a Posix compatible grep and sed. Solaris, Digital Unix,
# Tru64, HP-UX and a few others need tweaking
if (EXISTS /usr/xpg4/bin/grep)
set(GREP_CMD /usr/xpg4/bin/grep)
elseif (EXISTS /usr/gnu/bin/grep)
set(GREP_CMD /usr/gnu/bin/grep)
elseif (EXISTS /usr/linux/bin/grep)
set(GREP_CMD /usr/linux/bin/grep)
else ()
set(GREP_CMD grep)
endif ()
if (EXISTS /usr/xpg4/bin/sed)
set(SED_CMD /usr/xpg4/bin/sed)
elseif (EXISTS /usr/gnu/bin/sed)
set(SED_CMD /usr/gnu/bin/sed)
elseif (EXISTS /usr/linux/bin/sed)
set(SED_CMD /usr/linux/bin/sed)
else ()
set(SED_CMD sed)
endif ()
###############################################################################
function(CheckCompileOption opt var)
if (MSVC)
# TODO: improve this...
CHECK_CXX_COMPILER_FLAG(${opt} ${var})
elseif (CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
message(STATUS "Performing Test ${var}")
execute_process(
COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${opt} -c ${TEST_CXX_FILE} 2>&1"
COMMAND ${GREP_CMD} -i -c -E "illegal value ignored"
RESULT_VARIABLE COMMAND_RESULT
OUTPUT_VARIABLE COMMAND_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# No dereference below. Thanks for the warning, CMake (not!).
if (COMMAND_RESULT AND NOT COMMAND_OUTPUT)
set(${var} 1 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Success")
else ()
set(${var} 0 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Failed")
endif ()
# Must use CMAKE_CXX_COMPILER here due to XLC 13.1 and LLVM front-end.
elseif (CMAKE_CXX_COMPILER MATCHES "xlC")
message(STATUS "Performing Test ${var}")
execute_process(
COMMAND sh -c "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${opt} -c ${TEST_CXX_FILE} 2>&1"
COMMAND ${GREP_CMD} -i -c -E "Unrecognized value"
RESULT_VARIABLE COMMAND_RESULT
OUTPUT_VARIABLE COMMAND_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# No dereference below. Thanks for the warning, CMake (not!).
if (COMMAND_RESULT AND NOT COMMAND_OUTPUT)
set(${var} 1 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Success")
else ()
set(${var} 0 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Failed")
endif ()
else ()
CHECK_CXX_COMPILER_FLAG(${opt} ${var})
endif ()
endfunction(CheckCompileOption)
function(CheckCompileLinkOption opt var prog)
if (MSVC)
# TODO: improve this...
CHECK_CXX_COMPILER_FLAG(${opt} ${var})
elseif (APPLE)
message(STATUS "Performing Test ${var}")
try_compile(COMMAND_SUCCESS ${CMAKE_BINARY_DIR} ${prog} COMPILE_DEFINITIONS ${opt})
if (COMMAND_SUCCESS)
set(${var} 1 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Success")
else ()
set(${var} 0 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Failed")
endif ()
else ()
message(STATUS "Performing Test ${var}")
try_compile(COMMAND_SUCCESS ${CMAKE_BINARY_DIR} ${prog} COMPILE_DEFINITIONS ${opt})
if (COMMAND_SUCCESS)
set(${var} 1 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Success")
else ()
set(${var} 0 PARENT_SCOPE)
message(STATUS "Performing Test ${var} - Failed")
endif ()
endif ()
endfunction(CheckCompileLinkOption)
function(AddCompileOption opt)
if ("${COMMAND_OUTPUT}" NOT STREQUAL "")
list(APPEND CRYPTOPP_COMPILE_OPTIONS "${opt}")
endif ()
endfunction(AddCompileOption)
###############################################################################
function(DumpMachine output pattern)
if (MSVC)
# CMake does not provide a generic shell/terminal mechanism
# and Microsoft environments don't know what 'sh' is.
set(${output} 0 PARENT_SCOPE)
else ()
if(CMAKE_SYSTEM_PROCESSOR MATCHES ${pattern})
set(${output} TRUE PARENT_SCOPE)
endif()
endif()
endfunction(DumpMachine)
# Thanks to Anonimal for MinGW; see http://github.com/weidai11/cryptopp/issues/466
DumpMachine(CRYPTOPP_AMD64 "(x86_64|AMD64|amd64)")
DumpMachine(CRYPTOPP_I386 "^i.86$")
DumpMachine(CRYPTOPP_MINGW32 "^mingw32")
DumpMachine(CRYPTOPP_MINGW64 "(w64-mingw32|mingw64)")
DumpMachine(CRYPTOPP_ARMV8 "(armv8|arm64|aarch32|aarch64)")
DumpMachine(CRYPTOPP_ARM32 "(arm|armhf|arm7l|eabihf)")
DumpMachine(CRYPTOPP_PPC32 "^(powerpc|ppc)")
DumpMachine(CRYPTOPP_PPC64 "^ppc64")
# Cleanup 32/64 bit
if (CRYPTOPP_AMD64)
set (CRYPTOPP_I386 0)
endif ()
if (CRYPTOPP_ARMV8)
set (CRYPTOPP_ARM32 0)
endif ()
if (CRYPTOPP_PPC64)
set (CRYPTOPP_PPC32 0)
endif ()
###############################################################################
# Test SunCC for a string like 'CC: Sun C++ 5.13 SunOS_i386'
if (NOT CRYPTOPP_SOLARIS)
execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1"
COMMAND ${GREP_CMD} -i -c "SunOS"
OUTPUT_VARIABLE CRYPTOPP_SOLARIS
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
# Test GCC for a string like 'i386-pc-solaris2.11'
if (NOT CRYPTOPP_SOLARIS)
execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -dumpmachine 2>&1"
COMMAND ${GREP_CMD} -i -c "Solaris"
OUTPUT_VARIABLE CRYPTOPP_SOLARIS
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
# Fixup PowerPC. If both 32-bit and 64-bit use 64-bit.
if (CRYPTOPP_PPC32 AND CRYPTOPP_PPC64)
unset(CRYPTOPP_PPC32)
endif ()
# Fixup for xlC compiler. -dumpmachine fails so we miss PowerPC
# TODO: something better than proxying the platform via compiler
# Must use CMAKE_CXX_COMPILER here due to XLC 13.1 and LLVM front-end.
if (CMAKE_CXX_COMPILER MATCHES "xlC")
message ("-- Fixing platform due to IBM xlC")
set(CRYPTOPP_PPC64 1)
endif ()
# DumpMachine SunCC style
if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
# SunCC is 32-bit, but it builds both 32 and 64 bit. Use
execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1"
COMMAND ${GREP_CMD} -i -c "Sparc"
OUTPUT_VARIABLE CRYPTOPP_SPARC
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND sh -c "${CMAKE_CXX_COMPILER} -V 2>&1"
COMMAND ${GREP_CMD} -i -c -E "i386|i86"
OUTPUT_VARIABLE CRYPTOPP_I386
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND isainfo -k
COMMAND ${GREP_CMD} -i -c "i386"
OUTPUT_VARIABLE KERNEL_I386
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND isainfo -k
COMMAND ${GREP_CMD} -i -c "amd64"
OUTPUT_VARIABLE KERNEL_AMD64
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND isainfo -k
COMMAND ${GREP_CMD} -i -c "Sparc"
OUTPUT_VARIABLE KERNEL_SPARC
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND isainfo -k
COMMAND ${GREP_CMD} -i -c -E "UltraSarc|Sparc64|SparcV9"
OUTPUT_VARIABLE KERNEL_SPARC64
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
###############################################################################
# TODO: what about ICC and LLVM on Windows?
if (MSVC)
if (CMAKE_SYSTEM_VERSION MATCHES "10\\.0.*")
list(APPEND CRYPTOPP_COMPILE_DEFINITIONS "_WIN32_WINNT=0x0A00")
endif ()
list(APPEND CRYPTOPP_COMPILE_OPTIONS /FI winapifamily.h)
endif ()
# Enable PIC for all target machines except 32-bit i386 due to register pressures.
if (NOT CRYPTOPP_I386)
SET(CMAKE_POSITION_INDEPENDENT_CODE 1)
endif ()
# IBM XLC compiler options for AIX and Linux.
# Must use CMAKE_CXX_COMPILER here due to XLC 13.1 and LLVM front-end.
if (CMAKE_CXX_COMPILER MATCHES "xlC")
#CheckCompileLinkOption("-qxlcompatmacros" CRYPTOPP_XLC_COMPAT "${TEST_CXX_FILE}")
#if (CRYPTOPP_XLC_COMPAT)
# list(APPEND CRYPTOPP_COMPILE_OPTIONS "-qxlcompatmacros")
#endif ()
CheckCompileLinkOption("-qrtti" CRYPTOPP_PPC_RTTI "${TEST_CXX_FILE}")
if (CRYPTOPP_PPC_RTTI)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-qrtti")
endif ()
CheckCompileLinkOption("-qmaxmem=-1" CRYPTOPP_PPC_MAXMEM "${TEST_CXX_FILE}")
if (CRYPTOPP_PPC_MAXMEM)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-qmaxmem=-1")
endif ()
CheckCompileLinkOption("-qthreaded" CRYPTOPP_PPC_THREADED "${TEST_CXX_FILE}")
if (CRYPTOPP_PPC_THREADED)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-qthreaded")
endif ()
endif ()
# Solaris specific
if (CRYPTOPP_SOLARIS)
# SunCC needs -template=no%extdef
if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-template=no%extdef")
endif ()
# SunCC needs -xregs=no%appl on Sparc (not x86) for libraries (not test program)
# TODO: wire this up properly
if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro" AND (CRYPTOPP_SPARC OR CRYPTOPP_SPARC64))
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-xregs=no%appl")
endif ()
# GCC needs to enable use of '/' for division in the assembler
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-Wa,--divide")
endif ()
endif ()
#============================================================================
# Sources & headers
#============================================================================
# Library headers
file(GLOB cryptopp_HEADERS ${SRC_DIR}/*.h)
# Remove headers used to build test suite
list(REMOVE_ITEM cryptopp_HEADERS
${SRC_DIR}/bench.h
${SRC_DIR}/validate.h
)
# Test sources. You can use the GNUmakefile to generate the list: `make sources`.
set(cryptopp_SOURCES_TEST
${SRC_DIR}/test.cpp
${SRC_DIR}/bench1.cpp
${SRC_DIR}/bench2.cpp
${SRC_DIR}/bench3.cpp
${SRC_DIR}/validat0.cpp
${SRC_DIR}/validat1.cpp
${SRC_DIR}/validat2.cpp
${SRC_DIR}/validat3.cpp
${SRC_DIR}/validat4.cpp
${SRC_DIR}/validat5.cpp
${SRC_DIR}/validat6.cpp
${SRC_DIR}/validat7.cpp
${SRC_DIR}/validat8.cpp
${SRC_DIR}/validat9.cpp
${SRC_DIR}/validat10.cpp
${SRC_DIR}/regtest1.cpp
${SRC_DIR}/regtest2.cpp
${SRC_DIR}/regtest3.cpp
${SRC_DIR}/regtest4.cpp
${SRC_DIR}/datatest.cpp
${SRC_DIR}/fipsalgt.cpp
${SRC_DIR}/fipstest.cpp
${SRC_DIR}/dlltest.cpp
#${SRC_DIR}/adhoc.cpp
)
# Library sources. You can use the GNUmakefile to generate the list: `make sources`.
# Makefile sorted them at http://github.com/weidai11/cryptopp/pull/426.
file(GLOB cryptopp_SOURCES ${SRC_DIR}/*.cpp)
list(SORT cryptopp_SOURCES)
list(REMOVE_ITEM cryptopp_SOURCES
${SRC_DIR}/cryptlib.cpp
${SRC_DIR}/cpu.cpp
${SRC_DIR}/integer.cpp
${SRC_DIR}/pch.cpp
${SRC_DIR}/simple.cpp
${SRC_DIR}/adhoc.cpp
${cryptopp_SOURCES_TEST}
)
set(cryptopp_SOURCES
${SRC_DIR}/cryptlib.cpp
${SRC_DIR}/cpu.cpp
${SRC_DIR}/integer.cpp
${cryptopp_SOURCES}
)
if(ANDROID)
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
list(APPEND cryptopp_SOURCES ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
endif()
set(cryptopp_SOURCES_ASM)
if (MSVC AND NOT DISABLE_ASM)
if (${CMAKE_GENERATOR} MATCHES ".*ARM")
message(STATUS "Disabling ASM because ARM is specified as target platform.")
else ()
enable_language(ASM_MASM)
list(APPEND cryptopp_SOURCES_ASM
${SRC_DIR}/rdrand.asm
${SRC_DIR}/rdseed.asm
)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND cryptopp_SOURCES_ASM
${SRC_DIR}/x64dll.asm
${SRC_DIR}/x64masm.asm
)
set_source_files_properties(${cryptopp_SOURCES_ASM} PROPERTIES COMPILE_DEFINITIONS "_M_X64")
else ()
set_source_files_properties(${cryptopp_SOURCES_ASM} PROPERTIES COMPILE_DEFINITIONS "_M_X86" COMPILE_FLAGS "/safeseh")
endif ()
set_source_files_properties(${cryptopp_SOURCES_ASM} PROPERTIES LANGUAGE ASM_MASM)
endif ()
endif ()
#============================================================================
# Architecture flags
#============================================================================
# TODO: Android, AIX, IBM xlC, iOS and a few other profiles are missing.
# New as of Pull Request 461, http://github.com/weidai11/cryptopp/pull/461.
# Must use CMAKE_CXX_COMPILER here due to XLC 13.1 and LLVM front-end.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER MATCHES "xlC")
if (CRYPTOPP_AMD64 OR CRYPTOPP_I386)
# For Darwin and a GCC port compiler, we need to check for -Wa,-q first. -Wa,-q
# is a GCC option, and it tells GCC to use the Clang Integrated Assembler. We
# need LLVM's assembler because GAS is too old on Apple platforms. GAS will
# not assemble modern ISA, like AVX or AVX2.
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
CheckCompileLinkOption("-Wa,-q" CRYPTOPP_IA32_WAQ
"${TEST_PROG_DIR}/test_x86_sse2.cpp")
if (CRYPTOPP_IA32_WAQ)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-Wa,-q")
endif ()
endif ()
# Now we can move on to normal feature testing.
CheckCompileLinkOption("-msse2" CRYPTOPP_IA32_SSE2
"${TEST_PROG_DIR}/test_x86_sse2.cpp")
CheckCompileLinkOption("-mssse3" CRYPTOPP_IA32_SSSE3
"${TEST_PROG_DIR}/test_x86_ssse3.cpp")
CheckCompileLinkOption("-msse4.1" CRYPTOPP_IA32_SSE41
"${TEST_PROG_DIR}/test_x86_sse41.cpp")
CheckCompileLinkOption("-msse4.2" CRYPTOPP_IA32_SSE42
"${TEST_PROG_DIR}/test_x86_sse42.cpp")
CheckCompileLinkOption("-mssse3 -mpclmul" CRYPTOPP_IA32_CLMUL
"${TEST_PROG_DIR}/test_x86_clmul.cpp")
CheckCompileLinkOption("-msse4.1 -maes" CRYPTOPP_IA32_AES
"${TEST_PROG_DIR}/test_x86_aes.cpp")
CheckCompileLinkOption("-mavx" CRYPTOPP_IA32_AVX
"${TEST_PROG_DIR}/test_x86_avx.cpp")
CheckCompileLinkOption("-mavx2" CRYPTOPP_IA32_AVX2
"${TEST_PROG_DIR}/test_x86_avx2.cpp")
CheckCompileLinkOption("-msse4.2 -msha" CRYPTOPP_IA32_SHA
"${TEST_PROG_DIR}/test_x86_sha.cpp")
if (EXISTS "${TEST_PROG_DIR}/test_asm_mixed.cpp")
CheckCompileLinkOption("" CRYPTOPP_MIXED_ASM
"${TEST_PROG_DIR}/test_asm_mixed.cpp")
else ()
CheckCompileLinkOption("" CRYPTOPP_MIXED_ASM
"${TEST_PROG_DIR}/test_mixed_asm.cpp")
endif ()
# https://github.com/weidai11/cryptopp/issues/756
if (NOT CRYPTOPP_MIXED_ASM)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_MIXED_ASM")
endif ()
if (NOT CRYPTOPP_IA32_SSE2 AND NOT DISABLE_ASM)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ASM")
elseif (CRYPTOPP_IA32_SSE2 AND NOT DISABLE_ASM)
set_source_files_properties(${SRC_DIR}/sse_simd.cpp PROPERTIES COMPILE_FLAGS "-msse2")
set_source_files_properties(${SRC_DIR}/chacha_simd.cpp PROPERTIES COMPILE_FLAGS "-msse2")
set_source_files_properties(${SRC_DIR}/donna_sse.cpp PROPERTIES COMPILE_FLAGS "-msse2")
endif ()
if (NOT CRYPTOPP_IA32_SSSE3 AND NOT DISABLE_SSSE3)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_SSSE3")
elseif (CRYPTOPP_IA32_SSSE3 AND NOT DISABLE_SSSE3)
set_source_files_properties(${SRC_DIR}/aria_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/cham_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/keccak_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/lea_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/lsh256_sse.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/lsh512_sse.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/simon128_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
set_source_files_properties(${SRC_DIR}/speck128_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3")
if (NOT CRYPTOPP_IA32_SSE41 AND NOT DISABLE_SSE4)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_SSE4")
elseif (CRYPTOPP_IA32_SSE41 AND NOT DISABLE_SSE4)
set_source_files_properties(${SRC_DIR}/blake2s_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(${SRC_DIR}/blake2b_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
endif ()
if (NOT CRYPTOPP_IA32_SSE42 AND NOT DISABLE_SSE4)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_SSE4")
elseif (CRYPTOPP_IA32_SSE42 AND NOT DISABLE_SSE4)
set_source_files_properties(${SRC_DIR}/crc_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2")
if (NOT CRYPTOPP_IA32_CLMUL AND NOT DISABLE_CLMUL)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_CLMUL")
elseif (CRYPTOPP_IA32_CLMUL AND NOT DISABLE_CLMUL)
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3 -mpclmul")
set_source_files_properties(${SRC_DIR}/gf2n_simd.cpp PROPERTIES COMPILE_FLAGS "-mpclmul")
endif ()
if (NOT CRYPTOPP_IA32_AES AND NOT DISABLE_AES)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_AESNI")
elseif (CRYPTOPP_IA32_AES AND NOT DISABLE_AES)
set_source_files_properties(${SRC_DIR}/rijndael_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.1 -maes")
set_source_files_properties(${SRC_DIR}/sm4_simd.cpp PROPERTIES COMPILE_FLAGS "-mssse3 -maes")
endif ()
#if (NOT CRYPTOPP_IA32_AVX AND NOT DISABLE_AVX)
# list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_AVX")
#elseif (CRYPTOPP_IA32_AVX AND NOT DISABLE_AVX)
# set_source_files_properties(${SRC_DIR}/XXX_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx")
#endif ()
if (NOT CRYPTOPP_IA32_AVX2 AND NOT DISABLE_AVX2)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_AVX2")
elseif (CRYPTOPP_IA32_AVX2 AND NOT DISABLE_AVX2)
set_source_files_properties(${SRC_DIR}/chacha_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2")
set_source_files_properties(${SRC_DIR}/lsh256_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2")
set_source_files_properties(${SRC_DIR}/lsh512_avx.cpp PROPERTIES COMPILE_FLAGS "-mavx2")
endif ()
if (NOT CRYPTOPP_IA32_SHA AND NOT DISABLE_SHA)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_SHANI")
elseif (CRYPTOPP_IA32_SHA AND NOT DISABLE_SHA)
set_source_files_properties(${SRC_DIR}/sha_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha")
set_source_files_properties(${SRC_DIR}/shacal2_simd.cpp PROPERTIES COMPILE_FLAGS "-msse4.2 -msha")
endif ()
endif ()
endif ()
elseif (CRYPTOPP_ARMV8)
# This checks for <arm_acle.h>
CheckCompileLinkOption("-march=armv8-a" CRYPTOPP_ARM_ACLE_HEADER
"${TEST_PROG_DIR}/test_arm_acle_header.cpp")
# Use <arm_acle.h> if available
if (CRYPTOPP_ARM_NEON_HEADER)
CheckCompileOption("-march=armv8-a -DCRYPTOPP_ARM_ACLE_HEADER=1" CRYPTOPP_ARMV8A_ASIMD)
CheckCompileOption("-march=armv8-a+crc -DCRYPTOPP_ARM_ACLE_HEADER=1" CRYPTOPP_ARMV8A_CRC)
CheckCompileOption("-march=armv8-a+crypto -DCRYPTOPP_ARM_ACLE_HEADER=1" CRYPTOPP_ARMV8A_CRYPTO)
else ()
CheckCompileOption("-march=armv8-a" CRYPTOPP_ARMV8A_ASIMD)
CheckCompileOption("-march=armv8-a+crc" CRYPTOPP_ARMV8A_CRC)
CheckCompileOption("-march=armv8-a+crypto" CRYPTOPP_ARMV8A_CRYPTO)
endif ()
if (CRYPTOPP_ARMV8A_ASIMD)
set_source_files_properties(${SRC_DIR}/aria_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/blake2s_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/blake2b_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/chacha_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/cham_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/lea_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/neon_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/simon128_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
set_source_files_properties(${SRC_DIR}/speck128_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a")
else ()
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_ASIMD")
endif ()
if (CRYPTOPP_ARMV8A_CRC)
set_source_files_properties(${SRC_DIR}/crc_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crc")
else ()
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_CRC32")
endif ()
if (CRYPTOPP_ARMV8A_CRYPTO)
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto")
set_source_files_properties(${SRC_DIR}/gf2n_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto")
set_source_files_properties(${SRC_DIR}/rijndael_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto")
set_source_files_properties(${SRC_DIR}/sha_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto")
set_source_files_properties(${SRC_DIR}/shacal2_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv8-a+crypto")
else ()
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_AES")
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_PMULL")
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_SHA")
endif ()
elseif (CRYPTOPP_ARM32)
# This checks for <arm_neon.h>
CheckCompileLinkOption("-march=armv7-a -mfpu=neon" CRYPTOPP_ARM_NEON_HEADER
"${TEST_PROG_DIR}/test_arm_neon_header.cpp")
# Use <arm_neon.h> if available
if (CRYPTOPP_ARM_NEON_HEADER)
CheckCompileLinkOption("-march=armv7-a -mfpu=neon -DCRYPTOPP_ARM_NEON_HEADER=1" CRYPTOPP_ARMV7A_NEON
"${TEST_PROG_DIR}/test_arm_neon.cpp")
else ()
CheckCompileLinkOption("-march=armv7-a -mfpu=neon" CRYPTOPP_ARMV7A_NEON
"${TEST_PROG_DIR}/test_arm_neon.cpp")
endif ()
if (CRYPTOPP_ARMV7A_NEON)
# Add Cryptogams ASM files for ARM on Linux. Linux is required due to GNU Assembler.
# AES requires -mthumb under Clang. Do not add -mthumb for SHA for any files.
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
list(APPEND cryptopp_SOURCES ${SRC_DIR}/aes_armv4.S)
list(APPEND cryptopp_SOURCES ${SRC_DIR}/sha1_armv4.S)
list(APPEND cryptopp_SOURCES ${SRC_DIR}/sha256_armv4.S)
list(APPEND cryptopp_SOURCES ${SRC_DIR}/sha512_armv4.S)
set_source_files_properties(${SRC_DIR}/aes_armv4.S PROPERTIES LANGUAGE CXX)
set_source_files_properties(${SRC_DIR}/sha1_armv4.S PROPERTIES LANGUAGE CXX)
set_source_files_properties(${SRC_DIR}/sha256_armv4.S PROPERTIES LANGUAGE CXX)
set_source_files_properties(${SRC_DIR}/sha512_armv4.S PROPERTIES LANGUAGE CXX)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_source_files_properties(${SRC_DIR}/aes_armv4.S PROPERTIES COMPILE_FLAGS "-march=armv7-a -mthumb -mfpu=neon -Wa,--noexecstack")
else ()
set_source_files_properties(${SRC_DIR}/aes_armv4.S PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon -Wa,--noexecstack")
endif ()
set_source_files_properties(${SRC_DIR}/sha1_armv4.S PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon -Wa,--noexecstack")
set_source_files_properties(${SRC_DIR}/sha256_armv4.S PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon -Wa,--noexecstack")
set_source_files_properties(${SRC_DIR}/sha512_armv4.S PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon -Wa,--noexecstack")
endif ()
set_source_files_properties(${SRC_DIR}/aria_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/blake2s_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/blake2b_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/chacha_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/cham_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/crc_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/lea_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/rijndael_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/neon_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/sha_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/simon128_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/speck128_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
set_source_files_properties(${SRC_DIR}/sm4_simd.cpp PROPERTIES COMPILE_FLAGS "-march=armv7-a -mfpu=neon")
else ()
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ARM_NEON")
endif ()
elseif (CRYPTOPP_PPC32 OR CRYPTOPP_PPC64)
# XLC requires -qaltivec in addition to Arch or CPU option
# Disable POWER9 due to https://github.com/weidai11/cryptopp/issues/986.
if (CMAKE_CXX_COMPILER MATCHES "xlC")
set(CRYPTOPP_ALTIVEC_FLAGS "-qaltivec")
set(CRYPTOPP_POWER4_FLAGS "-qarch=pwr4 -qaltivec")
set(CRYPTOPP_POWER5_FLAGS "-qarch=pwr5 -qaltivec")
set(CRYPTOPP_POWER6_FLAGS "-qarch=pwr6 -qaltivec")
set(CRYPTOPP_POWER7_VSX_FLAG "-qarch=pwr7 -qvsx -qaltivec")
set(CRYPTOPP_POWER7_PWR_FLAGS "-qarch=pwr7 -qaltivec")
set(CRYPTOPP_POWER8_FLAGS "-qarch=pwr8 -qaltivec")
#set(CRYPTOPP_POWER9_FLAGS "-qarch=pwr9 -qaltivec")
else ()
set(CRYPTOPP_ALTIVEC_FLAGS "-maltivec")
set(CRYPTOPP_POWER7_VSX_FLAGS "-mcpu=power7 -mvsx")
set(CRYPTOPP_POWER7_PWR_FLAGS "-mcpu=power7")
set(CRYPTOPP_POWER8_FLAGS "-mcpu=power8")
#set(CRYPTOPP_POWER9_FLAGS "-mcpu=power9")
endif ()
CheckCompileLinkOption("${CRYPTOPP_ALTIVEC_FLAGS}" PPC_ALTIVEC_FLAG
"${TEST_PROG_DIR}/test_ppc_altivec.cpp")
# Hack for XLC. Find the lowest PWR architecture.
if (CMAKE_CXX_COMPILER MATCHES "xlC")
if (NOT PPC_ALTIVEC_FLAG)
CheckCompileLinkOption("${CRYPTOPP_POWER4_FLAGS}" PPC_POWER4_FLAG
"${TEST_PROG_DIR}/test_ppc_altivec.cpp")
if (PPC_POWER4_FLAG)
set(PPC_ALTIVEC_FLAG 1)
set(CRYPTOPP_ALTIVEC_FLAGS "${CRYPTOPP_POWER4_FLAGS}")
endif ()
endif ()
if (NOT PPC_ALTIVEC_FLAG)
CheckCompileLinkOption("${CRYPTOPP_POWER5_FLAGS}" PPC_POWER5_FLAG
"${TEST_PROG_DIR}/test_ppc_altivec.cpp")
if (PPC_POWER5_FLAG)
set(PPC_ALTIVEC_FLAG 1)
set(CRYPTOPP_ALTIVEC_FLAGS "${CRYPTOPP_POWER5_FLAGS}")
endif ()
endif ()
if (NOT PPC_ALTIVEC_FLAG)
CheckCompileLinkOption("${CRYPTOPP_POWER6_FLAGS}" PPC_POWER6_FLAG
"${TEST_PROG_DIR}/test_ppc_altivec.cpp")
if (PPC_POWER6_FLAG)
set(PPC_ALTIVEC_FLAG 1)
set(CRYPTOPP_ALTIVEC_FLAGS "${CRYPTOPP_POWER6_FLAGS}")
endif ()
endif ()
endif ()
# Hack for XLC and GCC. Find the right combination for PWR7 and the VSX unit.
CheckCompileLinkOption("${CRYPTOPP_POWER7_VSX_FLAGS}" PPC_POWER7_FLAG
"${TEST_PROG_DIR}/test_ppc_power7.cpp")
if (PPC_POWER7_FLAG)
set (CRYPTOPP_POWER7_FLAGS "${CRYPTOPP_POWER7_VSX_FLAGS}")
else ()
CheckCompileLinkOption("${CRYPTOPP_POWER7_PWR_FLAGS}" PPC_POWER7_FLAG
"${TEST_PROG_DIR}/test_ppc_power7.cpp")
if (PPC_POWER7_FLAG)
set (CRYPTOPP_POWER7_FLAGS "${CRYPTOPP_POWER7_PWR_FLAGS}")
endif ()
endif ()
CheckCompileLinkOption("${CRYPTOPP_POWER8_FLAGS}" PPC_POWER8_FLAG
"${TEST_PROG_DIR}/test_ppc_power8.cpp")
# Disable POWER9 due to https://github.com/weidai11/cryptopp/issues/986.
#CheckCompileLinkOption("${CRYPTOPP_POWER9_FLAGS}" PPC_POWER9_FLAG
# "${TEST_PROG_DIR}/test_ppc_power9.cpp")
#if (PPC_POWER9_FLAG AND NOT DISABLE_POWER9)
# set_source_files_properties(${SRC_DIR}/ppc_power9.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER9_FLAGS})
#endif ()
if (PPC_POWER8_FLAG AND NOT DISABLE_POWER8)
set_source_files_properties(${SRC_DIR}/ppc_power8.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
#set_source_files_properties(${SRC_DIR}/aria_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/blake2b_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/cham_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
#set_source_files_properties(${SRC_DIR}/crc_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/gf2n_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/lea_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/rijndael_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/sha_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/shacal2_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/simon128_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
set_source_files_properties(${SRC_DIR}/speck128_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER8_FLAGS})
endif ()
if (PPC_POWER7_FLAG AND NOT DISABLE_POWER7)
set_source_files_properties(${SRC_DIR}/ppc_power7.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_POWER7_FLAGS})
endif ()
if (PPC_ALTIVEC_FLAG AND NOT DISABLE_ALTIVEC)
set_source_files_properties(${SRC_DIR}/ppc_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_ALTIVEC_FLAGS})
set_source_files_properties(${SRC_DIR}/blake2s_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_ALTIVEC_FLAGS})
set_source_files_properties(${SRC_DIR}/chacha_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_ALTIVEC_FLAGS})
endif ()
# Drop to Altivec if Power8 unavailable
if (NOT PPC_POWER8_FLAG)
if (PPC_ALTIVEC_FLAG)
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS ${CRYPTOPP_ALTIVEC_FLAGS})
endif ()
endif ()
if (NOT PPC_ALTIVEC_FLAG)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_ALTIVEC")
elseif (NOT PPC_POWER7_FLAG)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_POWER7")
elseif (NOT PPC_POWER8_FLAG)
list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_POWER8")
#elseif (NOT PPC_POWER9_FLAG)
# list(APPEND CRYPTOPP_COMPILE_OPTIONS "-DCRYPTOPP_DISABLE_POWER9")
endif ()
endif ()
endif ()
# New as of Pull Request 461, http://github.com/weidai11/cryptopp/pull/461.
if (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
if (CRYPTOPP_AMD64 OR CRYPTOPP_I386)
CheckCompileLinkOption("-xarch=sse2" CRYPTOPP_IA32_SSE2
"${TEST_PROG_DIR}/test_x86_sse2.cpp")
CheckCompileLinkOption("-xarch=ssse3" CRYPTOPP_IA32_SSSE3
"${TEST_PROG_DIR}/test_x86_ssse3.cpp")
CheckCompileLinkOption("-xarch=sse4_1" CRYPTOPP_IA32_SSE41
"${TEST_PROG_DIR}/test_x86_sse41.cpp")
CheckCompileLinkOption("-xarch=sse4_2" CRYPTOPP_IA32_SSE42
"${TEST_PROG_DIR}/test_x86_sse42.cpp")
CheckCompileLinkOption("-xarch=aes" CRYPTOPP_IA32_CLMUL
"${TEST_PROG_DIR}/test_x86_clmul.cpp")
CheckCompileLinkOption("-xarch=aes" CRYPTOPP_IA32_AES
"${TEST_PROG_DIR}/test_x86_aes.cpp")
CheckCompileLinkOption("-xarch=avx" CRYPTOPP_IA32_AVX
"${TEST_PROG_DIR}/test_x86_avx.cpp")
CheckCompileLinkOption("-xarch=avx2" CRYPTOPP_IA32_AVX2
"${TEST_PROG_DIR}/test_x86_avx2.cpp")
CheckCompileLinkOption("-xarch=sha" CRYPTOPP_IA32_SHA
"${TEST_PROG_DIR}/test_x86_sha.cpp")
# Each -xarch=XXX options must be added to LDFLAGS if the option is used during a compile.
set(XARCH_LDFLAGS "")
if (CRYPTOPP_IA32_SSE2 AND NOT DISABLE_ASM)
set_source_files_properties(${SRC_DIR}/sse_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse2")
set_source_files_properties(${SRC_DIR}/chacha_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse2")
set(XARCH_LDFLAGS "-xarch=sse2")
endif ()
if (CRYPTOPP_IA32_SSSE3 AND NOT DISABLE_SSSE3)
set_source_files_properties(${SRC_DIR}/aria_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3")
set_source_files_properties(${SRC_DIR}/cham_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3")
set_source_files_properties(${SRC_DIR}/lea_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3")
set_source_files_properties(${SRC_DIR}/simon128_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3")
set_source_files_properties(${SRC_DIR}/speck128_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=ssse3")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=ssse3")
if (CRYPTOPP_IA32_SSE41 AND NOT DISABLE_SSE4)
set_source_files_properties(${SRC_DIR}/blake2s_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse4_1")
set_source_files_properties(${SRC_DIR}/blake2b_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse4_1")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=sse4_1")
endif ()
if (CRYPTOPP_IA32_SSE42 AND NOT DISABLE_SSE4)
set_source_files_properties(${SRC_DIR}/crc_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sse4_2")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=sse4_2")
if (CRYPTOPP_IA32_CLMUL AND NOT DISABLE_CLMUL)
set_source_files_properties(${SRC_DIR}/gcm_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes")
set_source_files_properties(${SRC_DIR}/gf2n_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes")
endif ()
if (CRYPTOPP_IA32_AES AND NOT DISABLE_AES)
set_source_files_properties(${SRC_DIR}/rijndael_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes")
set_source_files_properties(${SRC_DIR}/sm4_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=aes")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=aes")
endif ()
#if (CRYPTOPP_IA32_AVX AND NOT DISABLE_AVX)
# set_source_files_properties(${SRC_DIR}/XXX_avx.cpp PROPERTIES COMPILE_FLAGS "-xarch=avx2")
# set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=avx")
#endif ()
if (CRYPTOPP_IA32_AVX2 AND NOT DISABLE_AVX2)
set_source_files_properties(${SRC_DIR}/chacha_avx.cpp PROPERTIES COMPILE_FLAGS "-xarch=avx2")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=avx2")
endif ()
if (CRYPTOPP_IA32_SHA AND NOT DISABLE_SHA)
set_source_files_properties(${SRC_DIR}/sha_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sha")
set_source_files_properties(${SRC_DIR}/shacal2_simd.cpp PROPERTIES COMPILE_FLAGS "-xarch=sha")
set(XARCH_LDFLAGS "${XARCH_LDFLAGS} -xarch=sha")
endif ()
endif ()
endif ()
# https://stackoverflow.com/a/6088646/608639
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${XARCH_LDFLAGS} -M${SRC_DIR}/cryptopp.mapfile")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${XARCH_LDFLAGS} -M${SRC_DIR}/cryptopp.mapfile")