From 414f953d8195b3dc72341d9394211284871a63e5 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Mon, 19 Feb 2024 16:49:18 -0800 Subject: [PATCH] build: Fixes for DCMTK (#4147) It somehow escaped our notice, but not only does DCMTK have an exported config, but also CMake itself has a FindDCMTK.cmake module. So get rid of ours, and prefer the config if available. This is hoped to solve some edge cases for finding and using this library properly. Fixes #4146 (I hope?) Signed-off-by: Larry Gritz --- src/cmake/Config.cmake.in | 3 ++ src/cmake/externalpackages.cmake | 5 ++- src/cmake/modules/FindDCMTK.cmake | 72 ------------------------------- src/dicom.imageio/CMakeLists.txt | 3 +- 4 files changed, 8 insertions(+), 75 deletions(-) delete mode 100644 src/cmake/modules/FindDCMTK.cmake diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 5fd155728f..0ee290b4d4 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -36,6 +36,9 @@ if (NOT @BUILD_SHARED_LIBS@) if (@PNG_FOUND@) find_dependency(PNG) endif() + if (@DCMTK_FOUND@) + find_dependency(DCMTK) + endif() # The following have the same problem except that INTERFACE_LINK_LIBRARIES use # TARGET_NAME_IF_EXISTS, so the error only happens on link time. if (@OIIO_TBB@) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 241456725d..4068330fb2 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -200,7 +200,10 @@ checked_find_package (TBB 2017 SETVARIABLES OIIO_TBB PREFER_CONFIG) -checked_find_package (DCMTK VERSION_MIN 3.6.1) # For DICOM images +# DCMTK is used to read DICOM images +checked_find_package (DCMTK VERSION_MIN 3.6.1 + PREFER_CONFIG) + checked_find_package (FFmpeg VERSION_MIN 3.0) checked_find_package (GIF VERSION_MIN 4 diff --git a/src/cmake/modules/FindDCMTK.cmake b/src/cmake/modules/FindDCMTK.cmake deleted file mode 100644 index 8f9e434066..0000000000 --- a/src/cmake/modules/FindDCMTK.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# Module to find DCMTK -# -# Copyright Contributors to the OpenImageIO project. -# SPDX-License-Identifier: Apache-2.0 -# https://github.com/AcademySoftwareFoundation/OpenImageIO -# -# This module will first look into the directories defined by the variables: -# - DCMTK_ROOT, DCMTK_INCLUDE_PATH, DCMTK_LIBRARY_PATH -# -# This module defines the following variables: -# -# DCMTK_FOUND True if DCMTK was found. -# DCMTK_INCLUDES Where to find DCMTK headers -# DCMTK_LIBRARIES List of libraries to link against when using DCMTK -# DCMTK_VERSION Version of DCMTK (e.g., 3.6.2) -# DCMTK_VERSION_NUMBER Int version of DCMTK (e.g., 362 for 3.6.2) - -include (FindPackageHandleStandardArgs) -include (FindPackageMessage) - -if (NOT DCMTK_FIND_QUIETLY) - if (DCMTK_ROOT) - message(STATUS "DCMTK path explicitly specified: ${DCMTK_ROOT}") - endif() - if (DCMTK_INCLUDE_PATH) - message(STATUS "DCMTK INCLUDE_PATH explicitly specified: ${DCMTK_INCLUDE_PATH}") - endif() - if (DCMTK_LIBRARY_PATH) - message(STATUS "DCMTK LIBRARY_PATH explicitly specified: ${DCMTK_LIBRARY_PATH}") - endif() -endif () - -find_path (DCMTK_INCLUDE_DIR - dcmtk/dcmdata/dcuid.h - HINTS - ${DCMTK_INCLUDE_PATH} ENV DCMTK_INCLUDE_PATH - DOC "The directory where DCMTK headers reside") - -foreach (COMPONENT dcmimage dcmimgle dcmdata oflog ofstd iconv) - find_library (DCMTK_${COMPONENT}_LIB ${COMPONENT} - HINTS - ${DCMTK_LIBRARY_PATH} ENV DCMTK_LIBRARY_PATH - PATH_SUFFIXES lib lib64 - ) - if (DCMTK_${COMPONENT}_LIB) - set (DCMTK_LIBRARIES ${DCMTK_LIBRARIES} ${DCMTK_${COMPONENT}_LIB}) - endif () -endforeach() - -if (DCMTK_INCLUDE_DIR AND EXISTS "${DCMTK_INCLUDE_DIR}/dcmtk/config/osconfig.h") - file(STRINGS "${DCMTK_INCLUDE_DIR}/dcmtk/config/osconfig.h" TMP REGEX "^#define PACKAGE_VERSION[ \t].*$") - string(REGEX MATCHALL "[0-9.]+" DCMTK_VERSION ${TMP}) - file(STRINGS "${DCMTK_INCLUDE_DIR}/dcmtk/config/osconfig.h" TMP REGEX "^#define PACKAGE_VERSION_NUMBER[ \t].*$") - string(REGEX MATCHALL "[0-9.]+" DCMTK_VERSION_NUMBER ${TMP}) -endif () - -include (FindPackageHandleStandardArgs) -find_package_handle_standard_args (DCMTK - REQUIRED_VARS DCMTK_INCLUDE_DIR DCMTK_LIBRARIES - VERSION_VAR DCMTK_VERSION - ) - -if (DCMTK_FOUND) - set(DCMTK_INCLUDES "${DCMTK_INCLUDE_DIR}") -endif() - -mark_as_advanced ( - DCMTK_INCLUDE_DIR - DCMTK_LIBRARIES - DCMTK_VERSION - DCMTK_VERSION_NUMBER - ) diff --git a/src/dicom.imageio/CMakeLists.txt b/src/dicom.imageio/CMakeLists.txt index 6631a4d1bf..e8a2fbbb7a 100644 --- a/src/dicom.imageio/CMakeLists.txt +++ b/src/dicom.imageio/CMakeLists.txt @@ -4,8 +4,7 @@ if (DCMTK_FOUND) add_oiio_plugin (dicominput.cpp - INCLUDE_DIRS ${DCMTK_INCLUDE_DIR} - LINK_LIBRARIES ${DCMTK_LIBRARIES} + LINK_LIBRARIES DCMTK::DCMTK DEFINITIONS "-DUSE_DCMTK=1") else () message (WARNING "DICOM plugin will not be built, no DCMTK")