Skip to content

Commit

Permalink
Improved CMake install and CPack behavior (#12)
Browse files Browse the repository at this point in the history
- tcp_pubsub now properly installs dll/so files when BUILD_SHARED_LIBS is ON
- tcp_pubsub can now be packed with CPack
- Added CMake option to disable building the sample Projects
- Added integration_test project that can be build against an install to perform a very simple automated link and runtime test
- Created GH Actions that properly compile and package binaries for windows and Linux
  • Loading branch information
FlorianReimold authored Sep 12, 2022
1 parent 5b47272 commit c164c9b
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 42 deletions.
68 changes: 65 additions & 3 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,88 @@ env:

jobs:
build-ubuntu:

strategy:
matrix:
library_type: [static, shared]
os: [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04]

# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:

- name: Set Variables
run: |
if [[ '${{ matrix.library_type }}' == 'static' ]]; then
echo "build_shared_libs=OFF" >> "$GITHUB_ENV"
echo "package_postfix=static" >> "$GITHUB_ENV"
else
echo "build_shared_libs=ON" >> "$GITHUB_ENV"
echo "package_postfix=shared" >> "$GITHUB_ENV"
fi
- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'true'
fetch-depth: 0


############################################
# Test-compile the project
############################################

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/_build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: |
cmake -B ${{github.workspace}}/_build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DBUILD_SHARED_LIBS=${{ env.build_shared_libs }}
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/_build --config ${{env.BUILD_TYPE}}

- name: CPack
run: cpack -G DEB
working-directory: ${{ github.workspace }}/_build

- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: tcp-pubsub-${{ matrix.os }}-${{ env.package_postfix }}
path: ${{github.workspace}}/_build/_package/*.deb


############################################
# Test if our binary can be linked against
############################################

- name: Install binaries
shell: bash
run: sudo dpkg -i ${{ github.workspace }}/_build/_package/*.deb

- name: Compile integration test (Release)
run: |
cmake -B ${{github.workspace}}/samples/integration_test/_build/release -DCMAKE_BUILD_TYPE=Release
cmake --build ${{github.workspace}}/samples/integration_test/_build/release
working-directory: ${{ github.workspace }}/samples/integration_test

- name: Run integration test (Release)
run: ./integration_test
working-directory: ${{ github.workspace }}/samples/integration_test/_build/release

- name: Compile integration test (Debug)
run: |
cmake -B ${{github.workspace}}/samples/integration_test/_build/debug -DCMAKE_BUILD_TYPE=Debug
cmake --build ${{github.workspace}}/samples/integration_test/_build/debug
working-directory: ${{ github.workspace }}/samples/integration_test

- name: Run integration test (Debug)
run: ./integration_test
working-directory: ${{ github.workspace }}/samples/integration_test/_build/debug


92 changes: 87 additions & 5 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,112 @@ on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
INSTALL_PREFIX: _install

jobs:
build-windows:
strategy:
matrix:
library_type: [static, shared]

# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: windows-latest
runs-on: windows-2019

steps:

- name: Set Variables
run: |
if ( '${{ matrix.library_type }}' -eq 'static' )
{
echo "build_shared_libs=OFF" >> "$Env:GITHUB_ENV"
echo "package_postfix=static" >> "$Env:GITHUB_ENV"
}
else
{
echo "build_shared_libs=ON" >> "$Env:GITHUB_ENV"
echo "package_postfix=shared" >> "$Env:GITHUB_ENV"
}
- name: Checkout
uses: actions/checkout@v2
with:
submodules: 'true'
fetch-depth: 0

############################################
# Test-compile the project
############################################

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/_build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
shell: cmd
run: |
cmake -B ${{github.workspace}}/_build ^
-G "Visual Studio 16 2019" ^
-A x64 ^
-T v140 ^
-DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} ^
-DBUILD_SHARED_LIBS=${{ env.build_shared_libs }}
- name: Build
- name: Build (Release)
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/_build --config ${{env.BUILD_TYPE}}
shell: cmd
run: |
cmake --build ${{github.workspace}}/_build --config Release --parallel
cmake --build ${{github.workspace}}/_build --config Release --target INSTALL
- name: Build (Debug)
# Build your program with the given configuration
shell: cmd
run: |
cmake --build ${{github.workspace}}/_build --config Debug --parallel
cmake --build ${{github.workspace}}/_build --config Debug --target INSTALL
- name: Upload binaries
uses: actions/upload-artifact@v2
with:
name: tcp-pubsub-win64-${{ matrix.library_type }}
path: ${{github.workspace}}/${{env.INSTALL_PREFIX}}

############################################
# Test if our binary can be linked against
############################################

- name: CMake integration test
shell: cmd
run: |
cmake -B ${{github.workspace}}/samples/integration_test/_build ^
-A x64 ^
-DCMAKE_PREFIX_PATH=${{github.workspace}}/${{env.INSTALL_PREFIX}}
working-directory: ${{ github.workspace }}/samples/integration_test

- name: Compile integration test (Release)
shell: cmd
run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Release
working-directory: ${{ github.workspace }}/samples/integration_test

- name: Run integration test (Release)
run: |
if ( '${{ matrix.library_type }}' -eq 'shared' )
{
$Env:Path = '${{github.workspace}}/${{env.INSTALL_PREFIX}}/bin;' + $Env:Path
}
.\integration_test.exe
working-directory: ${{ github.workspace }}/samples/integration_test/_build/Release

- name: Compile integration test (Debug)
shell: cmd
run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Debug
working-directory: ${{ github.workspace }}/samples/integration_test

- name: Run integration test (Debug)
run: |
if ( '${{ matrix.library_type }}' -eq 'shared' )
{
$Env:Path = '${{github.workspace}}/${{env.INSTALL_PREFIX}}/bin;' + $Env:Path
}
.\integration_test.exe
working-directory: ${{ github.workspace }}/samples/integration_test/_build/Debug
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ CMakeLists.txt.user

#Build dir
/_build

/samples/integration_test/_build
42 changes: 35 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
cmake_minimum_required(VERSION 3.5.1)

# Project call
include("${CMAKE_CURRENT_LIST_DIR}/tcp_pubsub/version.cmake")
project(tcp_pubsub VERSION ${TCP_PUBSUB_VERSION_MAJOR}.${TCP_PUBSUB_VERSION_MINOR}.${TCP_PUBSUB_VERSION_PATCH})

# Normalize backslashes from Windows paths
file(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
message(STATUS "Module Path: ${CMAKE_MODULE_PATH}")
message(STATUS "Prefix Path: ${CMAKE_PREFIX_PATH}")

# CMake Options
option(TCP_PUBSUB_BUILD_SAMPLES
"Build project samples"
ON)

option(TCP_PUBSUB_BUILD_ECAL_SAMPLES
"Build eCAL-based project samples. Requires eCAL to be findable by CMake."
OFF)

# Module path for finding asio
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/modules)

project(tcp_pubsub)
# Set Debug postfix
set(CMAKE_DEBUG_POSTFIX d)
set(CMAKE_MINSIZEREL_POSTFIX minsize)
set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg)

# Add main tcp_pubsub library
add_subdirectory(tcp_pubsub)

# Recycle dependency. It's header only and not in the API, so we add it with EXCLUDE_FOR_ALL, so it won't be installed
add_subdirectory(thirdparty/recycle EXCLUDE_FROM_ALL)

add_subdirectory(samples/performance_publisher)
add_subdirectory(samples/performance_subscriber)
add_subdirectory(samples/hello_world_publisher)
add_subdirectory(samples/hello_world_subscriber)
# Generic samples
if (TCP_PUBSUB_BUILD_SAMPLES)
add_subdirectory(samples/performance_publisher)
add_subdirectory(samples/performance_subscriber)
add_subdirectory(samples/hello_world_publisher)
add_subdirectory(samples/hello_world_subscriber)
endif()

# Specific eCAL Samples that tunnel an eCAL Topic through TCP
if(TCP_PUBSUB_BUILD_ECAL_SAMPLES)
add_subdirectory(samples/ecal_to_tcp)
add_subdirectory(samples/tcp_to_ecal)
endif()

# add_subdirectory(samples/ecal_to_tcp)
# add_subdirectory(samples/tcp_to_ecal)
# Make this package available for packing with CPack
include("${CMAKE_CURRENT_LIST_DIR}/cpack_config.cmake")
20 changes: 20 additions & 0 deletions cpack_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A low-level publish-subscribe library operating on TCP/IP")
set(CPACK_PACKAGE_VENDOR "Eclipse eCAL")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_package")

set(CPACK_PACKAGE_CONTACT "florian.reimold@continental-corporation.com")

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Florian Reimold <florian.reimold@continental-corporation.com>")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/eclipse-ecal/tcp_pubsub")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/README.md")

include(CPack)
2 changes: 2 additions & 0 deletions samples/ecal_to_tcp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(tcp_pubsub REQUIRED)
find_package(eCAL REQUIRED)
find_package(Threads REQUIRED)

set(sources
src/main.cpp
Expand All @@ -20,4 +21,5 @@ add_executable (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME}
tcp_pubsub::tcp_pubsub
eCAL::core
Threads::Threads
)
20 changes: 20 additions & 0 deletions samples/integration_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.5.1)

project(integration_test)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(tcp_pubsub REQUIRED)

set(sources
src/main.cpp
)

add_executable (${PROJECT_NAME}
${sources}
)

target_link_libraries (${PROJECT_NAME}
tcp_pubsub::tcp_pubsub
)
19 changes: 19 additions & 0 deletions samples/integration_test/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Continental. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

#include <iostream>
#include <thread>

#include <tcp_pubsub/publisher.h>

int main()
{
{
std::shared_ptr<tcp_pubsub::Executor> executor = std::make_shared<tcp_pubsub::Executor>(6);
tcp_pubsub::Publisher hello_world_publisher(executor, 1588);
}

std::this_thread::sleep_for(std::chrono::milliseconds(10));

return 0;
}
2 changes: 2 additions & 0 deletions samples/performance_publisher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(tcp_pubsub REQUIRED)
find_package(Threads REQUIRED)

set(sources
src/main.cpp
Expand All @@ -17,4 +18,5 @@ add_executable (${PROJECT_NAME}

target_link_libraries (${PROJECT_NAME}
tcp_pubsub::tcp_pubsub
Threads::Threads
)
2 changes: 2 additions & 0 deletions samples/performance_subscriber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(tcp_pubsub REQUIRED)
find_package(Threads REQUIRED)

set(sources
src/main.cpp
Expand All @@ -17,4 +18,5 @@ add_executable (${PROJECT_NAME}

target_link_libraries (${PROJECT_NAME}
tcp_pubsub::tcp_pubsub
Threads::Threads
)
2 changes: 2 additions & 0 deletions samples/tcp_to_ecal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(tcp_pubsub REQUIRED)
find_package(eCAL REQUIRED)
find_package(Threads REQUIRED)

set(sources
src/main.cpp
Expand All @@ -20,4 +21,5 @@ add_executable (${PROJECT_NAME}
target_link_libraries (${PROJECT_NAME}
tcp_pubsub::tcp_pubsub
eCAL::core
Threads::Threads
)
Loading

0 comments on commit c164c9b

Please sign in to comment.