From 49a2add2adee551d18aece310213d3101338152d Mon Sep 17 00:00:00 2001 From: "Morgenthaler, Sven" Date: Fri, 8 Dec 2023 14:45:08 +0100 Subject: [PATCH] SKA-318: cmake install target improvements (#28) - 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 --- .gitignore | 6 ++ CMakeLists.txt | 98 ++++++++++++++----- CMakePresets.json | 2 +- README.md | 32 +++--- SocketCAN/README.md | 4 +- SocketCAN/adapter/CMakeLists.txt | 4 +- SocketCAN/demos/CANoe4SW_SE/run_all.sh | 2 +- SocketCAN/demos/EchoDevice/CMakeLists.txt | 2 +- .../setup_vCAN_start_adapter_send_frames.sh | 15 +-- 9 files changed, 117 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 6cc186f..cf520c9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,11 @@ out/ /out/ /.vs/ /build/ +/_build/ +/install/ +/_install/ +/Downloads/ +/bin/ +/lib/ /*/build/ /CMakeSettings.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 89781c7..4696420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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") @@ -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 ) ############################################################################### @@ -137,4 +185,8 @@ set(CPACK_PACKAGE_VENDOR "Vector Informatik") set(CPACK_PACKAGE_CONTACT "support@vector.com") 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) diff --git a/CMakePresets.json b/CMakePresets.json index 5b064f5..32d0716 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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": { diff --git a/README.md b/README.md index 9e077b8..df0157a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 ] - [--configuration ] - [--registry-uri silkit://:] - [--log ] - [--can-name ] - [--network ] - [--help] + ./bin/SilKitAdapterSocketCAN [--name ] + [--configuration ] + [--registry-uri silkit://:] + [--log ] + [--can-name ] + [--network ] + [--help] **Note:** SIL Kit-specific CLI arguments will be overwritten by the config file specified by ``--configuration``. ## SocketCAN Demo diff --git a/SocketCAN/README.md b/SocketCAN/README.md index 300600f..899eed4 100644 --- a/SocketCAN/README.md +++ b/SocketCAN/README.md @@ -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: @@ -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: diff --git a/SocketCAN/adapter/CMakeLists.txt b/SocketCAN/adapter/CMakeLists.txt index 2018619..387e851 100644 --- a/SocketCAN/adapter/CMakeLists.txt +++ b/SocketCAN/adapter/CMakeLists.txt @@ -10,7 +10,7 @@ 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 $<$:${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}> ) @@ -18,6 +18,6 @@ add_custom_command( TARGET SilKitAdapterSocketCAN POST_BUILD COMMAND ${CMAKE_COMMAND} - ARGS -E copy $ ${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY} + ARGS -E copy $ ${SILKIT_ADAPTERS_VCAN_LIBRARY_DIRECTORY}/libSilKit.so ) diff --git a/SocketCAN/demos/CANoe4SW_SE/run_all.sh b/SocketCAN/demos/CANoe4SW_SE/run_all.sh index 89ae06d..0507407 100755 --- a/SocketCAN/demos/CANoe4SW_SE/run_all.sh +++ b/SocketCAN/demos/CANoe4SW_SE/run_all.sh @@ -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 diff --git a/SocketCAN/demos/EchoDevice/CMakeLists.txt b/SocketCAN/demos/EchoDevice/CMakeLists.txt index 6bfc7e0..4dcfacd 100644 --- a/SocketCAN/demos/EchoDevice/CMakeLists.txt +++ b/SocketCAN/demos/EchoDevice/CMakeLists.txt @@ -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 $<$:${SILKIT_ADAPTERS_VCAN_OUTPUT_DIRECTORY}> ) diff --git a/SocketCAN/demos/shell_scripts/setup_vCAN_start_adapter_send_frames.sh b/SocketCAN/demos/shell_scripts/setup_vCAN_start_adapter_send_frames.sh index 68350f4..db43d23 100755 --- a/SocketCAN/demos/shell_scripts/setup_vCAN_start_adapter_send_frames.sh +++ b/SocketCAN/demos/shell_scripts/setup_vCAN_start_adapter_send_frames.sh @@ -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; @@ -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