Skip to content

Commit

Permalink
GDCM 2023-05-05 (401a81d7)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/malaterre/GDCM.git

at commit 401a81d746c980dae71957d4e6126b633d2b2952 (release).
  • Loading branch information
GDCM Upstream authored and seanm committed May 24, 2023
1 parent 91f7139 commit 8713d6f
Show file tree
Hide file tree
Showing 217 changed files with 10,945 additions and 1,778 deletions.
113 changes: 106 additions & 7 deletions CMakeLists.txt
Expand Up @@ -17,7 +17,7 @@ endif()
#----------------------------------------------------------------------------

project(GDCM
VERSION 3.0.10
VERSION 3.0.22
LANGUAGES CXX C
)
## NOTE: the "DESCRIPTION" feature of project() was introduced in cmake 3.10.0
Expand All @@ -28,6 +28,7 @@ set(GDCM_MAJOR_VERSION ${GDCM_VERSION_MAJOR})
set(GDCM_MINOR_VERSION ${GDCM_VERSION_MINOR})
set(GDCM_BUILD_VERSION ${GDCM_VERSION_PATCH})
set(GDCM_VERSION "${GDCM_VERSION_MAJOR}.${GDCM_VERSION_MINOR}.${GDCM_VERSION_PATCH}") # ${GDCM_VERSION_TWEAK}
set(GDCM_SHORT_VERSION "${GDCM_VERSION_MAJOR}.${GDCM_VERSION_MINOR}")

mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY CMAKE_BUILD_TYPE CMAKE_INSTALL_PREFIX)
set(GDCM_CMAKE_DIR "${GDCM_SOURCE_DIR}/CMake" CACHE INTERNAL "")
Expand Down Expand Up @@ -133,6 +134,12 @@ if(NOT LIBRARY_OUTPUT_PATH)
mark_as_advanced(LIBRARY_OUTPUT_PATH)
endif()

# TODO: The following should be used for CMake 3 and beyond,
# EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH are deprecated
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})

#-----------------------------------------------------------------------------
# Adding GDCM_DATA_ROOT
if(GDCM_STANDALONE)
Expand Down Expand Up @@ -497,11 +504,14 @@ endif()
#-----------------------------------------------------------------------------
# Wrapping
if(GDCM_STANDALONE)
option(GDCM_WRAP_PYTHON "build python wrapping" OFF)
option(GDCM_WRAP_PYTHON "build gdcm/python wrapping" OFF)
option(VTKGDCM_WRAP_PYTHON "build vtkgdcm/python wrapping" OFF)
option(GDCM_WRAP_PERL "build perl wrapping (experimental !)" OFF)
option(GDCM_WRAP_PHP "build php wrapping" OFF)
option(GDCM_WRAP_JAVA "build java wrapping" OFF)
option(GDCM_WRAP_CSHARP "build csharp wrapping" OFF)
option(GDCM_WRAP_JAVA "build gdcm/java wrapping" OFF)
option(VTKGDCM_WRAP_JAVA "build vtkgdcm/java wrapping" OFF)
option(GDCM_WRAP_CSHARP "build gdcm/csharp wrapping" OFF)
option(VTKGDCM_WRAP_CSHARP "build vtkgdcm/csharp wrapping" OFF)
mark_as_advanced(GDCM_WRAP_PHP)
mark_as_advanced(GDCM_WRAP_PERL)
mark_as_advanced(GDCM_USE_ACTIVIZ)
Expand Down Expand Up @@ -650,7 +660,96 @@ if(GDCM_STANDALONE)
mark_as_advanced(VTK_DIR)
set(GDCM_VTK_DIR ${VTK_DIR})
mark_as_advanced(GDCM_USE_PARAVIEW)
add_subdirectory(Utilities/VTK)

set(VTKGDCM_NAME vtkgdcm CACHE STRING "vtk-gdcm lib name")
mark_as_advanced(VTKGDCM_NAME)

