-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
153 lines (120 loc) · 4.79 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
cmake_minimum_required(VERSION 3.13)
project(SecurityMiddleware VERSION 2.5 LANGUAGES C)
include(CMakeDependentOption)
# Configuration types
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Set default build type Release.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
else()
message(STATUS "Build type ${CMAKE_BUILD_TYPE}.")
endif()
option(CODE_COVERAGE "Enable Code Coverage analysis" OFF)
if(CODE_COVERAGE)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "Code coverage required build type \"Debug\"")
endif()
message(STATUS "Code Coverage enabled, force all traces ON")
set(VERBOSE 4)
endif()
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_INSTALL_PREFIX /usr)
include(GNUInstallDirs)
if(VERBOSE)
if(NOT VERBOSE MATCHES "^[0-9]$")
message(FATAL_ERROR "VERBOSE must be an integer")
endif()
if(NOT VERBOSE EQUAL 0)
add_definitions(-DENABLE_TRACE)
endif()
if(${VERBOSE} GREATER 4)
set(VERBOSE 4)
endif()
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(${VERBOSE} GREATER 2)
set(VERBOSE 2)
endif()
endif()
add_definitions(-DTRACE_LEVEL=${VERBOSE})
message(STATUS TRACE_LEVEL: ${VERBOSE})
else()
set(VERBOSE 0)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DENABLE_DEBUG)
endif()
option(ENABLE_KEYMGR_MODULE "Link the Key manager" ON)
option(ENABLE_HASH "Enable Hash" ON)
cmake_dependent_option(ENABLE_SIGN_VERIFY "Enable Sign and Verify" ON "ENABLE_KEYMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_HMAC "Enable HMAC - Deprecated" OFF "ENABLE_KEYMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_CIPHER "Enable Cipher" ON "ENABLE_KEYMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_MAC "Enable MAC" ON "ENABLE_KEYMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_AEAD "Enable authenticated encryption" ON "ENABLE_KEYMGR_MODULE" OFF)
option(ENABLE_RNG "Enable Random number generator" ON)
option(ENABLE_TLS12 "Enable TLS 1.2 features" OFF)
option(ENABLE_PSA_DEFAULT_ALT "Enable alternative subsystem selection for PSA API" OFF)
option(ENABLE_DEVMGR_MODULE "Enable device manager module" ON)
cmake_dependent_option(ENABLE_DEVICE_ATTESTATION "Enable device attestation" ON "ENABLE_DEVMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_DEVICE_LIFECYCLE "Enable device lifecycle" ON "ENABLE_DEVMGR_MODULE" OFF)
cmake_dependent_option(ENABLE_STORAGE_MODULE "Enable storage module" ON "ENABLE_KEYMGR_MODULE" OFF)
#
# Define all targets compiler options
#
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall -Wextra -Werror)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
#
# Define tests build and install targets
# Building SMW and/or PKCS11 tests with make command
# "make build_tests"
#
# Installing SMW and/PKCS11 tests with make command
# "make install_tests [DESTDIR=dir]"
#
# Allow OPTEE TA to be installed in a dedicated directory if the
# TEE_TA_DESTDIR is defined as cmake option.
if(NOT TEE_TA_DESTDIR)
set(TEE_TA_DESTDIR ${CMAKE_INSTALL_LIBDIR})
endif()
string(APPEND TEE_TA_DESTDIR "/optee_armtz")
string(PREPEND TEE_TA_DESTDIR "/")
string(REGEX REPLACE "[/]+" "/" TEE_TA_DESTDIR ${TEE_TA_DESTDIR})
file(TO_NATIVE_PATH ${TEE_TA_DESTDIR} TEE_TA_DESTDIR)
add_custom_target(build_tests)
add_custom_target(install_tests)
# Include OS Abstration layer
set(OS linux)
add_subdirectory(osal/${OS})
# Include SMW Library (using osal)
add_subdirectory(core)
# Include SMW Library tests
add_subdirectory(tests)
# Include PKCS#11 project
add_subdirectory(pkcs11)
# Include SMW Documentations
add_subdirectory(Documentations)
if(NOT DISABLE_CMAKE_CONFIG)
# Create the SMW Package configuration
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/NXP_SMWConfig.cmake.in
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/NXP_SMWConfig.cmake
INSTALL_DESTINATION cmake)
write_basic_package_version_file(
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/NXP_SMWConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/NXP_SMWConfig.cmake
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/NXP_SMWConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
export(EXPORT SMWTargets
NAMESPACE NXP_SMW::
FILE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/NXP_SMWTargets.cmake")
install(EXPORT SMWTargets
NAMESPACE NXP_SMW::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
FILE "NXP_SMWTargets.cmake")
endif()