Fix OpenJPEG target handling in DCMTKConfig.cmake#145
Fix OpenJPEG target handling in DCMTKConfig.cmake#145lassoan wants to merge 1 commit intoDCMTK:masterfrom
Conversation
|
@eichelberg This is probably something for you. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a CMake package-consumption issue when DCMTK is built with OpenJPEG support: importing DCMTKTargets.cmake can fail if the consuming project hasn’t already created the openjp2 imported target.
Changes:
- Add a guarded
find_package(OpenJPEG ...)call inDCMTKConfig.cmakegeneration soopenjp2is defined before importing DCMTK targets. - Only perform the OpenJPEG lookup when DCMTK was built with OpenJPEG and the
openjp2target does not already exist.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS}) | ||
|
|
||
| if(DCMTK_WITH_OPENJPEG AND NOT TARGET openjp2) | ||
| find_package(OpenJPEG CONFIG QUIET) |
There was a problem hiding this comment.
find_package(OpenJPEG CONFIG QUIET) suppresses why OpenJPEG wasn’t found; if this call fails, include(DCMTKTargets.cmake) will still error later due to a missing openjp2 target, but with a less actionable message. Consider using REQUIRED or checking the result and emitting a clearer FATAL_ERROR that suggests setting OpenJPEG_DIR when DCMTK was built with OpenJPEG support.
| find_package(OpenJPEG CONFIG QUIET) | |
| find_package(OpenJPEG CONFIG QUIET) | |
| if(NOT TARGET openjp2) | |
| message(FATAL_ERROR | |
| "DCMTK was built with OpenJPEG support, but the OpenJPEG package " | |
| "configuration could not be found. Please make OpenJPEG available to " | |
| "CMake, for example by setting OpenJPEG_DIR to the directory " | |
| "containing OpenJPEGConfig.cmake or by adjusting CMAKE_PREFIX_PATH.") | |
| endif() |
When DCMTK is built with OpenJPEG support, DCMTKTargets.cmake contains INTERFACE_LINK_LIBRARIES entries that reference the imported target openjp2. If a consuming project includes DCMTKConfig.cmake without previously finding OpenJPEG, CMake errors out because the openjp2 target does not exist. Use CMakeFindDependencyMacro to conditionally call find_dependency(OpenJPEG) when DCMTK_WITH_OPENJPEG is enabled. This guarantees that the openjp2 target is defined before DCMTKTargets.cmake is processed, while avoiding redundant lookups in projects that have already found OpenJPEG themselves.
7f051c5 to
6b73475
Compare
|
@eichelberg please have a look. Without this, downstream projects need to add find_package calls depending on what DCMTK modules are enabled. Note that the same problem is fixed for OpenSSL and zlib packages here: #67 |
When DCMTK is built with OpenJPEG support, DCMTKTargets.cmake contains
INTERFACE_LINK_LIBRARIES entries that reference the imported target
openjp2. If a consuming project includes DCMTKConfig.cmake without
previously finding OpenJPEG, CMake errors out because the openjp2
target does not exist.
Use CMakeFindDependencyMacro to conditionally call find_dependency(OpenJPEG)
when DCMTK_WITH_OPENJPEG is enabled. This guarantees that the openjp2
target is defined before DCMTKTargets.cmake is processed,
while avoiding redundant lookups in projects that have already found
OpenJPEG themselves.