if(VTK_VERSION VERSION_LESS 8.90)
add_subdirectory(Utilities/VTK)
else()
message(STATUS "Building Utilities/VTK as a VTK 9 Module")
# TODO: use VTKGDCM_NAME instead of vtkgdcm

option(VTKGDCM_VERSIONED_INSTALL "Install with versioned names." ON)
mark_as_advanced(VTKGDCM_VERSIONED_INSTALL)
if(VTKGDCM_VERSIONED_INSTALL)
set(vtk_version_suffix "-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")
set(vtkgdcm_library_suffix "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")
else()
set(vtk_version_suffix "")
set(vtkgdcm_library_suffix "")
endif()
if(DEFINED GDCM_CUSTOM_LIBRARY_SUFFIX)
set(vtkgdcm_library_suffix "${GDCM_CUSTOM_LIBRARY_SUFFIX}")
endif()

vtk_module_scan(
MODULE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/VTK/vtkgdcm.module"
REQUEST_MODULES "GDCM::vtkgdcm"
PROVIDES_MODULES vtkgdcm_modules
ENABLE_TESTS "${GDCM_BUILD_TESTING}"
)

# documented at https://vtk.org/doc/nightly/html/group__module.html
vtk_module_build(
MODULES ${vtkgdcm_modules}
INSTALL_EXPORT GDCM
ARCHIVE_DESTINATION "${GDCM_INSTALL_LIB_DIR}"
HEADERS_DESTINATION "${GDCM_INSTALL_INCLUDE_DIR}/vtk${vtk_version_suffix}"
CMAKE_DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}"
LICENSE_DESTINATION "${GDCM_INSTALL_DATA_DIR}/vtkgdcm-${GDCM_SHORT_VERSION}"
HIERARCHY_DESTINATION "${GDCM_INSTALL_LIB_DIR}/vtk${vtk_version_suffix}/hierarchy/vtkgdcm"
LIBRARY_NAME_SUFFIX "${vtkgdcm_library_suffix}"
VERSION "${GDCM_VERSION}"
SOVERSION "1"
# TODO: these are probably not set as they should be
#USE_EXTERNAL "${GDCM_USE_EXTERNAL}"
#TEST_DATA_TARGET vtkgdcmData
#TEST_INPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_input}"
#TEST_OUTPUT_DATA_DIRECTORY "${vtkgdcm_test_data_directory_output}"
)

if(VTKGDCM_WRAP_PYTHON)
find_package(PythonInterp ${VTK_PYTHON_VERSION} QUIET)

vtk_module_wrap_python(
MODULES ${vtkgdcm_modules}
TARGET GDCM::vtkgdcmpython
INSTALL_EXPORT vtkgdcmPython
PYTHON_PACKAGE "vtkgdcm"
CMAKE_DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}"
LIBRARY_DESTINATION "${GDCM_INSTALL_LIB_DIR}"
MODULE_DESTINATION "${GDCM_VTK_INSTALL_PYTHONMODULE_DIR}"
SOABI "${Python${VTK_PYTHON_VERSION}_SOABI}"
BUILD_STATIC OFF
)

file(GENERATE
OUTPUT "${CMAKE_BINARY_DIR}/${GDCM_VTK_INSTALL_PYTHONMODULE_DIR}/vtkgdcm/__init__.py"
CONTENT "from .vtkgdcm import *\n\n__all__ = ['vtkgdcm']\n__version__ = \"${GDCM_VERSION}\"\n")
install(
FILES "${CMAKE_BINARY_DIR}/${GDCM_VTK_INSTALL_PYTHONMODULE_DIR}/vtkgdcm/__init__.py"
DESTINATION "${GDCM_VTK_INSTALL_PYTHONMODULE_DIR}/vtkgdcm/")

export(
EXPORT vtkgdcmPython
NAMESPACE GDCM::
FILE "${GDCM_INSTALL_PACKAGE_DIR}/vtkgdcmPython-targets.cmake")
install(
EXPORT vtkgdcmPython
NAMESPACE GDCM::
FILE vtkgdcmPython-targets.cmake
DESTINATION "${GDCM_INSTALL_PACKAGE_DIR}")
endif()

