forked from aws/aws-nitro-enclaves-sdk-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
146 lines (115 loc) · 4.67 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
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.
cmake_minimum_required(VERSION 3.1)
project(aws-nitro-enclaves-sdk-c C)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) # Enable LTO/IPO if available in the compiler, see AwsCFlags
endif()
if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
endif()
if (DEFINED CMAKE_INSTALL_PREFIX)
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
endif()
if (UNIX AND NOT APPLE)
include(GNUInstallDirs)
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH
set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake")
string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}")
# Append that generated list to the module search path
list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH})
include(AwsCFlags)
include(AwsCheckHeaders)
include(AwsSharedLibSetup)
include(AwsSanitizers)
include(AwsFindPackage)
include(CTest)
option(BUILD_RELOCATABLE_BINARIES
"Build Relocatable Binaries, this will turn off features that will fail on older kernels than used for the build."
OFF)
file(GLOB AWS_NITRO_ENCLAVES_HEADERS
"include/aws/nitro_enclaves/*.h"
)
file(GLOB AWS_NITRO_ENCLAVES_TESTING_HEADERS
"include/aws/testing/*.h"
)
file(GLOB AWS_NITRO_ENCLAVES_SRC
"source/*.c"
)
execute_process(COMMAND git describe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE VERSION)
if ("${VERSION}" STREQUAL "")
set(VERSION "v0.2.1-unknown")
endif()
message(STATUS "Version=" ${VERSION})
add_definitions(-DVERSION="${VERSION}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
find_package(LibJsonC REQUIRED)
if (NOT WIN32)
find_library(LibNSM NAMES nsm REQUIRED)
set(PLATFORM_LIBS LibJsonC::Json "${LibNSM}")
else()
set(PLATFORM_LIBS LibJsonC::Json)
include_directories(AFTER "${CMAKE_CURRENT_SOURCE_DIR}/include/aws/vsock")
endif()
aws_use_package(aws-c-common)
aws_use_package(aws-c-io)
aws_use_package(aws-c-http)
aws_use_package(aws-c-auth)
add_subdirectory(bin/kmstool-instance)
if (NOT WIN32)
add_library(${PROJECT_NAME} ${LIBTYPE} ${AWS_NITRO_ENCLAVES_HEADERS} ${AWS_NITRO_ENCLAVES_SRC})
aws_set_common_properties(${PROJECT_NAME})
aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_NITRO_ENCLAVES")
aws_check_headers(${PROJECT_NAME} ${AWS_NITRO_ENCLAVES_HEADERS})
aws_add_sanitizers(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION "${VERSION}")
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 0unstable)
target_compile_definitions(${PROJECT_NAME} PUBLIC)
if (BUILD_RELOCATABLE_BINARIES)
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DCOMPAT_MODE")
endif()
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS} ${PLATFORM_LIBS})
aws_prepare_shared_lib_exports(${PROJECT_NAME})
install(FILES ${AWS_NITRO_ENCLAVES_HEADERS} DESTINATION "include/aws/nitro_enclaves" COMPONENT Development)
install(FILES ${AWS_NITRO_ENCLAVES_TESTING_HEADERS} DESTINATION "include/aws/testing" COMPONENT Development)
if (BUILD_SHARED_LIBS)
set (TARGET_DIR "shared")
else()
set (TARGET_DIR "static")
endif()
install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)
configure_file("cmake/${PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake/"
COMPONENT Development)
if (NOT CMAKE_CROSSCOMPILING)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
endif()
if (NOT CMAKE_CROSSCOMPILING)
add_subdirectory(bin/kmstool-enclave)
add_subdirectory(bin/kmstool-enclave-cli)
endif()
find_package(Doxygen OPTIONAL_COMPONENTS dot mscgen dia)
if (DOXYGEN_FOUND)
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_GENERATE_MAN YES)
set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES)
doxygen_add_docs(docs ALL ${AWS_NITRO_ENCLAVES_HEADERS})
endif()
endif()