-
Notifications
You must be signed in to change notification settings - Fork 34
/
CMakeLists.txt
120 lines (102 loc) · 2.98 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
# CMake version
cmake_minimum_required(VERSION 3.5.1)
# Project
project(rats-tls)
set(RTLS_LIB rats_tls)
set(RTLS_SRC_PATH ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Software version
file(STRINGS "VERSION" RATS_TLS_VERSION)
set(VERSION ${RATS_TLS_VERSION})
string(REPLACE "." ";" VERSION_LIST ${RATS_TLS_VERSION})
list(GET VERSION_LIST 0 VERSION_MAJOR)
list(GET VERSION_LIST 1 VERSION_MINOR)
list(GET VERSION_LIST 2 VERSION_PATCH)
# Build options
option(BUILD_SAMPLES "Compile sample code along with libraries" ON)
option(SGX_HW "Run SGX on hardware, OFF for simulation" ON)
option(SGX_LVI_MITIGATION "Mitigation flag, default on" ON)
option(BUILD_FUZZ "Use lib-fuzzer to fuzz the code, default OFF" OFF)
# Define build mode
set(RATS_TLS_BUILD_MODE "host"
CACHE STRING "Select build mode for rats-tls(normal|occlum|sgx)")
# Print build mode
message(STATUS "Build Mode: ${RATS_TLS_BUILD_MODE}")
# CMake modules path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Bulid mode macro
# normal: NORMAL
# occlum: OCCLUM
# sgx: SGX
# tdx: TDX
if(RATS_TLS_BUILD_MODE STREQUAL "host")
set(HOST 1)
add_definitions(-DHOST)
elseif(RATS_TLS_BUILD_MODE STREQUAL "occlum")
set(OCCLUM 1)
add_definitions(-DOCCLUM)
elseif(RATS_TLS_BUILD_MODE STREQUAL "sgx")
include(FindSGX)
if(NOT SGX_FOUND)
message(FATAL_ERROR "Not found intel sgx sdk !")
else()
message(STATUS "Found intel sgx sdk.")
endif()
set(SGX 1)
add_definitions(-DSGX)
elseif(RATS_TLS_BUILD_MODE STREQUAL "tdx")
set(TDX 1)
add_definitions(-DTDX)
else()
message(FATAL_ERROR "Invalid build mode!")
endif()
# Default build type
set(RATS_TLS_BUILD_TYPE "debug"
CACHE STRING "Select build type for rats-tls(debug|prerelease|release)"
)
# Print build type
message(STATUS "Build Type: ${RATS_TLS_BUILD_TYPE}")
# Build type macro
# debug: DEBUG
# prerelease: PRERELEASE
# release: RELEASE
if(RATS_TLS_BUILD_TYPE STREQUAL "debug")
set(DEBUG 1)
set(SGX_DEBUG 1)
elseif(RATS_TLS_BUILD_TYPE STREQUAL "prerelease")
set(PRERELEASE 1)
set(SGX_PRERELEASE 1)
elseif(RATS_TLS_BUILD_TYPE STREQUAL "release")
set(RELEASE 1)
set(SGX_RELEASE 1)
else()
message(FATAL_ERROR "Invalid build type!")
endif()
# Include custom modules
include(CustomInstallDirs)
include(CompilerOptions)
if(SGX)
include(SGXCommon)
include(SGXSSL)
include(LibCBOR)
endif()
# Subdirectory
add_subdirectory(src)
if(BUILD_SAMPLES)
message(STATUS "Build Samples: on")
add_subdirectory(samples)
endif()
if(BUILD_FUZZ)
message(STATUS "Build Fuzz: on")
add_subdirectory(fuzz)
endif()
# Uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeUninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()