diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed4bc77..8437ee2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,11 @@ jobs: - name: Build cpp example run: | just cmake_source_dir=ccp/example cmake_build_dir=cpp/example/build build-cpp + - name: Test cpp as external project + run: | + cd cpp/test/external_project + cmake -GNinja -S . -B build/ + ninja -C build - id: prep name: Prepare deployment run: | diff --git a/cpp/test/external_project/.gitignore b/cpp/test/external_project/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/cpp/test/external_project/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/cpp/test/external_project/CMakeLists.txt b/cpp/test/external_project/CMakeLists.txt new file mode 100644 index 0000000..43b4283 --- /dev/null +++ b/cpp/test/external_project/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (C) 2026 University College London +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.12.0) +cmake_policy(SET CMP0074 NEW) # find_package() uses _ROOT variables + +project(PETSIRDtest VERSION 0.1 LANGUAGES CXX) + +find_program(CCACHE_PROGRAM ccache) +if(CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + message(STATUS "ccache found, so we will use it.") +endif() + +find_package(PETSIRD CONFIG REQUIRED) + +add_executable(minimal_test minimal_test.cpp) +target_link_libraries(minimal_test PETSIRD::petsird) + +add_executable(minimal_test_helpers minimal_test_helpers.cpp) +target_link_libraries(minimal_test_helpers PETSIRD::petsird_helpers) diff --git a/cpp/test/external_project/README.md b/cpp/test/external_project/README.md new file mode 100644 index 0000000..8dadcd2 --- /dev/null +++ b/cpp/test/external_project/README.md @@ -0,0 +1,7 @@ +# Test files for using PETSIRD from C++ with CMake + +This directory contains test files for a minimal test if +CMake can find PETSIRD with `find_package`, and if +The C++ files compile and link. + +There is currently no run-time test. diff --git a/cpp/test/external_project/minimal_test.cpp b/cpp/test/external_project/minimal_test.cpp new file mode 100644 index 0000000..5e5f173 --- /dev/null +++ b/cpp/test/external_project/minimal_test.cpp @@ -0,0 +1,26 @@ +/* + Copyright (C) 2026 University College London + + SPDX-License-Identifier: Apache-2.0 +*/ + +// (un)comment if you want HDF5 or binary output +#define USE_HDF5 + +#ifdef USE_HDF5 +# include "petsird/hdf5/protocols.h" +using petsird::hdf5::PETSIRDReader; +#else +# include "petsird/binary/protocols.h" +using petsird::binary::PETSIRDReader; +#endif + +int +main(int, char const* argv[]) +{ + PETSIRDReader reader(argv[1]); + petsird::Header header; + reader.ReadHeader(header); + + return 0; +} diff --git a/cpp/test/external_project/minimal_test_helpers.cpp b/cpp/test/external_project/minimal_test_helpers.cpp new file mode 100644 index 0000000..b9764dc --- /dev/null +++ b/cpp/test/external_project/minimal_test_helpers.cpp @@ -0,0 +1,29 @@ +/* + Copyright (C) 2026 University College London + + SPDX-License-Identifier: Apache-2.0 +*/ + +// (un)comment if you want HDF5 or binary output +#define USE_HDF5 + +#ifdef USE_HDF5 +# include "petsird/hdf5/protocols.h" +using petsird::hdf5::PETSIRDReader; +#else +# include "petsird/binary/protocols.h" +using petsird::binary::PETSIRDReader; +#endif +#include "petsird_helpers.h" +#include "petsird_helpers/geometry.h" +#include "petsird_helpers/create.h" + +int +main(int, char const* argv[]) +{ + PETSIRDReader reader(argv[1]); + petsird::Header header; + reader.ReadHeader(header); + + return 0; +}