forked from microsoft/CCF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1683 lines (1478 loc) · 50 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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.
cmake_minimum_required(VERSION 3.16)
set(ALLOWED_TARGETS "sgx;snp;virtual")
set(COMPILE_TARGET
"sgx"
CACHE STRING
"Target compilation platforms, Choose from: ${ALLOWED_TARGETS}"
)
set(CCF_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include(${CCF_DIR}/cmake/preproject.cmake)
include(${CCF_DIR}/cmake/version.cmake)
project(
${CCF_PROJECT}
VERSION ${CCF_RELEASE_VERSION}
LANGUAGES C CXX
)
message(STATUS "CCF version = ${CCF_VERSION}")
message(STATUS "CCF release version = ${CCF_RELEASE_VERSION}")
message(STATUS "CCF version suffix = ${CCF_VERSION_SUFFIX}")
# Set the default install prefix for CCF. Users may override this value with the
# cmake command. For example:
#
# $ cmake -DCMAKE_INSTALL_PREFIX=/opt/myplace ..
#
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX
"/opt/${CCF_PROJECT}"
CACHE PATH "Default install prefix" FORCE
)
endif()
include(${CCF_DIR}/cmake/cpack_settings.cmake)
message(STATUS "CMAKE_INSTALL_PREFIX is '${CMAKE_INSTALL_PREFIX}'")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/preproject.cmake
DESTINATION cmake
)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH "${CCF_DIR}/cmake;${CMAKE_MODULE_PATH}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(Threads REQUIRED)
function(message)
if(NOT MESSAGE_QUIET)
_message(${ARGN})
endif()
endfunction()
option(PROFILE_TESTS "Profile tests" OFF)
set(PYTHON unbuffer python3)
set(DISTRIBUTE_PERF_TESTS
""
CACHE
STRING
"Hosts to which performance tests should be distributed, for example -n ssh://x.x.x.x -n ssh://x.x.x.x -n ssh://x.x.x.x"
)
if(DISTRIBUTE_PERF_TESTS)
separate_arguments(NODES UNIX_COMMAND ${DISTRIBUTE_PERF_TESTS})
else()
unset(NODES)
endif()
option(
VERBOSE_LOGGING
"Enable verbose, potentially unsafe logging of enclave code. Affects logging level passed at run-time to end-to-end-tests, and compile-time max verbosity on SGX."
OFF
)
set(TEST_LOGGING_LEVEL "info")
if(VERBOSE_LOGGING)
set(TEST_LOGGING_LEVEL "trace")
endif()
# NB: Toggling VERBOSE_LOGGING on non-SGX platforms causes no build change, so
# should not cause a rebuild
if(COMPILE_TARGET STREQUAL "sgx" AND NOT VERBOSE_LOGGING)
# Disable verbose, unsafe logging of enclave code. On some platforms it is
# safe to build with this logging enabled, and then it can be disabled at
# run-time. However this run-time control is not possible on SGX, so to ensure
# a given MRENCLAVE cannot leak via debug logging it must be removed at
# build-time, with this option.
add_compile_definitions(CCF_DISABLE_VERBOSE_LOGGING)
endif()
option(USE_NULL_ENCRYPTOR "Turn off encryption of ledger updates - debug only"
OFF
)
if(USE_NULL_ENCRYPTOR)
add_compile_definitions(USE_NULL_ENCRYPTOR)
endif()
option(SAN "Enable Address and Undefined Behavior Sanitizers" OFF)
option(TSAN "Enable Thread Sanitizers" OFF)
option(BUILD_END_TO_END_TESTS "Build end to end tests" ON)
option(COVERAGE "Enable coverage mapping" OFF)
option(SHUFFLE_SUITE "Shuffle end to end test suite" OFF)
option(LONG_TESTS "Enable long end-to-end tests" OFF)
option(KV_STATE_RB "Enable RBMap as underlying KV state implementation" OFF)
if(KV_STATE_RB)
add_compile_definitions(KV_STATE_RB)
endif()
# This option controls whether to link virtual builds against snmalloc rather
# than use the system allocator. In builds using Open Enclave, enclave
# allocation is managed separately and enabling snmalloc is done by linking
# openenclave::oesnmalloc
option(USE_SNMALLOC "Link virtual build against snmalloc" ON)
enable_language(ASM)
set(CCF_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
include_directories(${CCF_DIR}/include)
include_directories(${CCF_DIR}/src)
set(CCF_3RD_PARTY_EXPORTED_DIR "${CCF_DIR}/3rdparty/exported")
set(CCF_3RD_PARTY_INTERNAL_DIR "${CCF_DIR}/3rdparty/internal")
include_directories(SYSTEM ${CCF_3RD_PARTY_EXPORTED_DIR})
include_directories(SYSTEM ${CCF_3RD_PARTY_INTERNAL_DIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools.cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/tools.cmake DESTINATION cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccf_app.cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/ccf_app.cmake DESTINATION cmake)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/open_enclave.cmake
DESTINATION cmake
)
if(SAN AND LVI_MITIGATIONS)
message(
FATAL_ERROR
"Building with both SAN and LVI mitigations is unsafe and deadlocks - choose one"
)
endif()
if(TSAN AND LVI_MITIGATIONS)
message(
FATAL_ERROR
"Building with both TSAN and LVI mitigations is unsafe and deadlocks - choose one"
)
endif()
add_custom_command(
COMMAND
openenclave::oeedger8r ${CCF_DIR}/edl/ccf.edl --search-path ${OE_INCLUDEDIR}
--trusted --trusted-dir ${CCF_GENERATED_DIR} --untrusted --untrusted-dir
${CCF_GENERATED_DIR}
COMMAND mv ${CCF_GENERATED_DIR}/ccf_t.c ${CCF_GENERATED_DIR}/ccf_t.cpp
COMMAND mv ${CCF_GENERATED_DIR}/ccf_u.c ${CCF_GENERATED_DIR}/ccf_u.cpp
DEPENDS ${CCF_DIR}/edl/ccf.edl
OUTPUT ${CCF_GENERATED_DIR}/ccf_t.cpp ${CCF_GENERATED_DIR}/ccf_u.cpp
COMMENT "Generating code from EDL, and renaming to .cpp"
)
# Copy and install CCF utilities
set(CCF_UTILITIES keygenerator.sh scurl.sh submit_recovery_share.sh
verify_quote.sh
)
foreach(UTILITY ${CCF_UTILITIES})
configure_file(
${CCF_DIR}/python/utils/${UTILITY} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY
)
install(PROGRAMS ${CCF_DIR}/python/utils/${UTILITY} DESTINATION bin)
endforeach()
# Copy utilities from tests directory
set(CCF_TEST_UTILITIES
tests.sh
cimetrics_env.sh
upload_pico_metrics.py
test_install.sh
docker_wrap.sh
config.jinja
recovery_benchmark.sh
)
foreach(UTILITY ${CCF_TEST_UTILITIES})
configure_file(
${CCF_DIR}/tests/${UTILITY} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY
)
endforeach()
# Install additional utilities
install(PROGRAMS ${CCF_DIR}/samples/scripts/sgxinfo.sh DESTINATION bin)
install(PROGRAMS ${CCF_DIR}/samples/scripts/snpinfo.sh DESTINATION bin)
install(FILES ${CCF_DIR}/tests/config.jinja DESTINATION bin)
if(SAN)
install(FILES ${CCF_DIR}/src/san_common.suppressions DESTINATION bin)
endif()
# Install getting_started scripts for VM creation and setup
install(
DIRECTORY ${CCF_DIR}/getting_started/
DESTINATION getting_started
USE_SOURCE_PERMISSIONS
)
if(COMPILE_TARGET STREQUAL "sgx")
# While virtual libraries need to be built for sgx for unit tests, these do
# not get installed to minimise installation size
set(INSTALL_VIRTUAL_LIBRARIES OFF)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_ENCLAVE_TYPE debug)
endif()
elseif(COMPILE_TARGET STREQUAL "snp")
set(INSTALL_VIRTUAL_LIBRARIES OFF)
else()
set(INSTALL_VIRTUAL_LIBRARIES ON)
endif()
set(HTTP_PARSER_SOURCES
${CCF_3RD_PARTY_EXPORTED_DIR}/llhttp/api.c
${CCF_3RD_PARTY_EXPORTED_DIR}/llhttp/http.c
${CCF_3RD_PARTY_EXPORTED_DIR}/llhttp/llhttp.c
)
set(CCF_ENDPOINTS_SOURCES
${CCF_DIR}/src/endpoints/endpoint.cpp
${CCF_DIR}/src/endpoints/endpoint_registry.cpp
${CCF_DIR}/src/endpoints/base_endpoint_registry.cpp
${CCF_DIR}/src/endpoints/common_endpoint_registry.cpp
${CCF_DIR}/src/endpoints/json_handler.cpp
${CCF_DIR}/src/endpoints/authentication/cose_auth.cpp
${CCF_DIR}/src/endpoints/authentication/cert_auth.cpp
${CCF_DIR}/src/endpoints/authentication/empty_auth.cpp
${CCF_DIR}/src/endpoints/authentication/jwt_auth.cpp
${CCF_DIR}/src/enclave/enclave_time.cpp
${CCF_DIR}/src/indexing/strategies/seqnos_by_key_bucketed.cpp
${CCF_DIR}/src/indexing/strategies/seqnos_by_key_in_memory.cpp
${CCF_DIR}/src/indexing/strategies/visit_each_entry_in_map.cpp
${CCF_DIR}/src/node/historical_queries_adapter.cpp
${CCF_DIR}/src/node/historical_queries_utils.cpp
${CCF_DIR}/src/node/receipt.cpp
)
include(${CCF_DIR}/cmake/crypto.cmake)
include(${CCF_DIR}/cmake/quickjs.cmake)
include(${CCF_DIR}/cmake/sss.cmake)
include(${CCF_DIR}/cmake/nghttp2.cmake)
include(${CCF_DIR}/cmake/qcbor.cmake)
include(${CCF_DIR}/cmake/t_cose.cmake)
set(MESSAGE_QUIET ON)
include(${CCF_DIR}/cmake/protobuf.cmake)
unset(MESSAGE_QUIET)
# Host Executable
if(SAN
OR TSAN
OR NOT USE_SNMALLOC
)
set(SNMALLOC_COMPILE_OPTIONS "")
else()
set(SNMALLOC_HEADER_ONLY_LIBRARY ON)
add_subdirectory(3rdparty/exported/snmalloc EXCLUDE_FROM_ALL)
set(SNMALLOC_COMPILE_OPTIONS "-mcx16")
list(APPEND CCHOST_SOURCES src/host/snmalloc.cpp)
endif()
list(APPEND CCHOST_SOURCES ${CCF_DIR}/src/host/main.cpp)
if(COMPILE_TARGET STREQUAL "sgx")
list(APPEND CCHOST_SOURCES ${CCF_GENERATED_DIR}/ccf_u.cpp)
endif()
add_executable(cchost ${CCHOST_SOURCES})
add_warning_checks(cchost)
add_san(cchost)
target_compile_options(
cchost PRIVATE ${COMPILE_LIBCXX} ${SNMALLOC_COMPILE_OPTIONS}
)
target_include_directories(cchost PRIVATE ${CCF_GENERATED_DIR})
if(COMPILE_TARGET STREQUAL "sgx")
target_compile_definitions(cchost PUBLIC PLATFORM_SGX)
elseif(COMPILE_TARGET STREQUAL "snp")
target_compile_definitions(cchost PUBLIC PLATFORM_SNP)
elseif(COMPILE_TARGET STREQUAL "virtual")
target_compile_definitions(cchost PUBLIC PLATFORM_VIRTUAL)
endif()
target_link_libraries(
cchost PRIVATE uv ${TLS_LIBRARY} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
${LINK_LIBCXX} ccfcrypto.host
)
if(COMPILE_TARGET STREQUAL "sgx")
target_link_libraries(cchost PRIVATE openenclave::oehost)
endif()
install(TARGETS cchost DESTINATION bin)
# Perf scenario executable
add_executable(
scenario_perf_client ${CCF_DIR}/src/clients/perf/scenario_perf_client.cpp
)
target_link_libraries(
scenario_perf_client PRIVATE ${CMAKE_THREAD_LIBS_INIT} http_parser.host
ccfcrypto.host
)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9)
target_link_libraries(scenario_perf_client PRIVATE c++fs)
endif()
install(TARGETS scenario_perf_client DESTINATION bin)
# HTTP parser
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library_c(http_parser.enclave "${HTTP_PARSER_SOURCES}")
install(
TARGETS http_parser.enclave
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_library(http_parser.snp "${HTTP_PARSER_SOURCES}")
set_property(TARGET http_parser.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS http_parser.snp
EXPORT ccf
DESTINATION lib
)
endif()
add_library(http_parser.host "${HTTP_PARSER_SOURCES}")
set_property(TARGET http_parser.host PROPERTY POSITION_INDEPENDENT_CODE ON)
if(INSTALL_VIRTUAL_LIBRARIES)
install(
TARGETS http_parser.host
EXPORT ccf
DESTINATION lib
)
endif()
# CCF kv libs
set(CCF_KV_SOURCES
${CCF_DIR}/src/kv/tx.cpp ${CCF_DIR}/src/kv/untyped_map_handle.cpp
${CCF_DIR}/src/kv/untyped_map_diff.cpp
)
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(ccf_kv.enclave "${CCF_KV_SOURCES}")
add_warning_checks(ccf_kv.enclave)
install(
TARGETS ccf_kv.enclave
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_host_library(ccf_kv.snp "${CCF_KV_SOURCES}")
add_san(ccf_kv.snp)
add_warning_checks(ccf_kv.snp)
install(
TARGETS ccf_kv.snp
EXPORT ccf
DESTINATION lib
)
endif()
add_host_library(ccf_kv.host "${CCF_KV_SOURCES}")
add_san(ccf_kv.host)
add_warning_checks(ccf_kv.host)
if(INSTALL_VIRTUAL_LIBRARIES)
install(
TARGETS ccf_kv.host
EXPORT ccf
DESTINATION lib
)
endif()
# CCF endpoints libs
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(ccf_endpoints.enclave "${CCF_ENDPOINTS_SOURCES}")
target_link_libraries(
ccf_endpoints.enclave
PUBLIC qcbor.enclave t_cose.enclave http_parser.enclave ccfcrypto.enclave
ccf_kv.enclave
)
add_warning_checks(ccf_endpoints.enclave)
install(
TARGETS ccf_endpoints.enclave
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_host_library(ccf_endpoints.snp "${CCF_ENDPOINTS_SOURCES}")
target_link_libraries(
ccf_endpoints.snp PUBLIC qcbor.snp t_cose.snp http_parser.snp ccfcrypto.snp
ccf_kv.snp
)
add_san(ccf_endpoints.snp)
add_warning_checks(ccf_endpoints.snp)
install(
TARGETS ccf_endpoints.snp
EXPORT ccf
DESTINATION lib
)
endif()
add_host_library(ccf_endpoints.host "${CCF_ENDPOINTS_SOURCES}")
target_link_libraries(
ccf_endpoints.host PUBLIC qcbor.host t_cose.host http_parser.host
ccfcrypto.host ccf_kv.host
)
add_san(ccf_endpoints.host)
add_warning_checks(ccf_endpoints.host)
if(INSTALL_VIRTUAL_LIBRARIES)
install(
TARGETS ccf_endpoints.host
EXPORT ccf
DESTINATION lib
)
endif()
# Common test args for Python scripts starting up CCF networks
set(WORKER_THREADS
0
CACHE STRING "Number of worker threads to start on each CCF node"
)
set(CCF_NETWORK_TEST_DEFAULT_CONSTITUTION
--constitution
${CCF_DIR}/samples/constitutions/default/actions.js
--constitution
${CCF_DIR}/samples/constitutions/default/validate.js
--constitution
${CCF_DIR}/samples/constitutions/default/resolve.js
--constitution
${CCF_DIR}/samples/constitutions/default/apply.js
)
set(CCF_NETWORK_TEST_ARGS
--host-log-level ${TEST_LOGGING_LEVEL} --enclave-log-level
${TEST_LOGGING_LEVEL} --worker-threads ${WORKER_THREADS}
)
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(js_openenclave.enclave ${CCF_DIR}/src/js/openenclave.cpp)
target_link_libraries(js_openenclave.enclave PUBLIC ccf.enclave)
add_lvi_mitigations(js_openenclave.enclave)
install(
TARGETS js_openenclave.enclave
EXPORT ccf
DESTINATION lib
)
add_enclave_library(
js_snp_attestation.enclave ${CCF_DIR}/src/js/snp_attestation.cpp
)
target_link_libraries(js_snp_attestation.enclave PUBLIC ccf.enclave)
add_lvi_mitigations(js_snp_attestation.enclave)
install(
TARGETS js_snp_attestation.enclave
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp" AND REQUIRE_OPENENCLAVE)
add_library(js_openenclave.snp STATIC ${CCF_DIR}/src/js/openenclave.cpp)
add_san(js_openenclave.snp)
target_link_libraries(js_openenclave.snp PUBLIC ccf.snp)
target_compile_options(js_openenclave.snp PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_openenclave.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(TARGET js_openenclave.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS js_openenclave.snp
EXPORT ccf
DESTINATION lib
)
set(JS_OPENENCLAVE_SNP js_openenclave.snp)
elseif(COMPILE_TARGET STREQUAL "virtual" AND REQUIRE_OPENENCLAVE)
add_library(js_openenclave.virtual STATIC ${CCF_DIR}/src/js/openenclave.cpp)
add_san(js_openenclave.virtual)
target_link_libraries(js_openenclave.virtual PUBLIC ccf.virtual)
target_compile_options(js_openenclave.virtual PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_openenclave.virtual
PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE _LIBCPP_HAS_THREAD_API_PTHREAD
PLATFORM_VIRTUAL
)
set_property(
TARGET js_openenclave.virtual PROPERTY POSITION_INDEPENDENT_CODE ON
)
install(
TARGETS js_openenclave.virtual
EXPORT ccf
DESTINATION lib
)
set(JS_OPENENCLAVE_VIRTUAL js_openenclave.virtual)
endif()
if(COMPILE_TARGET STREQUAL "snp")
add_library(
js_snp_attestation.snp STATIC ${CCF_DIR}/src/js/snp_attestation.cpp
)
add_san(js_snp_attestation.snp)
target_link_libraries(js_snp_attestation.snp PUBLIC ccf.snp)
target_compile_options(js_snp_attestation.snp PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_snp_attestation.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(
TARGET js_snp_attestation.snp PROPERTY POSITION_INDEPENDENT_CODE ON
)
install(
TARGETS js_snp_attestation.snp
EXPORT ccf
DESTINATION lib
)
set(JS_SNP_ATTESTATION_SNP js_snp_attestation.snp)
elseif(COMPILE_TARGET STREQUAL "virtual")
add_library(
js_snp_attestation.virtual STATIC ${CCF_DIR}/src/js/snp_attestation.cpp
)
add_san(js_snp_attestation.virtual)
target_link_libraries(js_snp_attestation.virtual PUBLIC ccf.virtual)
target_compile_options(js_snp_attestation.virtual PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_snp_attestation.virtual
PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE _LIBCPP_HAS_THREAD_API_PTHREAD
PLATFORM_VIRTUAL
)
set_property(
TARGET js_snp_attestation.virtual PROPERTY POSITION_INDEPENDENT_CODE ON
)
install(
TARGETS js_snp_attestation.virtual
EXPORT ccf
DESTINATION lib
)
set(JS_SNP_ATTESTATION_VIRTUAL js_snp_attestation.virtual)
endif()
if(COMPILE_TARGET STREQUAL "sgx")
add_enclave_library(
js_generic_base.enclave ${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
)
target_link_libraries(js_generic_base.enclave PUBLIC ccf.enclave)
add_lvi_mitigations(js_generic_base.enclave)
install(
TARGETS js_generic_base.enclave
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_library(
js_generic_base.snp STATIC
${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
)
add_san(js_generic_base.snp)
add_warning_checks(js_generic_base.snp)
target_link_libraries(js_generic_base.snp PUBLIC ccf.snp)
target_compile_options(js_generic_base.snp PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_generic_base.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(TARGET js_generic_base.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS js_generic_base.snp
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "virtual")
add_library(
js_generic_base.virtual STATIC
${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
)
add_san(js_generic_base.virtual)
add_warning_checks(js_generic_base.virtual)
target_link_libraries(js_generic_base.virtual PUBLIC ccf.virtual)
target_compile_options(js_generic_base.virtual PRIVATE ${COMPILE_LIBCXX})
if(REQUIRE_OPENENCLAVE)
target_compile_definitions(
js_openenclave.virtual
PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE _LIBCPP_HAS_THREAD_API_PTHREAD
PLATFORM_VIRTUAL
)
endif()
target_compile_definitions(
js_snp_attestation.virtual
PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE _LIBCPP_HAS_THREAD_API_PTHREAD
PLATFORM_VIRTUAL
)
set_property(
TARGET js_generic_base.virtual PROPERTY POSITION_INDEPENDENT_CODE ON
)
install(
TARGETS js_generic_base.virtual
EXPORT ccf
DESTINATION lib
)
endif()
# SNIPPET_START: JS generic application
add_ccf_app(
js_generic
SRCS ${CCF_DIR}/src/apps/js_generic/js_generic.cpp
LINK_LIBS_ENCLAVE js_generic_base.enclave js_openenclave.enclave
js_snp_attestation.enclave
LINK_LIBS_VIRTUAL js_generic_base.virtual ${JS_OPENENCLAVE_VIRTUAL}
${JS_SNP_ATTESTATION_VIRTUAL}
LINK_LIBS_SNP js_generic_base.snp ${JS_OPENENCLAVE_SNP}
${JS_SNP_ATTESTATION_SNP} INSTALL_LIBS ON
)
sign_app_library(
js_generic.enclave ${CCF_DIR}/src/apps/js_generic/oe_sign.conf
${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem INSTALL_LIBS ON
)
# SNIPPET_END: JS generic application
install(DIRECTORY ${CCF_DIR}/samples/apps/logging/js
DESTINATION samples/logging
)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake)
file(WRITE ${CMAKE_BINARY_DIR}/PLATFORM "${COMPILE_TARGET}")
install(FILES ${CMAKE_BINARY_DIR}/PLATFORM DESTINATION share)
set(CMAKE_GENERATED_COMMENT
"This file was auto-generated by CMake from a corresponding *.in file. DO NOT EDIT"
)
configure_file(
${CCF_DIR}/src/common/version.h.in ${CCF_DIR}/include/ccf/version.h @ONLY
)
configure_file(
${CCF_DIR}/python/version.py.in ${CCF_DIR}/python/version.py @ONLY
)
install(FILES ${CCF_DIR}/include/ccf/version.h DESTINATION include/ccf)
file(READ ${CCF_DIR}/doc/host_config_schema/cchost_config.json
HOST_CONFIG_SCHEMA
)
configure_file(
${CCF_DIR}/src/host/config_schema.h.in ${CCF_DIR}/src/host/config_schema.h
@ONLY
)
file(READ ${CCF_DIR}/doc/schemas/mccf/2023-06-01-preview/mccfgov.json
GOV_API_SCHEMA_2023_06_01_PREVIEW
)
configure_file(
${CCF_DIR}/src/node/gov/api_schema.h.in ${CCF_DIR}/src/node/gov/api_schema.h
@ONLY
)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_UNIT_TESTS "Build unit tests" ON)
option(CLIENT_PROTOCOLS_TEST "Test client protocols (TLS, HTTP/2)" OFF)
option(BUILD_TPCC "Build TPPC sample app and clients" OFF)
option(
FORCE_ENABLE_XAPIC_MITIGATION
"Always enable aligned reads from host-memory to mitigate xAPIC stale data read vulnerability. When this setting is off, the mitigation is enabled at run-time when vulnerable hardware is detected"
OFF
)
# Allow framework code to use LOG_*_FMT macros. These will be removed from
# public headers in future
add_compile_definitions(CCF_LOGGER_NO_DEPRECATE)
option(CCF_RAFT_TRACING "Enable tracing of Raft consensus" OFF)
if(CCF_RAFT_TRACING)
add_compile_definitions(CCF_RAFT_TRACING)
endif()
# Build common library for CCF enclaves
add_custom_target(ccf ALL)
set(CCF_IMPL_SOURCE
${CCF_DIR}/src/enclave/main.cpp ${CCF_DIR}/src/enclave/enclave_time.cpp
${CCF_DIR}/src/enclave/thread_local.cpp ${CCF_DIR}/src/js/wrap.cpp
${CCF_DIR}/src/node/quote.cpp
)
if(COMPILE_TARGET STREQUAL "sgx")
# enclave version
add_enclave_library(
ccf.enclave ${CCF_IMPL_SOURCE} ${CCF_GENERATED_DIR}/ccf_t.cpp
)
# PLATFORM_SGX to initialise Open Enclave SGX enclave creation and
# SGX_ATTESTATION_VERIFICATION to verify SGX attestation reports.
target_compile_definitions(
ccf.enclave PUBLIC PLATFORM_SGX SGX_ATTESTATION_VERIFICATION
)
add_warning_checks(ccf.enclave)
target_include_directories(
ccf.enclave SYSTEM
PUBLIC
$<BUILD_INTERFACE:${CCF_GENERATED_DIR}>
$<INSTALL_INTERFACE:include/ccf/> #< This contains the private headers
#< which are currently under src, and
#< should be removed or renamed
$<INSTALL_INTERFACE:include/>
$<INSTALL_INTERFACE:include/3rdparty/>
)
target_link_libraries(
ccf.enclave
PUBLIC quickjs.enclave
http_parser.enclave
sss.enclave
ccf_endpoints.enclave
ccfcrypto.enclave
ccf_kv.enclave
nghttp2.enclave
)
add_lvi_mitigations(ccf.enclave)
install(
TARGETS ccf.enclave
EXPORT ccf
DESTINATION lib
)
add_dependencies(ccf ccf.enclave)
# Same as virtual for the time being but will diverge soon
elseif(COMPILE_TARGET STREQUAL "snp")
# SNP version
add_library(ccf.snp STATIC ${CCF_IMPL_SOURCE})
target_compile_definitions(
ccf.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
target_compile_options(ccf.snp PUBLIC ${COMPILE_LIBCXX})
add_warning_checks(ccf.snp)
target_include_directories(
ccf.snp SYSTEM
PUBLIC
$<BUILD_INTERFACE:${CCF_GENERATED_DIR}>
$<INSTALL_INTERFACE:include/ccf/> #< This contains the private headers
#< which are currently under src, and
#< should be removed or renamed
$<INSTALL_INTERFACE:include/>
$<INSTALL_INTERFACE:include/3rdparty/>
)
target_link_libraries(
ccf.snp
PUBLIC ${LINK_LIBCXX}
-lgcc
http_parser.snp
quickjs.snp
sss.snp
ccf_endpoints.snp
ccfcrypto.snp
ccf_kv.snp
nghttp2.snp
${CMAKE_THREAD_LIBS_INIT}
)
link_openenclave_host(ccf.snp)
set_property(TARGET ccf.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
add_san(ccf.snp)
install(
TARGETS ccf.snp
EXPORT ccf
DESTINATION lib
)
add_dependencies(ccf ccf.snp)
elseif(COMPILE_TARGET STREQUAL "virtual")
# virtual version
add_library(ccf.virtual STATIC ${CCF_IMPL_SOURCE})
target_compile_definitions(
ccf.virtual PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_VIRTUAL
)
target_compile_options(ccf.virtual PUBLIC ${COMPILE_LIBCXX})
add_warning_checks(ccf.virtual)
target_include_directories(
ccf.virtual SYSTEM
PUBLIC
$<BUILD_INTERFACE:${CCF_GENERATED_DIR}>
$<INSTALL_INTERFACE:include/ccf/> #< This contains the private headers
#< which are currently under src, and
#< should be removed or renamed
$<INSTALL_INTERFACE:include/>
$<INSTALL_INTERFACE:include/3rdparty/>
)
target_link_libraries(
ccf.virtual
PUBLIC ${LINK_LIBCXX}
-lgcc
http_parser.host
quickjs.host
sss.host
ccf_endpoints.host
ccfcrypto.host
ccf_kv.host
nghttp2.host
${CMAKE_THREAD_LIBS_INIT}
)
link_openenclave_host(ccf.virtual)
set_property(TARGET ccf.virtual PROPERTY POSITION_INDEPENDENT_CODE ON)
add_san(ccf.virtual)
install(
TARGETS ccf.virtual
EXPORT ccf
DESTINATION lib
)
add_dependencies(ccf ccf.virtual)
endif()
install(
EXPORT ccf
DESTINATION cmake
FILE ccf-targets.cmake
)
# Install exported 3rd-party library includes
install(
DIRECTORY 3rdparty/exported/
DESTINATION include/3rdparty
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp"
PATTERN "*.inc"
)
# Install all private CCF headers, which may still be needed
install(
DIRECTORY src/
DESTINATION include/ccf/_private
FILES_MATCHING
PATTERN "*.h"
PATTERN "*/test*" EXCLUDE
)
# Install all public CCF headers
install(
DIRECTORY include/
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
)
# Install CCF Python infrastructure
install(
DIRECTORY tests/infra/
DESTINATION bin/infra
FILES_MATCHING
PATTERN "*.py"
PATTERN "*/__pycache__*" EXCLUDE
)
install(PROGRAMS tests/sandbox/sandbox.sh DESTINATION bin)
install(PROGRAMS tests/docker_wrap.sh DESTINATION bin)
install(FILES samples/constitutions/default/actions.js DESTINATION bin)
install(FILES samples/constitutions/default/validate.js DESTINATION bin)
install(FILES samples/constitutions/sandbox/resolve.js DESTINATION bin)
install(FILES samples/constitutions/default/apply.js DESTINATION bin)
install(FILES tests/start_network.py DESTINATION bin)
install(FILES tests/requirements.txt DESTINATION bin)
# Generate an ephemeral signing key
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem
COMMAND openssl genrsa -out ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem -3
3072
)
add_custom_target(
signing_key ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/signing_key.pem
)
# Add sample apps
add_subdirectory(${CCF_DIR}/samples)
# Add external_executor app
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/apps/external_executor)
if(BUILD_TESTS)
enable_testing()
# Unit tests
if(BUILD_UNIT_TESTS)
add_unit_test(map_test ${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/map_test.cpp)
add_unit_test(
json_schema ${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/json_schema.cpp
)
add_unit_test(
logger_test ${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/logger.cpp
)
add_unit_test(
openapi_test ${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/openapi.cpp
)
target_link_libraries(openapi_test PRIVATE http_parser.host)
add_unit_test(
logger_json_test
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/logger_json_test.cpp
)
add_unit_test(
kv_test
${CMAKE_CURRENT_SOURCE_DIR}/src/kv/test/kv_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/kv/test/kv_contention.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/kv/test/kv_serialisation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/kv/test/kv_snapshot.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/kv/test/kv_dynamic_tables.cpp
)
target_link_libraries(
kv_test PRIVATE ${CMAKE_THREAD_LIBS_INIT} http_parser.host ccf_kv.host
)
add_unit_test(
ds_test
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/ring_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/messaging.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/oversized.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/typed_messages.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/serializer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/hash.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/thread_messaging.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/lru.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/hex.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/nonstd.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/contiguous_set.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/unit_strings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ds/test/dl_list.cpp
)
target_link_libraries(ds_test PRIVATE ${CMAKE_THREAD_LIBS_INIT})
add_unit_test(
ledger_test ${CMAKE_CURRENT_SOURCE_DIR}/src/host/test/ledger.cpp
)
add_unit_test(
raft_test ${CMAKE_CURRENT_SOURCE_DIR}/src/consensus/aft/test/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/consensus/aft/test/view_history.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/consensus/aft/test/committable_suffix.cpp
)
target_link_libraries(raft_test PRIVATE ccfcrypto.host)
add_unit_test(
raft_enclave_test
${CMAKE_CURRENT_SOURCE_DIR}/src/consensus/aft/test/enclave.cpp
)
target_include_directories(raft_enclave_test PRIVATE ${CCFCRYPTO_INC})
target_link_libraries(raft_enclave_test PRIVATE ccfcrypto.host)
add_unit_test(
crypto_test ${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/crypto.cpp
)
target_include_directories(crypto_test PRIVATE ${CCFCRYPTO_INC})
target_link_libraries(crypto_test PRIVATE ccfcrypto.host)
add_unit_test(
sharing_test
${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/secret_sharing.cpp
)
target_include_directories(sharing_test PRIVATE ${CCFCRYPTO_INC})
target_link_libraries(sharing_test PRIVATE ccfcrypto.host)
add_unit_test(
key_exchange_test
${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/key_exchange.cpp
)
target_link_libraries(key_exchange_test PRIVATE)
add_unit_test(