if(VTKGDCM_WRAP_JAVA)
# TODO: this is broken, incomplete, needs lots of work
vtk_module_wrap_java(
MODULES ${vtkgdcm_modules}
WRAPPED_MODULES vtkgdcm_java_wrapped_modules
JAVA_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles")
endif()
endif()
endif()
endif()

Expand Down Expand Up @@ -805,11 +904,11 @@ if(GDCM_STANDALONE) # disabled for ITK distribution of gdcm
if(GDCM_USE_VTK)
foreach(comp ${components})
if( "${comp}" STREQUAL "PythonModule" )
if(VTK_WRAP_PYTHON)
if(VTK_WRAP_PYTHON AND VTKGDCM_WRAP_PYTHON)
list(APPEND components VTK${comp})
endif()
elseif( "${comp}" STREQUAL "JavaModule" )
if(VTK_WRAP_JAVA)
if(VTK_WRAP_JAVA AND VTKGDCM_WRAP_JAVA)
list(APPEND components VTK${comp})
endif()
else()
Expand Down
18 changes: 17 additions & 1 deletion Source/Common/CMakeLists.txt
Expand Up @@ -62,8 +62,11 @@ CHECK_CXX_SOURCE_COMPILES(
"int main() { const char *f = __FUNCTION__; return 0;}"
GDCM_CXX_HAS_FUNCTION)
CHECK_CXX_SOURCE_COMPILES(
"\#include <fstream>\nint main() { const wchar_t fn[10] = {}; std::ifstream is( fn ); return 0;}"
"\#include <fstream>\nint main() { const wchar_t fn[10] = {}; std::ifstream is( fn ); std::wcerr << fn; return 0;}"
GDCM_HAVE_WCHAR_IFSTREAM)
CHECK_CXX_SOURCE_COMPILES(
"\#include <string>\n#include <codecvt>\n#include <locale>\nint main() { std::u16string u16; std::string utf8 = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16); }"
GDCM_HAVE_CODECVT)
if(GDCM_USE_SYSTEM_OPENSSL)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES}
Expand All @@ -74,6 +77,9 @@ CHECK_CXX_SOURCE_COMPILES(
#HAVE_CMS_RECIPIENT_KEY)
"\#include <openssl/cms.h>\nint main() { CMS_add0_recipient_password(0,0,0,0,0,0,0); return 0;}"
GDCM_HAVE_CMS_RECIPIENT_PASSWORD)
CHECK_CXX_SOURCE_COMPILES(
"\#include <openssl/bio.h>\nint main() { const void*mem; int len; BIO_new_mem_buf(mem, len); }"
OPENSSL_HAS_CONST_VOID_BIO_NEW_MEM_BUF)
endif()

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -164,13 +170,23 @@ set(Common_SRCS ${Common_SRCS}
gdcmOpenSSLP7CryptoFactory.cxx
gdcmOpenSSLP7CryptographicMessageSyntax.cxx
)
if(OPENSSL_HAS_CONST_VOID_BIO_NEW_MEM_BUF)
set_source_files_properties(
gdcmOpenSSLP7CryptographicMessageSyntax.cxx
PROPERTIES COMPILE_FLAGS "-DOPENSSL_HAS_CONST_VOID_BIO_NEW_MEM_BUF")
endif()
endif()

if(GDCM_USE_SYSTEM_OPENSSL AND GDCM_HAVE_CMS_RECIPIENT_PASSWORD)
set(Common_SRCS ${Common_SRCS}
gdcmOpenSSLCryptoFactory.cxx
gdcmOpenSSLCryptographicMessageSyntax.cxx
)
if(OPENSSL_HAS_CONST_VOID_BIO_NEW_MEM_BUF)
set_source_files_properties(
gdcmOpenSSLCryptographicMessageSyntax.cxx
PROPERTIES COMPILE_FLAGS "-DOPENSSL_HAS_CONST_VOID_BIO_NEW_MEM_BUF")
endif()
endif()

