Fix CMake export and include interfaces#181
Fix CMake export and include interfaces#181NikEfth wants to merge 34 commits intoETSInitiative:mainfrom
Conversation
- Add install/export rules for PETSIRD targets - Provide PETSIRDConfig.cmake and version file - Fix include directories using BUILD/INSTALL interfaces - Export PETSIRD::petsird target for find_package() - Prepare PETSIRD for external consumers (STIR -- this has been going on for a while )
for more information, see https://pre-commit.ci
|
Finally, this took me 2 week of bouncing around and many problems in STIR: Very brief summary. This PR fixes PETSIRD integration issues by properly exporting PETSIRD as a CMake package instead of relying on in-tree submodule builds. Specifically, it: ⸻ Background / Motivation PETSIRD was previously consumed via a submodule and built inside STIR, which caused: These issues became visible once CI enabled stricter sanitizers and newer compilers. Exporting PETSIRD as a proper CMake package ensures a single canonical definition of all PETSIRD/STIR types across the entire build. |
|
Further to the previous posts, While PETSIRD built correctly on my PC, it failed when used as an external dependency in CI. Several independent problems linked.
Fixes:
|
KrisThielemans
left a comment
There was a problem hiding this comment.
I think the export is a good idea. It'll also make it easier for putting on conda etc. However, I think it'd be best to export 2 targets: PETSIRD::generated and PETSIRD::helpers.
Potentially, we should INSTALL the examples.
And I guess we need a simple CI test for this as well. sorry.
| foreach(t petsird petsird_generated petsird_helpers) | ||
| if(TARGET ${t}) | ||
| get_target_property(_libs ${t} INTERFACE_LINK_LIBRARIES) | ||
| if(_libs) | ||
| list(FILTER _libs EXCLUDE REGEX "xtensor") | ||
| set_target_properties(${t} | ||
| PROPERTIES INTERFACE_LINK_LIBRARIES "${_libs}") | ||
| endif() | ||
| endif() | ||
| endforeach() |
There was a problem hiding this comment.
why did you need this? (probably because you removed target_link_libraries)
There was a problem hiding this comment.
To undo an overly-aggressive dependency propagation introduced by generated / helper targets.
xtensor is header-only
However… Some targets propagate xtensor via INTERFACE_LINK_LIBRARIES
Something like:
INTERFACE_LINK_LIBRARIES xtensor::xtensor
This becomes a real problem in STIR / STIR2PETSIRD. Header-only deps should not force downstream linking.
There was a problem hiding this comment.
As long as xtensor is header-only, we could use the same trick as https://github.com/UCL/STIR/blob/ec3a5670f9b63cb10f4bebce6edf22d6f028a6fb/src/buildblock/CMakeLists.txt#L125-L137, i.e. only add the include path.
However, this is all quite ugly. I'd rather avoid it as much as possible.
As long as we have find_dependency(xtensor) in the Config.cmake, there should be no problem
There was a problem hiding this comment.
Can you please try without it and document any problems?
NikEfth
left a comment
There was a problem hiding this comment.
I will try step-by-step to bring lxtensor-blas back and see when linking becomes an issue.
| foreach(t petsird petsird_generated petsird_helpers) | ||
| if(TARGET ${t}) | ||
| get_target_property(_libs ${t} INTERFACE_LINK_LIBRARIES) | ||
| if(_libs) | ||
| list(FILTER _libs EXCLUDE REGEX "xtensor") | ||
| set_target_properties(${t} | ||
| PROPERTIES INTERFACE_LINK_LIBRARIES "${_libs}") | ||
| endif() | ||
| endif() | ||
| endforeach() |
There was a problem hiding this comment.
To undo an overly-aggressive dependency propagation introduced by generated / helper targets.
xtensor is header-only
However… Some targets propagate xtensor via INTERFACE_LINK_LIBRARIES
Something like:
INTERFACE_LINK_LIBRARIES xtensor::xtensor
This becomes a real problem in STIR / STIR2PETSIRD. Header-only deps should not force downstream linking.
|
@KrisThielemans I am about to finish the CI yml and I think I have to apologize but my yml skill are not as good as yours (or @casperdcl ) and I make just as typing commands in the terminal :) I could not modify yours successfully, running to all sort of issues. Have a look at mine and let me know if I can improve. |
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
|
I am sorry I cannot reply inline. I commented out the lines above and when compiling STIR I get: |
|
In addition, what else did you change? |
|
hmmm. I just went back to |
|
CI fails due to xtensor now using |
This is quite disappointing. My feeling it's an xtensor CMake problem, as it shouldn't add that for a header-only library (@naegelejd @johnstairs @casperdcl what do you think?), but unlikely we will be able to get that fixed soon. Maybe we need to keep these lines in for now, but add a documentation line why |
But helpers have sources, no? |
…hich causes the CMake export to fail due to C++ 20
The helpers library is include only, which is why I expect that it should be an |
|
I really don't want to restrict to old xtensor, sorry. Did using C++-20 not solve this? |
|
But types.cc is not a header |
|
add_library(petsird_generated OBJECT
protocols.cc
types.cc
ndjson/protocols.cc
binary/protocols.cc
hdf5/protocols.cc
)i.e. it's on OBJECT library. PETSIRD itself shouldn't need to care about this (and this isn't related to any of the compilation errors that you flagged). BTW, https://cmake.org/cmake/help/git-stage/manual/cmake-buildsystem.7.html#interface-libraries has some examples, but as usual they're not incredibly helpful. |
set(CMAKE_CXX_STANDARD 20) This didn't |
|
OK. You cannot have it all. I'm sorry set(CMAKE_CXX_STANDARD 20) breaks yardl. |
|
should have been fixed. microsoft/yardl#245 and microsoft/yardl#270. @naegelejd and @johnstairs Can you please release a new yardl version asap? |
|
Besides the cxx20, this is done from myside. STIR links happily. |
|
Yes, I will release the next version of Yardl with this fix. Before doing that, however, have you had a chance to test this issue here using the main branch of Yardl? That would be a good idea before we release the next version. |
|
@NikEfth not sure if building yardl is an easy one fo ryou. still on Macos? |
|
If you give me ~24 hours I can try it myself and report back. If it works I'll release Yardl 0.6.7 ASAP. |
|
UPDATE: This is fine now.I updated everything as discussed above and when building STIR I have the problem: |
|
This is the last problem with compiling STIR (linked to PETSIRD). I am too tired to figure this out: |
|
Hi @NikEfth, I'm afraid I cannot follow anymore.
In any case, this is for tomorrow. |
|
Changes in this pull request
When PETSIRD is used as a subproject and exported by a parent project, CMake
requires that exported targets do not reference source-tree paths and that all
public dependencies are also exported.
This PR fixes those issues while keeping standalone PETSIRD builds unchanged.
Related issues
Checklist before requesting a review
Please tick the following: