Skip to content

Commit

Permalink
[dcmtk] Revise, fix, test (#41565)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt authored Oct 23, 2024
1 parent 31554ea commit 61a6ef5
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 91 deletions.
55 changes: 55 additions & 0 deletions ports/dcmtk/dependencies.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/CMake/3rdparty.cmake b/CMake/3rdparty.cmake
index c355922..33ddc73 100644
--- a/CMake/3rdparty.cmake
+++ b/CMake/3rdparty.cmake
@@ -1,3 +1,11 @@
+set(CMAKE_REQUIRE_FIND_PACKAGE_Iconv "${DCMTK_WITH_ICONV}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_ICU "${DCMTK_WITH_ICU}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_LibXml2 "${DCMTK_WITH_XML}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_OpenSSL "${DCMTK_WITH_OPENSSL}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_PNG "${DCMTK_WITH_PNG}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_TIFF "${DCMTK_WITH_TIFF}")
+set(CMAKE_REQUIRE_FIND_PACKAGE_ZLIB "${DCMTK_WITH_ZLIB}")
+
set(USE_FIND_PACKAGE_DOCS "Control whether libraries are searched via CMake's find_package() mechanism or a Windows specific fallback")
# Advanced user (eg. vcpkg) may want to override this:
if(NOT DEFINED DCMTK_USE_FIND_PACKAGE_WIN_DEFAULT)
@@ -42,7 +50,7 @@ if(DCMTK_USE_FIND_PACKAGE)
message(STATUS "Info: DCMTK TIFF support will be enabled")
include_directories(${TIFF_INCLUDE_DIR} ${JPEG_INCLUDE_DIR})
endif()
- set(LIBTIFF_LIBS ${TIFF_LIBRARY} ${TIFF_EXTRA_LIBS_STATIC} ${JPEG_LIBRARY})
+ set(LIBTIFF_LIBS ${TIFF_LIBRARIES})
endif()
endif()

@@ -57,7 +65,7 @@ if(DCMTK_USE_FIND_PACKAGE)
message(STATUS "Info: DCMTK PNG support will be enabled")
set(WITH_LIBPNG 1)
include_directories(${PNG_INCLUDE_DIR})
- set(LIBPNG_LIBS ${PNG_LIBRARY})
+ set(LIBPNG_LIBS ${PNG_LIBRARIES})
endif()
endif()

@@ -102,7 +110,7 @@ if(DCMTK_USE_FIND_PACKAGE)
else()
message(STATUS "Info: DCMTK XML support will be enabled")
set(WITH_LIBXML 1)
- include_directories(${LIBXML2_INCLUDE_DIR})
+ include_directories(${LIBXML2_INCLUDE_DIRS})
set(LIBXML_LIBS ${LIBXML2_LIBRARIES} ${LIBXML2_EXTRA_LIBS_STATIC})
endif()
endif()
@@ -140,7 +148,10 @@ if(DCMTK_USE_FIND_PACKAGE)
# Find libiconv
if(DCMTK_WITH_ICONV)
find_package(Iconv QUIET)
- find_package(LIBCHARSET QUIET)
+ set(ICONV_FOUND 1)
+ if(CHARSET_LIBRARIES)
+ set(LIBCHARSET_FOUND 1)
+ endif()
if(ICONV_FOUND)
if(NOT Iconv_IS_BUILT_IN)
set(LIBICONV_FOUND ${ICONV_FOUND})
19 changes: 19 additions & 0 deletions ports/dcmtk/disable-test-setup.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/CMake/dcmtkUseWine.cmake b/CMake/dcmtkUseWine.cmake
index 6dbd7dc..cf529e2 100644
--- a/CMake/dcmtkUseWine.cmake
+++ b/CMake/dcmtkUseWine.cmake
@@ -1,3 +1,14 @@
+if(CMAKE_HOST_WIN32)
+ function(DCMTK_SETUP_WINE)
+ endfunction()
+ function(WINE_COMMAND)
+ message(FATAL_ERROR "Not implemented")
+ endfunction()
+ function(WINE_DETACHED)
+ message(FATAL_ERROR "Not implemented")
+ endfunction()
+ return()
+endif()
#
# Functions for detection and usage of Wine
# Used when cross compiling
13 changes: 0 additions & 13 deletions ports/dcmtk/fix_link_tiff.patch

This file was deleted.

13 changes: 0 additions & 13 deletions ports/dcmtk/fix_link_xml2.patch

This file was deleted.

12 changes: 12 additions & 0 deletions ports/dcmtk/msvc.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bef673f..284d40e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,7 @@ target_include_directories(config INTERFACE
$<BUILD_INTERFACE:${DCMTK_BINARY_DIR}/config/include>
$<INSTALL_INTERFACE:include>
)
+target_compile_options(config INTERFACE "\$<\$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>")
install(TARGETS config EXPORT DCMTKTargets)

# Include directories
60 changes: 60 additions & 0 deletions ports/dcmtk/pkgconfig-lib-order.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 284d40e..8f8acfd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -158,7 +158,12 @@ endif()

if(DCMTK_WITH_ICONV)
# libiconv does not provide a .pc file
- set(PKGCONF_LIBS_PRIV "${PKGCONF_LIBS_PRIV} ${Iconv_LIBRARY} ${LIBCHARSET_LIBRARY}")
+ if(Iconv_LIBRARIES)
+ string(APPEND PKGCONF_LIBS_PRIV " -liconv")
+ endif()
+ if(CHARSET_LIBRARIES)
+ string(APPEND PKGCONF_LIBS_PRIV " -lcharset")
+ endif()
endif()

if(DCMTK_WITH_ICU)
@@ -200,6 +205,41 @@ endif()

get_property(DCMTK_LIBRARY_TARGETS GLOBAL PROPERTY DCMTK_LIBRARY_TARGETS)

+foreach(lib IN LISTS WIN32_STD_LIBRARIES)
+ string(APPEND PKGCONF_LIBS_PRIV " -l${lib}")
+endforeach()
+configure_file("${DCMTK_SOURCE_DIR}/CMake/dcmtk.pc.in" "${DCMTK_BINARY_DIR}/dcmtk-deps.pc" @ONLY)
+install(FILES "${DCMTK_BINARY_DIR}/dcmtk-deps.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
+set(PKGCONF_LIBS "")
+set(PKGCONF_LIBS_PRIV "")
+set(PKGCONF_REQ_PUB dcmtk-deps)
+set(PKGCONF_REQ_PRIV "")
+
+foreach(lib IN ITEMS
+ dcmfg # for dcmseg, dcmpmap, dcmect
+ dcmiod # for dcmpstat, dcmfg, dcmseg
+ dcmdsig # for dcmpstat
+ dcmtls # for dcmpstat
+ dcmqrdb # for dcmpstat
+ dcmsr # for cmr
+ dcmnet # for dcmtls, dcmwlm, dcmqrdb
+ dcmtkcharls # for dcmjpls
+ ijg8 # for dcmjpeg
+ ijg12 # fpr dcmjpeg
+ ijg16 # for dcmjpeg
+ dcmimage # for dcmjpeg etc.
+ dcmimgle # for dcmimage etc.
+ dcmxml # for i2d
+ dcmdata # fpr dcmxml, dcmimgle, etc.
+ oflog # for most libs
+ ofstd # for oflog
+ oficonv # for ofstd
+ )
+ if(lib IN_LIST DCMTK_LIBRARY_TARGETS)
+ list(REMOVE_ITEM DCMTK_LIBRARY_TARGETS ${lib})
+ list(APPEND DCMTK_LIBRARY_TARGETS ${lib})
+ endif()
+endforeach()
foreach(T ${DCMTK_LIBRARY_TARGETS})
set(PKGCONF_LIBS "${PKGCONF_LIBS} -l${T}")
endforeach()
73 changes: 46 additions & 27 deletions ports/dcmtk/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ vcpkg_from_github(
HEAD_REF master
PATCHES
dcmtk.patch
fix_link_xml2.patch
dependencies.diff
dictionary_paths.patch
fix_link_tiff.patch
disable-test-setup.diff
pkgconfig-lib-order.diff
msvc.diff
)
file(REMOVE
"${SOURCE_PATH}/CMake/FindICONV.cmake"
"${SOURCE_PATH}/CMake/FindICU.cmake"
"${SOURCE_PATH}/CMake/FindJPEG.cmake"
)

# Prefix all exported API symbols of vendored libjpeg with "dcmtk_"
Expand All @@ -19,6 +26,18 @@ foreach(file_path ${src_files})
file(WRITE "${file_path}" "${file_string}")
endforeach()

vcpkg_cmake_get_vars(cmake_vars_file)
include("${cmake_vars_file}")
if(VCPKG_DETECTED_CMAKE_CROSSCOMPILING)
message(STATUS [[
Cross-compiling DCMTK needs input from executing test programs in the target
environment. You may need to provide a suitable emulator setup, and you can set
values directly with `VCPKG_CMAKE_CONFIGURE_OPTIONS` in a custom triplet file.
For more information see
https://support.dcmtk.org/redmine/projects/dcmtk/wiki/Cross_Compiling
]])
endif()

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
"iconv" DCMTK_WITH_ICONV
Expand All @@ -33,37 +52,40 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS

if("external-dict" IN_LIST FEATURES)
set(DCMTK_DEFAULT_DICT "external")
set(DCMTK_ENABLE_BUILTIN_OFICONV_DATA OFF)
set(DCMTK_ENABLE_BUILTIN_OFICONV_DATA OFF)
else()
set(DCMTK_DEFAULT_DICT "builtin")
set(DCMTK_ENABLE_BUILTIN_OFICONV_DATA ON)
set(DCMTK_ENABLE_BUILTIN_OFICONV_DATA ON)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
${FEATURE_OPTIONS}
"-DDCMTK_DEFAULT_DICT=${DCMTK_DEFAULT_DICT}"
-DDCMTK_ENABLE_BUILTIN_OFICONV_DATA=${DCMTK_ENABLE_BUILTIN_OFICONV_DATA}
-DDCMTK_WITH_DOXYGEN=OFF
-DDCMTK_FORCE_FPIC_ON_UNIX=ON
-DDCMTK_OVERWRITE_WIN32_COMPILER_FLAGS=OFF
-DDCMTK_ENABLE_PRIVATE_TAGS=ON
-DCMAKE_CXX_STANDARD=17
-DCMAKE_INSTALL_DOCDIR=share/${PORT}/doc
-DDCMTK_DEFAULT_DICT=${DCMTK_DEFAULT_DICT}
-DCMAKE_DISABLE_FIND_PACKAGE_BISON=ON
-DCMAKE_DISABLE_FIND_PACKAGE_FLEX=ON
-DDCMTK_ENABLE_BUILTIN_OFICONV_DATA=${DCMTK_ENABLE_BUILTIN_OFICONV_DATA}
-DDCMTK_ENABLE_PRIVATE_TAGS=ON
-DDCMTK_ENABLE_STL=ON
-DDCMTK_OVERWRITE_WIN32_COMPILER_FLAGS=OFF
-DDCMTK_USE_FIND_PACKAGE=ON
-DDCMTK_WIDE_CHAR_FILE_IO_FUNCTIONS=ON
-DDCMTK_WIDE_CHAR_MAIN_FUNCTION=ON
-DDCMTK_ENABLE_STL=ON
-DCMAKE_DEBUG_POSTFIX=d
-DDCMTK_USE_FIND_PACKAGE_WIN_DEFAULT=ON
-DBUILD_TESTING=OFF
-DDCMTK_WITH_OPENJPEG=OFF
-DDCMTK_WITH_DOXYGEN=OFF
-DDCMTK_WITH_SNDFILE=OFF
-DDCMTK_WITH_WRAP=OFF
OPTIONS_DEBUG
-DINSTALL_HEADERS=OFF
-DINSTALL_OTHER=OFF
-DBUILD_APPS=OFF
)

vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_cmake_config_fixup()
vcpkg_fixup_pkgconfig()

if ("tools" IN_LIST FEATURES)
set(_tools
Expand Down Expand Up @@ -147,18 +169,15 @@ if ("tools" IN_LIST FEATURES)
vcpkg_copy_tools(TOOL_NAMES ${_tools} AUTO_CLEAN)
endif()

vcpkg_cmake_config_fixup()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/dcmtk/config/osconfig.h" "#define DCMTK_PREFIX \"${CURRENT_PACKAGES_DIR}\"" "" IGNORE_UNCHANGED)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/dcmtk/config/osconfig.h" "#define DCM_DICT_DEFAULT_PATH \"${CURRENT_PACKAGES_DIR}/share/dcmtk-${VERSION}/dicom.dic:${CURRENT_PACKAGES_DIR}/share/dcmtk-${VERSION}/private.dic\"" "" IGNORE_UNCHANGED)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/dcmtk/config/osconfig.h" "#define DEFAULT_CONFIGURATION_DIR \"${CURRENT_PACKAGES_DIR}/etc/dcmtk-${VERSION}/\"" "" IGNORE_UNCHANGED)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/dcmtk/config/osconfig.h" "#define DEFAULT_SUPPORT_DATA_DIR \"${CURRENT_PACKAGES_DIR}/share/dcmtk-${VERSION}/\"" "" IGNORE_UNCHANGED)

vcpkg_fixup_pkgconfig()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYRIGHT")
# no absolute paths
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/dcmtk/config/osconfig.h"
"#define (DCMTK_PREFIX|DCM_DICT_DEFAULT_PATH|DEFAULT_CONFIGURATION_DIR|DEFAULT_SUPPORT_DATA_DIR) \"[^\"]*\""
"#define \\1 \"\" /* redacted by vcpkg */"
REGEX
)

configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" @ONLY)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/${PORT}/doc-${VERSION}/COPYRIGHT" "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright")
30 changes: 7 additions & 23 deletions ports/dcmtk/usage
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
The package dcmtk provides CMake targets:
dcmtk provides CMake targets:

find_package(DCMTK CONFIG REQUIRED)
target_link_libraries(main PRIVATE DCMTK::DCMTK)
# You may also need one or more of the following targets:
# DCMTK::cmr DCMTK::i2d DCMTK::ijg8 DCMTK::config DCMTK::ofstd
# DCMTK::oflog DCMTK::dcmdata DCMTK::dcmimgle DCMTK::dcmimage
# DCMTK::dcmjpeg DCMTK::ijg12 DCMTK::ijg16 DCMTK::dcmjpls
# DCMTK::dcmtkcharls DCMTK::dcmtls DCMTK::dcmnet DCMTK::dcmsr
# DCMTK::dcmdsig DCMTK::dcmwlm DCMTK::dcmqrdb DCMTK::dcmpstat
# DCMTK::dcmrt DCMTK::dcmiod DCMTK::dcmfg DCMTK::dcmseg
# DCMTK::dcmtract DCMTK::dcmpmap DCMTK::dcmect
find_package(DCMTK CONFIG REQUIRED)
target_link_libraries(main PRIVATE DCMTK::DCMTK)
# You may also select specific modules using DCMTK::<module>.

Add the following cmake code to your CMakeLists.txt to create definitions for DCMTK
if ("${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}" STREQUAL "/")
message(WARNING "No vcpkg install dir found, DCMTK definitions are not set")
else()
target_compile_definitions(main
PUBLIC
"DCMTK_PREFIX=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}"
"DCM_DICT_DEFAULT_PATH=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk-@VERSION@/dicom.dic:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk-@VERSION@/private.dic"
"DEFAULT_CONFIGURATION_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/etc/dcmtk-@VERSION@/"
"DEFAULT_SUPPORT_DATA_DIR=${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/dcmtk-@VERSION@/"
)
endif()
dcmtk provides pkg-config modules:

dcmtk
10 changes: 7 additions & 3 deletions ports/dcmtk/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "dcmtk",
"version": "3.6.8",
"port-version": 8,
"port-version": 9,
"description": "This DICOM ToolKit (DCMTK) package consists of source code, documentation and installation instructions for a set of software libraries and applications implementing part of the DICOM/MEDICOM Standard.",
"homepage": "https://github.com/DCMTK/dcmtk",
"license": "BSD-3-Clause OR BSD-2-Clause OR libtiff OR MIT OR Zlib OR Libpng",
"supports": "!(windows & arm)",
"license": null,
"supports": "!uwp",
"dependencies": [
{
"name": "vcpkg-cmake",
Expand All @@ -14,6 +14,10 @@
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "vcpkg-cmake-get-vars",
"host": true
}
],
"features": {
Expand Down
13 changes: 2 additions & 11 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,6 @@ cctag:x64-windows-static-md=fail
cello:arm64-uwp=fail
cello:x64-uwp=fail
chakracore:x64-linux=skip
# DCMTK currently has a vendored copy of libcharls.a, which causes conflicts with charls (TODO: use charls' copy)
charls:arm64-windows=skip
charls:arm64-uwp=skip
charls:x64-linux=skip
charls:x64-osx=skip
charls:x64-uwp=skip
charls:x64-windows=skip
charls:x64-windows-static=skip
charls:x64-windows-static-md=skip
charls:x86-windows=skip
# chartdir does not offer stable download URLs
chartdir:arm-neon-android=fail
chartdir:arm64-android=fail
Expand Down Expand Up @@ -300,10 +290,11 @@ dbghelp:x64-windows-static=skip
dbghelp:x64-windows-static-md=skip
dbghelp:x64-windows=skip
dbghelp:x86-windows=skip
# Cross builds depend on try_run results
dcmtk:arm-neon-android=fail
dcmtk:arm64-android=fail
dcmtk:arm64-windows=fail
dcmtk:x64-android=fail
dcmtk:x64-uwp=fail
# legacy directxsdk which conflicts with dxsdk-d3dx
directxsdk:x86-windows=skip
directxsdk:x64-windows=skip
Expand Down
10 changes: 10 additions & 0 deletions scripts/test_ports/vcpkg-ci-dcmtk/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

vcpkg_find_acquire_program(PKGCONFIG)

vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
OPTIONS
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
)
vcpkg_cmake_build()
Loading

0 comments on commit 61a6ef5

Please sign in to comment.