if(GDCM_BUILD_TESTING)
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/gdcmASN1.cxx
Expand Up @@ -14,7 +14,7 @@
#include "gdcmASN1.h"
#include "gdcmSystem.h"

#include <string.h>
#include <cstring>

#ifdef GDCM_USE_SYSTEM_OPENSSL
#include <openssl/bio.h>
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/gdcmBase64.cxx
Expand Up @@ -12,7 +12,7 @@
=========================================================================*/
#include "gdcmBase64.h"
#include <string.h> // memcpy
#include <cstring> // memcpy
#include <iostream>

namespace gdcm
Expand Down
4 changes: 4 additions & 0 deletions Source/Common/gdcmConfigure.h.in
Expand Up @@ -117,6 +117,10 @@
// UTF-8
#cmakedefine GDCM_HAVE_WCHAR_IFSTREAM

// https://stackoverflow.com/questions/15615136/is-codecvt-not-a-std-header
// https://stackoverflow.com/questions/50867257/c-use-of-wstring-convert-on-linux
#cmakedefine GDCM_HAVE_CODECVT

#cmakedefine GDCM_FORCE_BIGENDIAN_EMULATION

#ifndef GDCM_OVERRIDE_BROKEN_IMPLEMENTATION
Expand Down
12 changes: 7 additions & 5 deletions Source/Common/gdcmDirectory.cxx
Expand Up @@ -14,11 +14,11 @@
#include "gdcmDirectory.h"
#include "gdcmTrace.h"

#include <cassert>
#include <cerrno>
#include <cstring> // strerror
#include <iterator>
#include <assert.h>
#include <errno.h>
#include <sys/stat.h> //stat function
#include <string.h> // strerror

#ifdef _MSC_VER
#include <windows.h>
Expand Down Expand Up @@ -65,8 +65,10 @@ unsigned int Directory::Explore(FilenameType const &name, bool recursive)
std::wstring dirName = System::ConvertToUNC(name.c_str());
Directories.push_back(ToUtf8(dirName));
WIN32_FIND_DATAW fileData;
if ('\\' != dirName[dirName.size()-1]) dirName.push_back('\\');
assert( '\\' == dirName[dirName.size()-1] );
if ('\\' == dirName[dirName.size() - 1])
dirName = dirName.substr(0, dirName.size() - 1);
if ('/' != dirName[dirName.size() - 1]) dirName.push_back('/');
assert( '/' == dirName[dirName.size()-1] );
const std::wstring firstfile = dirName+L"*";
HANDLE hFile = FindFirstFileW(firstfile.c_str(), &fileData);

Expand Down
4 changes: 2 additions & 2 deletions Source/Common/gdcmEvent.h
Expand Up @@ -49,7 +49,7 @@ public :
};

