diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0617f3ce..22a230b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,9 @@ jobs: - name: Install run: cmake --install build + - name: Check installation with a downstream project + run: test/consumer/check-install.sh build + sanitizers: if: github.repository == 'FairRootGroup/FairMQ' name: ${{ matrix.sanitizer.name }} diff --git a/test/consumer/CMakeLists.txt b/test/consumer/CMakeLists.txt new file mode 100644 index 00000000..67038d93 --- /dev/null +++ b/test/consumer/CMakeLists.txt @@ -0,0 +1,33 @@ +################################################################################ +# Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# # +# This software is distributed under the terms of the # +# GNU Lesser General Public Licence (LGPL) version 3, # +# copied verbatim in the file "LICENSE" # +################################################################################ + +# Minimal downstream project. It checks that an installed FairMQ can be found +# and used the way the README describes. Run it via check-install.sh. + +cmake_minimum_required(VERSION 3.15...3.30 FATAL_ERROR) +project(FairMQConsumer LANGUAGES CXX) + +find_package(FairCMakeModules REQUIRED) +include(FairFindPackage2) +find_package2(PUBLIC FairMQ REQUIRED) +find_package2_implicit_dependencies() + +# Variables documented in the README +foreach(var IN ITEMS FairMQ_VERSION FairMQ_PREFIX FairMQ_PACKAGE_DEPENDENCIES + FairMQ_PACKAGE_COMPONENTS) + if("${${var}}" STREQUAL "") + message(FATAL_ERROR "${var} is not set by find_package(FairMQ)") + endif() +endforeach() +if(NOT FairMQ_fairmq_FOUND STREQUAL "TRUE") + message(FATAL_ERROR "FairMQ_fairmq_FOUND is not set") +endif() +message(STATUS "FairMQ_PACKAGE_COMPONENTS: ${FairMQ_PACKAGE_COMPONENTS}") + +add_executable(consumer main.cxx) +target_link_libraries(consumer PRIVATE FairMQ::FairMQ) diff --git a/test/consumer/check-install.sh b/test/consumer/check-install.sh new file mode 100755 index 00000000..0c1bea5e --- /dev/null +++ b/test/consumer/check-install.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +################################################################################ +# Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # +# # +# This software is distributed under the terms of the # +# GNU Lesser General Public Licence (LGPL) version 3, # +# copied verbatim in the file "LICENSE" # +################################################################################ + +# Checks an installed FairMQ: +# 1. install to a temporary prefix that differs from CMAKE_INSTALL_PREFIX +# 2. check that no installed file refers to the configure-time prefix +# (scripts must be configured for the prefix given at install time) +# 3. move the installation to a second prefix and build and run a small +# downstream project against it (the CMake package must be relocatable) +# +# Usage: check-install.sh [extra cmake configure args...] +# +# Dependencies of FairMQ (FairLogger, FairCMakeModules, ...) must be found via +# CMAKE_PREFIX_PATH (environment or extra cmake args). + +set -euo pipefail + +if [ $# -lt 1 ]; then + echo "Usage: $0 [extra cmake configure args...]" >&2 + exit 2 +fi + +here=$(cd "$(dirname "$0")" && pwd) +build=$(cd "$1" && pwd) +shift + +work=$(mktemp -d) +trap 'rm -rf "$work"' EXIT +first="$work/prefix-one" +second="$work/prefix-two" + +echo "--- install to $first" +cmake --install "$build" --prefix "$first" > "$work/install.log" + +echo "--- check for references to the configure-time prefix" +configured=$(sed -n 's/^CMAKE_INSTALL_PREFIX:PATH=//p' "$build/CMakeCache.txt") +if [ -n "$configured" ] && [ "$configured" != "$first" ] && grep -rIl -F "$configured/" "$first"; then + echo "ERROR: installed files above refer to the configure-time prefix $configured" >&2 + exit 1 +fi + +echo "--- relocate to $second" +mv "$first" "$second" + +echo "--- build downstream project" +cmake -S "$here" -B "$work/consumer" -DCMAKE_PREFIX_PATH="$second${CMAKE_PREFIX_PATH:+;$CMAKE_PREFIX_PATH}" "$@" +cmake --build "$work/consumer" +LD_LIBRARY_PATH="$second/lib:$second/lib64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" "$work/consumer/consumer" +echo "OK" diff --git a/test/consumer/main.cxx b/test/consumer/main.cxx new file mode 100644 index 00000000..a521b6bd --- /dev/null +++ b/test/consumer/main.cxx @@ -0,0 +1,19 @@ +/******************************************************************************** + * Copyright (C) 2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include +#include + +#include + +int main() +{ + fair::mq::Device device; + std::cout << "FairMQ " << FAIRMQ_VERSION << " consumer ok\n"; + return 0; +}