-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (122 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
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
cmake_minimum_required(VERSION 3.15)
project(adb_lib)
set(CMAKE_CXX_STANDARD 17)
# Setup
set(ADBLIB_VERSION "1.0.0")
set(source_dir
src)
set(source
${source_dir}/APacket.cpp
${source_dir}/UsbTransport.cpp
${source_dir}/Transport.cpp
${source_dir}/APayload.cpp
${source_dir}/AdbBase.cpp
${source_dir}/Features.cpp
${source_dir}/AdbDevice.cpp
${source_dir}/utils.cpp
${source_dir}/streams/AdbStreamBase.cpp
${source_dir}/streams/AdbIStream.cpp
${source_dir}/streams/AdbOStream.cpp)
set(headers_dir
include)
set(headers
${headers_dir}/AdbBase.hpp
${headers_dir}/AdbDevice.hpp
${headers_dir}/adb.hpp
${headers_dir}/AdbStreams.hpp
${headers_dir}/APacket.hpp
${headers_dir}/APayload.hpp
${headers_dir}/Features.hpp
${headers_dir}/Transport.hpp
${headers_dir}/UsbTransport.hpp
${headers_dir}/utils.hpp
${headers_dir}/streams/AdbIStream.hpp
${headers_dir}/streams/AdbOStream.hpp
${headers_dir}/streams/AdbStreamBase.hpp)
set(cmake_config
cmake/adblib-config.cmake)
set(lib_destination
"lib/adblib-${ADBLIB_VERSION}")
set(headers_destination
"include/adblib-${ADBLIB_VERSION}")
set(cmake_destination
${lib_destination})
add_library(adblib
${source})
# ! Setup
# Build
# Include
target_include_directories(adblib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${headers_dir}>
$<INSTALL_INTERFACE:${headers_destination}>)
# ! Include
# Mbed TLS
if (DEFINED MBED_TLS_ROOT)
set(CMAKE_PREFIX_PATH "${MBED_TLS_ROOT};${CMAKE_PREFIX_PATH}")
message(NOTICE "MBED_TLS_ROOT added to CMake prefix")
endif()
find_package(MbedTLS 3.0.0)
if(MbedTLS_FOUND)
message(NOTICE "MbedTLS found")
target_link_libraries(adblib PUBLIC
MbedTLS::mbedtls
MbedTLS::mbedcrypto
MbedTLS::mbedx509)
else()
message(NOTICE "MbedTLS not found. Trying to link MbedTLS from provided paths...")
if ((MBED_TLS_INCLUDE_DIR STREQUAL "") OR (MBED_TLS_LIBRARIES STREQUAL ""))
message(SEND_ERROR "MbedTLS paths are not set")
else()
message(NOTICE "MbedTLS include dir: ${MBED_TLS_INCLUDE_DIR}")
message(NOTICE "MbedTLS libraries dir: ${MBED_TLS_LIBRARIES}")
target_link_libraries(adblib PUBLIC "${MBED_TLS_LIBRARIES}")
target_include_directories(adblib PUBLIC
${MBED_TLS_INCLUDE_DIR})
endif()
endif()
# ! Mbed TLS
# ObjLibusb
if (DEFINED OBJLIBUSB_ROOT)
set(CMAKE_PREFIX_PATH "${OBJLIBUSB_ROOT};${CMAKE_PREFIX_PATH}")
message(NOTICE "OBJLIBUSB_ROOT added to CMake prefix")
endif()
find_package(ObjLibusb)
if (ObjLibusb_FOUND)
message(NOTICE "ObjLibusb found")
if(DEFINED UNIX)
find_package(Threads REQUIRED)
endif()
target_link_libraries(adblib PUBLIC ObjLibusb)
else()
message(NOTICE "ObjLibusb not found. Trying to link ObjLibusb from provided paths")
if ((OBJLIBUSB_INCLUDE_DIR STREQUAL "") OR (OBJLIBUSB_LIBRARY STREQUAL ""))
message(SEND_ERROR "ObjLibusb paths are not set")
else()
message(NOTICE "ObjLibusb include dir: ${OBJLIBUSB_INCLUDE_DIR}")
message(NOTICE "ObjLibusb libraries dir: ${OBJLIBUSB_LIBRARY}")
target_link_libraries(adblib PUBLIC
${OBJLIBUSB_LIBRARY})
target_include_directories(adblib PUBLIC
${OBJLIBUSB_INCLUDE_DIR})
endif()
endif()
# ! ObjLibusb
# ! Build
# Install
install(TARGETS adblib EXPORT adblib DESTINATION "${lib_destination}/${CMAKE_BUILD_TYPE}")
install(EXPORT adblib DESTINATION "${lib_destination}/${CMAKE_BUILD_TYPE}")
install(FILES ${headers} DESTINATION "${headers_destination}") # headers
install(FILES ${cmake_config} DESTINATION ${cmake_destination}) # package
# ! Install
# Tests
add_executable(test_transport tests/test_transport.cpp)
add_executable(test_base tests/test_adb_base.cpp)
add_executable(test_device tests/test_adb_device.cpp)
add_executable(test_shell tests/test_adb_shell.cpp)
add_executable(test_utils tests/test_utils.cpp)
target_link_libraries(test_transport adblib)
target_link_libraries(test_base adblib)
target_link_libraries(test_device adblib)
target_link_libraries(test_shell adblib)
target_link_libraries(test_utils adblib)
# ! Tests