Skip to content

Commit cfdfa12

Browse files
add test if external C++ project can use PETSIRD
1 parent ddbcf12 commit cfdfa12

6 files changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
- name: Build cpp example
6565
run: |
6666
just cmake_source_dir=ccp/example cmake_build_dir=cpp/example/build build-cpp
67+
- name: Test cpp as external project
68+
run: |
69+
cd test/external_project
70+
cmake -GNinja -S . -B build/
71+
ninja -C build
6772
- id: prep
6873
name: Prepare deployment
6974
run: |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2026 University College London
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.12.0)
5+
cmake_policy(SET CMP0074 NEW) # find_package() uses <PackageName>_ROOT variables
6+
7+
project(PETSIRDtest VERSION 0.1 LANGUAGES CXX)
8+
9+
find_program(CCACHE_PROGRAM ccache)
10+
if(CCACHE_PROGRAM)
11+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
12+
message(STATUS "ccache found, so we will use it.")
13+
endif()
14+
15+
find_package(PETSIRD CONFIG REQUIRED)
16+
17+
add_executable(minimal_test minimal_test.cpp)
18+
target_link_libraries(minimal_test PETSIRD::petsird)
19+
20+
add_executable(minimal_test_helpers minimal_test_helpers.cpp)
21+
target_link_libraries(minimal_test_helpers PETSIRD::petsird_helpers)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Test files for using PETSIRD from C++ with CMake
2+
3+
This directory contains test files for a minimal test if
4+
CMake can find PETSIRD with `find_package`, and if
5+
The C++ files compile and link.
6+
7+
There is currently no run-time test.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright (C) 2026 University College London
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// (un)comment if you want HDF5 or binary output
8+
#define USE_HDF5
9+
10+
#ifdef USE_HDF5
11+
# include "petsird/hdf5/protocols.h"
12+
using petsird::hdf5::PETSIRDReader;
13+
#else
14+
# include "petsird/binary/protocols.h"
15+
using petsird::binary::PETSIRDReader;
16+
#endif
17+
18+
int
19+
main(int, char const* argv[])
20+
{
21+
PETSIRDReader reader(argv[1]);
22+
petsird::Header header;
23+
reader.ReadHeader(header);
24+
25+
return 0;
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright (C) 2026 University College London
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// (un)comment if you want HDF5 or binary output
8+
#define USE_HDF5
9+
10+
#ifdef USE_HDF5
11+
# include "petsird/hdf5/protocols.h"
12+
using petsird::hdf5::PETSIRDReader;
13+
#else
14+
# include "petsird/binary/protocols.h"
15+
using petsird::binary::PETSIRDReader;
16+
#endif
17+
#include "petsird_helpers.h"
18+
#include "petsird_helpers/geometry.h"
19+
#include "petsird_helpers/create.h"
20+
21+
int
22+
main(int, char const* argv[])
23+
{
24+
PETSIRDReader reader(argv[1]);
25+
petsird::Header header;
26+
reader.ReadHeader(header);
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)