/// Generic inserter operator for Event and its subclasses.
inline std::ostream& operator<<(std::ostream& os, Event &e)
inline std::ostream& operator<<(std::ostream& os, const Event &e)
{
e.Print(os);
return os;
Expand All @@ -71,7 +71,7 @@ inline std::ostream& operator<<(std::ostream& os, Event &e)
{ return dynamic_cast<const Self*>(e) ? true : false; } \
virtual ::gdcm::Event* MakeObject() const override \
{ return new Self; } \
classname(const Self&s) : super(s){}; \
classname(const Self&s) : super(s){} \
private: \
void operator=(const Self&); \
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/gdcmFileNameEvent.h
Expand Up @@ -34,7 +34,7 @@ class FileNameEvent : public AnyEvent
FileNameEvent(const char *s = ""):m_FileName(s) {}
~FileNameEvent() override = default;

FileNameEvent(const Self&s) : AnyEvent(s){};
FileNameEvent(const Self&s) : AnyEvent(s){}
void operator=(const Self&) = delete;


Expand Down
18 changes: 9 additions & 9 deletions Source/Common/gdcmFilename.cxx
Expand Up @@ -12,10 +12,10 @@
=========================================================================*/
#include "gdcmFilename.h"
#include <limits.h>
#include <stdlib.h> // realpath
#include <assert.h>
#include <string.h>
#include <cassert>
#include <climits>
#include <cstdlib> // realpath
#include <cstring>

namespace gdcm
{
Expand All @@ -28,7 +28,7 @@ const char *Filename::GetPath()
{
std::string fn = ToUnixSlashes();

std::string::size_type slash_pos = fn.rfind("/");
std::string::size_type slash_pos = fn.rfind('/');
if(slash_pos != std::string::npos)
{
Path = fn.substr(0, slash_pos);
Expand All @@ -52,14 +52,14 @@ const char *Filename::GetName()
#if defined(_WIN32)
std::string::size_type slash_pos = filename.find_last_of("/\\");
#else
std::string::size_type slash_pos = filename.find_last_of("/");
std::string::size_type slash_pos = filename.find_last_of('/');
#endif
if(slash_pos != std::string::npos)
{
return &FileName[0] + slash_pos + 1;
return FileName.data() + slash_pos + 1;
}

return &FileName[0];
return FileName.data();
}

const char *Filename::ToWindowsSlashes()
Expand Down Expand Up @@ -142,7 +142,7 @@ inline void Realpath(const char *path, std::string & resolved_path)
const char *Filename::GetExtension()
{
std::string name = GetName();
std::string::size_type dot_pos = name.rfind(".");
std::string::size_type dot_pos = name.rfind('.');
if(dot_pos != std::string::npos)
{
return GetName() + dot_pos;
Expand Down
12 changes: 8 additions & 4 deletions Source/Common/gdcmMD5.cxx
Expand Up @@ -19,8 +19,12 @@
#elif defined(GDCM_BUILD_TESTING)
#include "gdcm_md5.h"
#endif
#include <cstdio>
#include <fstream>
#include <vector>
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif

// http://stackoverflow.com/questions/13256446/compute-md5-hash-value-by-c-winapi
namespace gdcm
Expand All @@ -39,7 +43,7 @@ bool MD5::Compute(const char *buffer, size_t buf_len, char digest_str[33])
MD5_Update(&ctx, buffer, buf_len);
MD5_Final(digest, &ctx);
for (int di = 0; di < 16; ++di)
sprintf(digest_str+2*di, "%02x", digest[di]);
snprintf(digest_str+2*di, 3, "%02x", digest[di]);
digest_str[2*16] = '\0';
return true;
#elif defined(GDCM_BUILD_TESTING)
Expand All @@ -49,7 +53,7 @@ bool MD5::Compute(const char *buffer, size_t buf_len, char digest_str[33])
md5_append(&state, (const md5_byte_t *)buffer, buf_len);
md5_finish(&state, digest);
for (int di = 0; di < 16; ++di)
sprintf(digest_str+2*di, "%02x", digest[di]);
snprintf(digest_str+2*di, 3, "%02x", digest[di]);
digest_str[2*16] = '\0';
return true;
#else
Expand Down Expand Up @@ -90,7 +94,7 @@ static bool process_file(const char *filename, md5_byte_t *digest)
const size_t file_size = System::FileSize(filename);
std::vector<char> v( file_size );

char *buffer = &v[0];
char *buffer = v.data();
file.read(buffer, file_size);

md5_state_t state;
Expand Down Expand Up @@ -124,7 +128,7 @@ bool MD5::ComputeFile(const char *filename, char digest_str[33])

for (int di = 0; di < 16; ++di)
{
sprintf(digest_str+2*di, "%02x", digest[di]);
snprintf(digest_str+2*di, 3, "%02x", digest[di]);
}
digest_str[2*16] = '\0';
return true;
Expand Down

0 comments on commit 8713d6f

Please sign in to comment.