Skip to content

Commit

Permalink
SKA-318: cmake install target improvements (#28)
Browse files Browse the repository at this point in the history
- install target can now also be used with "--target install" (not only for "--target package")
- output folder structure has been reworked for that purpose
- updated readme.md and demo script accordingly
  • Loading branch information
VSvenMorgenthaler authored and GitHub Enterprise committed Dec 8, 2023
1 parent 501525c commit 49a2add
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ out/
/out/
/.vs/
/build/
/_build/
/install/
/_install/
/Downloads/
/bin/
/lib/
/*/build/
/CMakeSettings.json
98 changes: 75 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 17)

set(SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(SILKIT_ADAPTERS_VCAN_LIBRARY_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib")

set(SILKIT_VERSION "4.0.36" CACHE STRING "If no SIL Kit package is specified, this version will be downloaded")
set(SILKIT_VERSION "4.0.42" 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)
Expand All @@ -33,12 +34,11 @@ if(DEFINED 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")
if(WIN32)
# only look for installed version of SIL Kit (.msi) if environment is Windows
find_package(SilKit 4.0.7
CONFIG
)
endif()

find_package(SilKit 4.0.7
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")
Expand Down Expand Up @@ -86,43 +86,91 @@ add_subdirectory(SocketCAN/demos)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN
${CMAKE_CURRENT_SOURCE_DIR}/third_party
DESTINATION .
COMPONENT source
EXCLUDE_FROM_ALL
REGEX "\.git$" EXCLUDE
REGEX "\.github$" EXCLUDE
)

install(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/third_party
DESTINATION .
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/OpenVCan_can0.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/SendSocketCANFrames.sh
${CMAKE_CURRENT_SOURCE_DIR}/SocketCAN/demos/shell_scripts/setup_vCAN_start_adapter_send_frames.sh
DESTINATION SocketCAN/demos/shell_scripts
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
COMPONENT source
REGEX "\.git$" EXCLUDE
REGEX "\.github$" EXCLUDE
EXCLUDE_FROM_ALL
)

install(
FILES
CMakeLists.txt
CMakePresets.json
DESTINATION .
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
README.md
SECURITY.md
CONTRIBUTING.md
DESTINATION .
COMPONENT source
EXCLUDE_FROM_ALL
)

include(GNUInstallDirs)

install(
DIRECTORY
${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}
DESTINATION build
COMPONENT bin
FILES
${SILKIT_ADAPTERS_VCAN_LIBRARY_DIRECTORY}/libSilKit.so
DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS
OWNER_READ OWNER_WRITE
GROUP_READ
WORLD_READ
COMPONENT lib
EXCLUDE_FROM_ALL
)

install(
TARGETS
SilKitDemoCanEchoDevice
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 SilKitAdapterSocketCAN should be installed to /usr/local/bin by calling --target install (therefore it is not excluded)
install(
TARGETS
SilKitAdapterSocketCAN
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/SilKitAdapterSocketCAN COMPONENT Development
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)

###############################################################################
Expand All @@ -137,4 +185,8 @@ 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)
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"SILKIT_VERSION": "4.0.36",
"SILKIT_VERSION": "4.0.42",
"SILKIT_FLAVOR": "ubuntu-18.04-x86_64-gcc"
},
"condition": {
Expand Down
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ The adapters and demos are built using ``cmake``:
cmake -S. -Bbuild -DSILKIT_PACKAGE_DIR=/path/to/SilKit-x.y.z-$ubuntu/ -D CMAKE_BUILD_TYPE=Release
cmake --build build --parallel

**Note 1:** If you have installed a self-built version of SIL Kit, you can build the adapter against it by setting SILKIT_PACKAGE_DIR to the installation path, where the bin, include and lib directories are.
**Note 1:** If you have a self-built or pre-built version of SIL Kit, you can build the adapter against it by setting SILKIT_PACKAGE_DIR to the path, where the bin, include and lib directories are.

**Note 2:** If you don't provide a specific path for SILKIT_PACKAGE_DIR, a SIL Kit release package (the default version listed in CMakeLists.txt) will be fetched from github.com and the adapter will be built against it.
**Note 2:** If you have SIL Kit installed on your system, you can build the adapter against it, even by not providing SILKIT_PACKAGE_DIR to the installation path at all.

The adapter executable will be available in ``build/bin`` (depending on the configured build directory).
Additionally the ``SilKit`` shared object (e.g., ``libSilKitd.so``) is copied to that directory automatically.
**Note 3:** If you don't provide a specific path for SILKIT_PACKAGE_DIR and there is no SIL Kit installation on your system, a SIL Kit release package (the default version listed in CMakeLists.txt) will be fetched from github.com and the adapter will be built against it.


The adapters and demo executables will be available in the ``bin`` directory.
Additionally the ``SilKit`` shared library is copied to the ``lib`` directory next to it automatically.

## b) Getting Started with pre-built Adapter and Demos
Download a preview or a release of the Adapter directly from [Vector SIL Kit Adapters Releases](https://github.com/vectorgrp/sil-kit-adapters-vcan/releases).

You should also download a SIL Kit Release directly from [Vector SIL Kit Releases](https://github.com/vectorgrp/sil-kit/releases). You will need this for being able to start a sil-kit-registry.

## Install the SilKitAdapterSocketCAN (optional)
If you call the following command (can be done for self build and pre build package after cmake configure) ``SilKitAdapterSocketCAN`` can be called from everywhere without defining a path:

sudo cmake --build build --target install

The default installation path will be ``/usr/local/bin``. Be aware that SIL Kit itself also needs to be installed to make this work.

## Run the SilKitAdapterSocketCAN
This application allows the user to attach virtual CAN interfaces (``SocketCAN``) running in Linux environment to the
SIL Kit.
Expand All @@ -71,13 +81,13 @@ Now you can run the adapter from terminal.

The application *optionally* takes the following command line arguments:

./build/bin/SilKitAdapterSocketCAN [--name <participant name{SilKitAdapterSocketCAN}>]
[--configuration <path to .silkit.yaml or .json configuration file>]
[--registry-uri silkit://<host{localhost}>:<port{8501}>]
[--log <Trace|Debug|Warn|{Info}|Error|Critical|Off>]
[--can-name <vCAN device name{can0}>]
[--network <SIL Kit CAN network{CAN1}>]
[--help]
./bin/SilKitAdapterSocketCAN [--name <participant name{SilKitAdapterSocketCAN}>]
[--configuration <path to .silkit.yaml or .json configuration file>]
[--registry-uri silkit://<host{localhost}>:<port{8501}>]
[--log <Trace|Debug|Warn|{Info}|Error|Critical|Off>]
[--can-name <vCAN device name{can0}>]
[--network <SIL Kit CAN network{CAN1}>]
[--help]
**Note:** SIL Kit-specific CLI arguments will be overwritten by the config file specified by ``--configuration``.

## SocketCAN Demo
Expand Down
4 changes: 2 additions & 2 deletions SocketCAN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Now is a good point to start the `sil-kit-registry`:

After that, launch the SilKitAdapterSocketCAN

./build/bin/SilKitAdapterSocketCAN --configuration ./SocketCAN/demos/SilKitConfig_Adapter.silkit.yaml
./bin/SilKitAdapterSocketCAN --configuration ./SocketCAN/demos/SilKitConfig_Adapter.silkit.yaml

You should see the following output in the terminal where the adapter was launched:

Expand All @@ -87,7 +87,7 @@ You should see also a `SilKitAdapterSocketCAN` participant announcement in the S

In a separate Terminal, launch the CanEchoDevice

./build/bin/SilKitDemoCanEchoDevice
./bin/SilKitDemoCanEchoDevice

You should see the following output in the terminal after launching the CanEchoDevice:

Expand Down
4 changes: 2 additions & 2 deletions SocketCAN/adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ target_link_libraries(SilKitAdapterSocketCAN
set_target_properties(SilKitAdapterSocketCAN
PROPERTIES
#ensure SilKit shared libraries can be loaded
INSTALL_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN"
BUILD_RPATH "$ORIGIN"
RUNTIME_OUTPUT_DIRECTORY $<$<BOOL:ALWAYS>:${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}>
)
add_custom_command(
TARGET SilKitAdapterSocketCAN
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy $<TARGET_FILE:SilKit::SilKit> ${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}
ARGS -E copy $<TARGET_FILE:SilKit::SilKit> ${SILKIT_ADAPTERS_VCAN_LIBRARY_DIRECTORY}/libSilKit.so
)

2 changes: 1 addition & 1 deletion SocketCAN/demos/CANoe4SW_SE/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ sleep 1

<&3 $scriptDir/../shell_scripts/setup_vCAN_start_adapter_send_frames.sh &> $scriptDir/setup_vCAN_start_adapter_send_frames.out &

<&3 $scriptDir/../../../build/bin/SilKitDemoCanEchoDevice &> $scriptDir/SilKitDemoCanEchoDevice.out &
<&3 $scriptDir/../../../bin/SilKitDemoCanEchoDevice &> $scriptDir/SilKitDemoCanEchoDevice.out &

$scriptDir/run.sh
2 changes: 1 addition & 1 deletion SocketCAN/demos/EchoDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target_link_libraries(SilKitDemoCanEchoDevice
set_target_properties(SilKitDemoCanEchoDevice
PROPERTIES
#ensure SilKit shared libraries can be loaded
INSTALL_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN"
BUILD_RPATH "$ORIGIN"
RUNTIME_OUTPUT_DIRECTORY $<$<BOOL:ALWAYS>:${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}>
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

scriptDir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# cleanup trap for child processes
trap 'kill $(jobs -p); exit' EXIT SIGHUP;
Expand All @@ -20,19 +20,20 @@ rm $tmp_fifo

# Setup can0
echo "Setting up [can0]..."
<&3 $scriptDir/OpenVCan_can0.sh &> $scriptDir/OpenVCan_can0.out
<&3 $SCRIPT_DIR/OpenVCan_can0.sh &> $SCRIPT_DIR/OpenVCan_can0.out


# Start adapter
echo "Starting SKA vCAN..."
<&3 $scriptDir/../../../build/bin/SilKitAdapterSocketCAN &> $scriptDir/SilKitAdapterSocketCAN.out &
echo "Starting SilKitAdapterSocketCAN..."
<&3 $SCRIPT_DIR/../../../bin/SilKitAdapterSocketCAN &> $SCRIPT_DIR/SilKitAdapterSocketCAN.out &
sleep 1 # wait 1 second for the creation/existens of the .out file

# Wait for adapter to start and connect to both [can0] and SIL Kit
sleep 2
timeout 30s grep -q 'Created CAN device connector for ' <(tail -f /$SCRIPT_DIR/SilKitAdapterSocketCAN.out) || exit 1
echo "SilKitAdapterSocketCAN has been started"

# Send frames on [can0]
echo "Sending CAN frames on [can0]..."
<&3 $scriptDir/SendSocketCANFrames.sh &> $scriptDir/SendSocketCANFrames.out &
<&3 $SCRIPT_DIR/SendSocketCANFrames.sh &> $SCRIPT_DIR/SendSocketCANFrames.out &

# Wait for the SendSocketCANFrames process to complete (300 frames @ 2Hz -> 150 sec maximum wait)
sleep 150

0 comments on commit 49a2add

Please sign in to comment.