InsightSoftwareConsortium / InsightSoftwareConsortium/ITK
conflict with exported CMake target for HDF5 with ITK_USE_SYSTEM_HDF5=OFF
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 748
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 64
Description
### Description
When using `ITK_USE_SYSTEM_HDF5=OFF`, ITK exports `hdf5_cpp-shared` and `hdf5-shared` (or the non-shared) targets but this is incorrect for 2 reasons:
- they point to the ITK HDF5 libraries which are not compatible with not normal HDF5 libraries
- they cause conflicts when using `find_package(HDF5)` after `find_package(ITK)`
In my opinion, those targets should be renamed to `itkhdf*`.
### Steps to Reproduce
The following `CMakeLists.txt` illustrates both problems
```cmake
make_minimum_required(VERSION 3.9.0)
PROJECT(TEST)
include(CMakePrintHelpers)
find_package(ITK)
cmake_print_properties(
TARGETS hdf5_cpp-shared hdf5-shared
PROPERTIES IMPORTED_LOCATION_RELEASE IMPORTED_LOCATION_RELWITHDEBINFO IMPORTED_LOCATION_DEBUG
IMPORTED_LOCATION
)
find_package(HDF5 COMPONENTS C REQUIRED)
```
### Expected behavior
This should just find an "external" HDF5
### Actual behavior
After building/installing ITK `master` and HDF5 1.13.1, CMake outputs
```
Properties for TARGET hdf5_cpp-shared:
hdf5_cpp-shared.IMPORTED_LOCATION_RELEASE =
hdf5_cpp-shared.IMPORTED_LOCATION_RELWITHDEBINFO = "C:/Users/krisf/INSTALL/bin/itkhdf5_cpp-shared-5.2.dll"
hdf5_cpp-shared.IMPORTED_LOCATION_DEBUG =
hdf5_cpp-shared.IMPORTED_LOCATION =
Properties for TARGET hdf5-shared:
hdf5-shared.IMPORTED_LOCATION_RELEASE =
hdf5-shared.IMPORTED_LOCATION_RELWITHDEBINFO = "C:/Users/krisf/Documents/INSTALL/bin/itkhdf5-shared-5.2.dll"
hdf5-shared.IMPORTED_LOCATION_DEBUG =
hdf5-shared.IMPORTED_LOCATION =
CMake Error at C:/Users/krisf/Documents/INSTALL/cmake/hdf5-targets.cmake:37 (message):
Some (but not all) targets in this export set were already defined.
Targets Defined: hdf5-shared;hdf5_cpp-shared
Targets not yet defined:
hdf5-static;mirror_server;mirror_server_stop;hdf5_cpp-static
```
### Reproducibility
all the time.
### Versions
Tested with ITK 5.2.1 and current `master`
### Environment
Tested on Windows 10 with VC 2019, CMake 3.22.3, but this will happen everywhere.
Contributor guide
Assessment
This issue has not been assessed yet.