forked from Azure/azure-utpm-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
218 lines (184 loc) · 6.26 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
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
cmake_minimum_required(VERSION 2.8.11)
project(utpm)
set(UTPM_VERSION 1.0.1)
option(use_emulator "build using the tpm emulator" ON)
option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF)" OFF)
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF)
option(run_int_tests "set run_int_tests to ON to integration tests (default is OFF)." OFF)
option(skip_samples "set skip_samples to ON to skip building samples (default is OFF)[if possible, they are always built]" OFF)
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF)
option(use_custom_heap "use externally defined heap functions instead of the malloc family" OFF)
if(${use_custom_heap})
add_definitions(-DGB_USE_CUSTOM_HEAP)
endif()
#do not add or build any tests of the dependencies
set(original_run_e2e_tests ${run_e2e_tests})
set(original_run_int_tests ${run_int_tests})
set(original_run_unittests ${run_unittests})
set(original_skip_samples ${skip_samples})
set(run_e2e_tests OFF)
set(run_int_tests OFF)
set(run_unittests OFF)
set(skip_samples ON)
if(NOT ${use_installed_dependencies})
if (NOT TARGET azure_macro_utils_c AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/deps/azure-macro-utils-c/CMakeLists.txt")
add_subdirectory(deps/azure-macro-utils-c)
include_directories(${MACRO_UTILS_INC_FOLDER})
endif()
if (NOT TARGET umock_c)
add_subdirectory(deps/umock-c)
include_directories(${UMOCK_C_INC_FOLDER})
endif()
if(${original_run_e2e_tests} OR ${original_run_unittests})
if (NOT TARGET testrunnerswitcher)
add_subdirectory(deps/azure-c-testrunnerswitcher)
endif()
if (NOT TARGET ctest)
add_subdirectory(deps/azure-ctest)
endif()
endif()
if (NOT TARGET aziotsharedutil AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/deps/c-utility/CMakeLists.txt")
add_subdirectory(deps/c-utility)
include_directories(${SHARED_UTIL_INC_FOLDER})
endif()
enable_testing()
endif()
set(run_e2e_tests ${original_run_e2e_tests})
set(run_int_tests ${original_run_int_tests})
set(run_unittests ${original_run_unittests})
set(skip_samples ${original_skip_samples})
set(TPM_C_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using sharedLib lib" FORCE)
set_platform_files(${SHARED_UTIL_FOLDER})
if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers ")
endif()
set(utpm_c_files
./src/Marshal.c
./src/Memory.c
./src/tpm_codec.c
./src/gbfiledescript.c
)
set(utpm_h_files
./inc/azure_utpm_c/BaseTypes.h
./inc/azure_utpm_c/Capabilities.h
./inc/azure_utpm_c/CompilerDependencies.h
./inc/azure_utpm_c/GpMacros.h
./inc/azure_utpm_c/gbfiledescript.h
./inc/azure_utpm_c/Implementation.h
./inc/azure_utpm_c/Marshal_fp.h
./inc/azure_utpm_c/Memory_fp.h
./inc/azure_utpm_c/swap.h
./inc/azure_utpm_c/Tpm.h
./inc/azure_utpm_c/TPMB.h
./inc/azure_utpm_c/TpmBuildSwitches.h
./inc/azure_utpm_c/TpmError.h
./inc/azure_utpm_c/TpmTypes.h
./inc/azure_utpm_c/tpm_codec.h
./inc/azure_utpm_c/tpm_comm.h
)
if (APPLE)
# For apple don't include file decript
else()
set(utpm_h_files
${utpm_h_files}
./inc/azure_utpm_c/gbfiledescript.h
)
set(utpm_c_files
${utpm_c_files}
./src/gbfiledescript.c
)
endif()
if (${use_emulator})
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
set(utpm_h_files
${utpm_h_files}
./inc/azure_utpm_c/tpm_socket_comm.h
)
set(utpm_c_files
${utpm_c_files}
./src/tpm_comm_emulator.c
./src/tpm_socket_comm.c
)
else()
if (WIN32)
set(utpm_c_files
${utpm_c_files}
./src/tpm_comm_win32.c
)
else()
set(utpm_c_files
${utpm_c_files}
./src/tpm_comm_linux.c
./src/tpm_socket_comm.c
)
endif()
endif()
include_directories(./inc)
if (WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DGB_MEASURE_MEMORY_FOR_THIS -DGB_DEBUG_ALLOC)
endif (WIN32)
add_library(utpm ${utpm_c_files} ${utpm_h_files})
target_link_libraries(utpm aziotsharedutil)
if (${use_emulator})
else ()
if (WIN32)
target_link_libraries(utpm tbs)
else()
target_link_libraries(utpm dl)
endif()
endif()
if (${run_unittests})
add_subdirectory(tests)
endif()
if (NOT ${skip_samples})
add_subdirectory(samples)
endif()
# Set CMAKE_INSTALL_LIBDIR if not defined
include(GNUInstallDirs)
if(${use_installed_dependencies})
# Install utpm
set(package_location "cmake")
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
install(TARGETS utpm EXPORT utpmTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot
)
install(FILES ${utpm_h_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azureiot/azure_utpm_c)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${UTPM_VERSION}
COMPATIBILITY SameMajorVersion
)
install(EXPORT utpmTargets
FILE
"${PROJECT_NAME}Targets.cmake"
DESTINATION
${package_location}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${package_location}
)
else()
set(install_staticlibs
utpm
)
install(FILES ${utpm_h_files}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/azure_utpm_c)
install(TARGETS ${install_staticlibs}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
compileTargetAsC99(utpm)