Skip to content

Commit f582758

Browse files
Merge pull request #161 from KrisThielemans/cpp_generated_location
move location of C++ generated files to generated/petsird and better CMake - Moving the generated C++ files, together with an adaptation of our CMakeLists.txt - Create petsird and petsird_helpers (interface) libraries that keep track of include paths and dependencies This means that we use #include "petsird/types.h" as opposed to #include "generated/petsird.h" WARNING: breaks backward compatibility!
2 parents 76d1a91 + 648bd00 commit f582758

File tree

9 files changed

+42
-17
lines changed

9 files changed

+42
-17
lines changed

cpp/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,14 @@ if(CCACHE_PROGRAM)
1515
message(STATUS "ccache found, so we will use it.")
1616
endif()
1717

18-
add_subdirectory(generated)
18+
# assume that yardl was run with the following in the _package.yml
19+
# sourcesOutputDir: ../cpp/generated/petsird
20+
21+
add_subdirectory(generated/petsird)
22+
# create a petsird library target
23+
# Currently it is just empty, but allows creating target properties which are transitive
24+
add_library(petsird)
25+
target_link_libraries(petsird PUBLIC petsird_generated)
26+
target_include_directories(petsird PUBLIC "${PROJECT_SOURCE_DIR}/generated")
27+
1928
add_subdirectory(helpers)

cpp/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ The C++ code shows writing to and reading from an HDF5 file
1717
2. Run the generator: `./petsird_generator test.h5`
1818
3. Run the analyzer: `./petsird_analysis test.h5`
1919
4. You can inspect the HDF5 file by running `h5dump test.h5`
20+
21+
## Using this is a library
22+
23+
Currently, we do not install files yet. You therefore need to do something
24+
like
25+
```cmake
26+
set(PETSIRD_dir ../PETSIRD/cpp/) # or wherever
27+
add_subdirectory(${PETSIRD_dir} PETSIRD)
28+
29+
# only uses petsird
30+
add_executable(your_executable PUBLIC STIR_PETSIRD_convertor.cpp petsird)
31+
32+
# also uses helpers
33+
add_library(your_lib PUBLIC petsird_helpers)
34+
```

cpp/helpers/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
find_package(xtensor-blas REQUIRED)
2+
3+
# create a petsird_helpers library target
4+
# Currently it is just empty, but allows creating target properties which are transitive
5+
add_library(petsird_helpers INTERFACE)
6+
target_link_libraries(petsird_helpers INTERFACE petsird xtensor-blas)
7+
target_include_directories(petsird_helpers INTERFACE "${PROJECT_SOURCE_DIR}/helpers/include")
18

29
add_executable(petsird_generator petsird_generator.cpp)
3-
target_link_libraries(petsird_generator petsird_generated)
4-
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
5-
# needed for generated PETSIRD files
6-
target_include_directories(petsird_generator PRIVATE "${PROJECT_SOURCE_DIR}/")
10+
target_link_libraries(petsird_generator petsird_helpers)
711

812
add_executable(petsird_analysis petsird_analysis.cpp)
9-
target_link_libraries(petsird_analysis petsird_generated)
10-
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/helpers/include")
11-
# needed for generated PETSIRD files
12-
target_include_directories(petsird_analysis PRIVATE "${PROJECT_SOURCE_DIR}/")
13+
target_link_libraries(petsird_analysis petsird_helpers)

cpp/helpers/include/petsird_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef __petsird_helpers_h__
77
#define __petsird_helpers_h__
88

9-
#include "generated/types.h"
9+
#include "petsird/types.h"
1010
#include <array>
1111

1212
namespace petsird_helpers

cpp/helpers/include/petsird_helpers/create.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef __petsird_helpers_create_h__
88
#define __petsird_helpers_create_h__
99

10-
#include "generated/types.h"
10+
#include "petsird/types.h"
1111
#include <array>
1212

1313
namespace petsird_helpers

cpp/helpers/include/petsird_helpers/geometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <xtensor/xio.hpp>
1212
#include <xtensor-blas/xlinalg.hpp>
1313
#include <vector>
14-
#include "generated/types.h"
14+
#include "petsird/types.h"
1515
#include "petsird_helpers.h"
1616

1717
namespace petsird_helpers

cpp/helpers/petsird_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#define USE_HDF5
1010

1111
#ifdef USE_HDF5
12-
# include "generated/hdf5/protocols.h"
12+
# include "petsird/hdf5/protocols.h"
1313
using petsird::hdf5::PETSIRDReader;
1414
#else
15-
# include "generated/binary/protocols.h"
15+
# include "petsird/binary/protocols.h"
1616
using petsird::binary::PETSIRDReader;
1717
#endif
1818
#include "petsird_helpers.h"

cpp/helpers/petsird_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#define USE_HDF5
1515

1616
#ifdef USE_HDF5
17-
# include "generated/hdf5/protocols.h"
17+
# include "petsird/hdf5/protocols.h"
1818
using petsird::hdf5::PETSIRDWriter;
1919
#else
20-
# include "generated/binary/protocols.h"
20+
# include "petsird/binary/protocols.h"
2121
using petsird::binary::PETSIRDWriter;
2222
#endif
2323

model/_package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace: PETSIRD
22

33
cpp:
4-
sourcesOutputDir: ../cpp/generated
4+
sourcesOutputDir: ../cpp/generated/petsird
55

66
python:
77
outputDir: ../python

0 commit comments

Comments
 (0)