-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
227 lines (196 loc) · 7.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
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
219
220
221
222
223
224
225
226
227
cmake_minimum_required(VERSION 3.5)
project(VectorSilKitAdapterVcan)
include(FetchContent)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(SILKIT_ADAPTER_VCAN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(SILKIT_ADAPTER_VCAN_LIBRARY_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")
set(SILKIT_VERSION "4.0.50" CACHE STRING "If no SIL Kit package is specified, this version will be downloaded")
set(SILKIT_FLAVOR "ubuntu-18.04-x86_64-gcc" CACHE STRING "If no SIL Kit package is specified, this package flavor will be downloaded")
find_package(Threads REQUIRED)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/asio/asio/include)
target_compile_definitions(asio INTERFACE ASIO_STANDALONE=1)
target_link_libraries(asio INTERFACE Threads::Threads)
# Set SIL Kit lib name
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(SILKIT_SO_NAME "libSilKit.so")
else() # Debug or RelWithDebInfo
set(SILKIT_SO_NAME "libSilKitd.so")
endif()
if(DEFINED SILKIT_PACKAGE_DIR)
# if the user forces using a specific SIL Kit package, use it
message(STATUS "SILKIT_PACKAGE_DIR has been set to: ${SILKIT_PACKAGE_DIR}, CMAKE will look for a SIL Kit package in that directory")
find_package(SilKit 4.0.40
REQUIRED
CONFIG
NO_CMAKE_PACKAGE_REGISTRY
NO_DEFAULT_PATH
PATHS "${SILKIT_PACKAGE_DIR}"
)
else()
# otherwise, look for an installed version of SIL Kit
message(STATUS "SILKIT_PACKAGE_DIR has not been set by user. Attempting to find an installed version of SIL Kit")
find_package(SilKit 4.0.40
CONFIG
)
if(NOT SilKit_FOUND)
# if installed SIL Kit is not found, fetch it from github.com
message(STATUS "No installed version of SIL Kit was found. Attempting to fetch [SilKit-${SILKIT_VERSION}-${SILKIT_FLAVOR}] from github.com")
FetchContent_Declare(
silkit
URL https://github.com/vectorgrp/sil-kit/releases/download/sil-kit%2Fv${SILKIT_VERSION}/SilKit-${SILKIT_VERSION}-${SILKIT_FLAVOR}.zip
DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR}/Downloads
)
message(STATUS "SIL Kit: fetching [SilKit-${SILKIT_VERSION}-${SILKIT_FLAVOR}]")
FetchContent_MakeAvailable(silkit)
set(SILKIT_SOURCE_DIR ${silkit_SOURCE_DIR}/SilKit-Source)
message(STATUS "SIL Kit: using source code from: \"${SILKIT_SOURCE_DIR}\"")
message(STATUS "SIL Kit: using pre-built binaries from: ${silkit_SOURCE_DIR}")
message(STATUS "Searching SilKit package which has been fetched from github.com")
find_package(SilKit 4.0.40
REQUIRED
CONFIG
NO_CMAKE_PACKAGE_REGISTRY
NO_DEFAULT_PATH
PATHS "${silkit_SOURCE_DIR}"
)
endif()
endif()
if(TARGET SilKit::SilKit)
message(STATUS "SIL Kit package has been successfully imported as a CMake target. [version : ${SilKit_VERSION}]")
else()
message(FATAL_ERROR "Something went wrong : Could not find SIL Kit package.")
endif()
add_subdirectory(SocketCAN/adapter)
add_subdirectory(SocketCAN/demos)
################################################################################
# Distribution of the source code and binaries
################################################################################
# Install sources and binaries
# Copy all files from the source and bin directory to the proper destination
# Leave out git repo related data
install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN
${CMAKE_CURRENT_SOURCE_DIR}/third_party
${CMAKE_CURRENT_SOURCE_DIR}/.devcontainer
${CMAKE_CURRENT_SOURCE_DIR}/.vscode
DESTINATION .
COMPONENT source
EXCLUDE_FROM_ALL
REGEX "\.git$" EXCLUDE
REGEX "\.github$" EXCLUDE
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/setup_vcan_device.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/send_CAN_frames.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/setup_vcan_start_adapter_send_CAN_frames.sh
DESTINATION SocketCAN/demos/shell_scripts
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT source
EXCLUDE_FROM_ALL
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/tasks_scripts/build_adapter.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/tasks_scripts/prepare_run_silkit.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/tasks_scripts/run_EchoDevice.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/tasks_scripts/stop_processes.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/tasks_scripts/traffic_monitoring.sh
DESTINATION SocketCAN/demos/shell_scripts/tasks_scripts
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT source
EXCLUDE_FROM_ALL
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/Cuttlefish/prepare_cuttlefish_vcan_device.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/Cuttlefish/send_CAN_frames.sh
DESTINATION SocketCAN/demos/shell_scripts/Cuttlefish
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT source
EXCLUDE_FROM_ALL
)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/CANoe4SW_SE/run.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/CANoe4SW_SE/run_all.sh
DESTINATION SocketCAN/demos/CANoe4SW_SE
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT source
EXCLUDE_FROM_ALL
)
install(
FILES
CMakeLists.txt
CMakePresets.json
LICENSE
README.md
SECURITY.md
CONTRIBUTING.md
DESTINATION .
COMPONENT source
EXCLUDE_FROM_ALL
)
include(GNUInstallDirs)
install(
FILES
${SILKIT_ADAPTER_VCAN_LIBRARY_DIRECTORY}/${SILKIT_SO_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
WORLD_READ
COMPONENT lib
EXCLUDE_FROM_ALL
)
install(
TARGETS
sil-kit-demo-can-echo-device
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
EXCLUDE_FROM_ALL
)
# only sil-kit-adapter-vcan should be installed to /usr/local/bin by calling --target install (therefore it is not excluded)
install(
TARGETS
sil-kit-adapter-vcan
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/sil-kit-adapter-vcan COMPONENT Development
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
###############################################################################
# Packaging
###############################################################################
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_DESCRIPTION "binary release of SIL Kit Adapter vcan")
set(CPACK_PACKAGE_NAME "SilKit-Adapter-vcan")
set(CPACK_PACKAGE_VENDOR "Vector Informatik")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}${PACKAGE_FILENAME_SUFFIX}")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE ON)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY ON)
include(CPack)