-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathCMakeLists.txt
110 lines (92 loc) · 4.31 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
# Microsoft Reference Implementation for TPM 2.0
# Copyright (c) Microsoft Corporation
# This software is being made available under certain license terms, as detailed at
# https://github.com/microsoft/ms-tpm-20-ref/blob/main/LICENSE
#
cmake_minimum_required(VERSION 3.16.3)
include(${CMAKE_CURRENT_SOURCE_DIR}/../tpm/cmake/tpm_support.cmake)
project(Simulator)
print_project_info()
set(CMAKE_CONFIGURATION_TYPES "Debug"
CACHE STRING "Configuration types" FORCE)
# use standard output directories. Expected by package_utilities
include(GNUInstallDirs)
add_executable(Simulator
src/TcpServer.c
src/TPMCmdp.c
src/TPMCmds.c
)
# Additional include directories
# simulator folders
target_include_directories(Simulator PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include;
${CMAKE_CURRENT_SOURCE_DIR}/include/prototypes;
)
# Preprocessor definitions
target_compile_definitions(Simulator PRIVATE
_UNICODE
_CONSOLE
_DIAGNOSTICS
)
# Only call find_package if this CMakeLists file is not being included via
# add_subdirectory. Calling find_package during add_subdirectory will cause the
# REQUIRED clause of the find_pacakge to fail since they haven't been built
# yet.)
if(PROJECT_IS_TOP_LEVEL)
# External libs and include directories
find_package(Tpm_CompilerOptions PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(TpmConfiguration CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_Public_Headers CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_Platform_Interface CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_PlatformLib CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_CryptoLib_Common PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_CryptoLib_TpmBigNum_Headers PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_CryptoLib_Math_Ossl CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_CryptoLib_TpmBigNum CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
find_package(Tpm_CoreLib CONFIG REQUIRED PATHS ${CMAKE_INSTALL_PREFIX} NO_DEFAULT_PATH )
endif()
# Link libraries
target_link_libraries(Simulator PUBLIC TpmConfiguration::TpmConfiguration)
target_link_libraries(Simulator PUBLIC Tpm_Public_Headers::Tpm_Public_Headers)
target_link_libraries(Simulator PUBLIC Tpm_PlatformLib::Tpm_PlatformLib)
target_link_libraries(Simulator PUBLIC Tpm_Platform_Interface::Tpm_Platform_Interface)
target_link_libraries(Simulator PUBLIC Tpm_CoreLib::Tpm_CoreLib)
target_link_libraries(Simulator PUBLIC Tpm_CryptoLib_TpmBigNum::Tpm_CryptoLib_TpmBigNum)
set(WIN_LIBCRYPTO_PATH)
if(WIN32)
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set(WIN_LIBCRYPTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib/x64")
set(source_filename libcrypto-1_1-x64.dll)
elseif( CMAKE_SIZEOF_VOID_P EQUAL 4 )
set(WIN_LIBCRYPTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib")
set(source_filename libcrypto-1_1.dll)
else()
message(FATAL_ERROR "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}")
endif()
target_link_libraries(Simulator PRIVATE
Ws2_32.lib
Rpcrt4.lib
)
target_link_directories(Simulator PRIVATE ${WIN_LIBCRYPTO_PATH})
# copy the openssl dll to simulator output folder if TPM is using openssl.
# only necessary on WIN32.
message(DEBUG "adding target to copy ${WIN_LIBCRYPTO_PATH}/${source_filename} to simulator folder")
# target must be included in ALL or it won't be built by default
# since the direction of the dependency is simulator->copy,
# specifying DEPENDS here doesn't include the copy if simulator is built, but
# would build Simulator if --target copy_libcrypto_dll is built first.
add_custom_target(copy_libcrypto_dll ALL
COMMAND ${CMAKE_COMMAND} -E
copy ${WIN_LIBCRYPTO_PATH}/${source_filename} $<TARGET_FILE_DIR:Simulator>/${source_filename}
)
install(FILES ${WIN_LIBCRYPTO_PATH}/${source_filename}
DESTINATION ${CMAKE_INSTALL_BINDIR})
else()
# not supported yet.
endif ()
# include Simulator
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)