Skip to content

Commit

Permalink
Harmonize dictionary options.
Browse files Browse the repository at this point in the history
There are now two variables in CMake to control the default dictionary
chosen on DCMTK startup: DCMTK_DEFAULT_DICT and DCMTK_USE_DCMDICTPATH.

DCMTK_DEFAULTDICT has three settings:
- external: Will load dictionary on DCMTK startup from pre-defined
  default path.
- builtin: Will compile and load built-in dictionary into DCMTK.
- none: Will not load any pre-configured dictionary at all.

On top, DCMTK can load one or more dictionaries from evaulating
the environment variable DCMDICTPATH at runtime. This behaviour is
controlled by the CMake setting DCMTK_USE_DCMDICTPATH. If it is turned
on, DCMTK will evaluate DCMDICTPATH, otherwise it doesn't.

More details can befound in dcmdata/docs/datadict.txt.

Also, an error message is printed if external default dictionary is
enabled but cannot be loaded (e.g. since file does not exist at
default path). In the past this has been silently ignored for the
default dictionary, only errors while loading dictionaries defined by
DCMDICTPATH environment variables have been reported.
  • Loading branch information
michaelonken committed Sep 1, 2021
1 parent 091eeed commit 4ab084d
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 299 deletions.
9 changes: 7 additions & 2 deletions CMake/DCMTKConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ set(DCMTK_WITH_OPENJPEG @DCMTK_WITH_OPENJPEG@)
set(DCMTK_WITH_DOXYGEN @DCMTK_WITH_DOXYGEN@)

# Dictionary-related
set(DCMTK_ENABLE_BUILTIN_DICTIONARY @DCMTK_ENABLE_BUILTIN_DICTIONARY@)
set(DCMTK_ENABLE_EXTERNAL_DICTIONARY @DCMTK_ENABLE_EXTERNAL_DICTIONARY@)

# Define the type of standard dictionary that we want to use:
# 0 - Do not load any default dictionary on startup
# 1 - Load builtin dictionary on startup
# 2 - Load external (i.e. file-based) dictionary on startup
set(DCM_DICT_DEFAULT @DCM_DICT_DEFAULT@)
set(DCM_DICT_USE_DCMDICTPATH @DCM_DICT_USE_DCMDICTPATH@)
set(DCMTK_ENABLE_PRIVATE_TAGS @DCMTK_ENABLE_PRIVATE_TAGS@)

# Compiler / standard library features
Expand Down
9 changes: 7 additions & 2 deletions CMake/DCMTKConfig.old_cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ set(DCMTK_WITH_OPENJPEG @DCMTK_WITH_OPENJPEG@)
SET(DCMTK_WITH_DOXYGEN @DCMTK_WITH_DOXYGEN@)

# Dictionary-related
SET(DCMTK_ENABLE_BUILTIN_DICTIONARY @DCMTK_ENABLE_BUILTIN_DICTIONARY@)
SET(DCMTK_ENABLE_EXTERNAL_DICTIONARY @DCMTK_ENABLE_EXTERNAL_DICTIONARY@)

# Define the type of standard dictionary that we want to use:
# 0 - Do not load any default dictionary on startup
# 1 - Load builtin dictionary on startup
# 2 - Load external (i.e. file-based) dictionary on startup
SET(DCM_DICT_DEFAULT @DCM_DICT_DEFAULT@)
SET(DCM_DICT_USE_DCMDICTPATH @DCM_DICT_USE_DCMDICTPATH@)
SET(DCMTK_ENABLE_PRIVATE_TAGS @DCMTK_ENABLE_PRIVATE_TAGS@)

# Compiler / standard library features
Expand Down
33 changes: 17 additions & 16 deletions CMake/GenerateDCMTKConfigure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@ else()
set(CMAKE_TRY_COMPILE_CONFIGURATION "Release")
endif()

# Compiled-in dictionary support
if(DCMTK_ENABLE_BUILTIN_DICTIONARY)
set(ENABLE_BUILTIN_DICTIONARY 1)
message(STATUS "Info: DCMTK will compile with built-in (compiled-in) dictionary")
# Select between built-in, external or no default dictionary support
if(DCMTK_DEFAULT_DICT STREQUAL "builtin")
message(STATUS "Info: DCMTK will compile with built-in (compiled-in) default dictionary")
set(DCM_DICT_DEFAULT 1)
# No extra variable needed since its only evaluated in CMake files
elseif(DCMTK_DEFAULT_DICT STREQUAL "external")
message(STATUS "Info: DCMTK will compile with external default dictionary")
set(DCM_DICT_DEFAULT 2)
else()
set(ENABLE_BUILTIN_DICTIONARY "")
message(STATUS "Info: DCMTK will compile without built-in (compiled-in) dictionary")
# No extra variable needed since its only evaluated in CMake files
message(STATUS "Info: DCMTK will compile without any default dictionary")
set(DCM_DICT_DEFAULT 0)
endif()

# External dictionary support
if(DCMTK_ENABLE_EXTERNAL_DICTIONARY)
set(ENABLE_EXTERNAL_DICTIONARY 1)
message(STATUS "Info: DCMTK will try to load external dictionary from default path on startup")
# Evaluation of DCMDICTPATH environment variable
if(DCMTK_USE_DCMDICTPATH)
set(DCM_DICT_USE_DCMDICTPATH 1)
message(STATUS "Info: DCMTK will load dictionaries defined by DCMDICTPATH environment variable")
else()
set(ENABLE_EXTERNAL_DICTIONARY "")
message(STATUS "Info: DCMTK will not try to load external dictionary from default path on startup")
set(DCM_DICT_USE_DCMDICTPATH "")
message(WARNING "Info: DCMTK will not load dictionaries defined by DCMDICTPATH environment variable")
endif()


# Private tags
if(DCMTK_ENABLE_PRIVATE_TAGS)
set(ENABLE_PRIVATE_TAGS 1)
Expand Down Expand Up @@ -126,7 +127,7 @@ if(WIN32 AND NOT CYGWIN)
set(PATH_SEPARATOR "\\\\")
set(ENVIRONMENT_PATH_SEPARATOR ";")
# Set dictionary path to the data dir inside install main dir (prefix)
if(DCMTK_ENABLE_EXTERNAL_DICTIONARY)
if(DCMTK_DEFAULT_DICT STREQUAL "external")
set(DCM_DICT_DEFAULT_PATH "${DCMTK_PREFIX}\\\\${CMAKE_INSTALL_DATADIR}\\\\dcmtk\\\\dicom.dic")
# If private dictionary should be utilized, add it to default dictionary path.
if(ENABLE_PRIVATE_TAGS)
Expand All @@ -147,7 +148,7 @@ else()
set(PATH_SEPARATOR "/")
set(ENVIRONMENT_PATH_SEPARATOR ":")
# Set dictionary path to the data dir inside install main dir (prefix).
if(DCMTK_ENABLE_EXTERNAL_DICTIONARY)
if(DCMTK_DEFAULT_DICT STREQUAL "external")
set(DCM_DICT_DEFAULT_PATH "${DCMTK_PREFIX}/${CMAKE_INSTALL_DATADIR}/dcmtk/dicom.dic")
# If private dictionary should be utilized, add it to default dictionary path.
if(ENABLE_PRIVATE_TAGS)
Expand Down
23 changes: 13 additions & 10 deletions CMake/dcmtkPrepare.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,25 @@ DCMTK_INFERABLE_OPTION(DCMTK_ENABLE_STL_TUPLE "Enable use of STL tuple.")
DCMTK_INFERABLE_OPTION(DCMTK_ENABLE_STL_SYSTEM_ERROR "Enable use of STL system_error.")
DCMTK_INFERABLE_OPTION(DCMTK_ENABLE_CXX11 "Enable use of native C++11 features (eg. move semantics).")

# Built-in (compiled-in) dictionary enabled on Windows per default, otherwise
# disabled. Loading of external dictionary via run-time is, per default,
# configured the the opposite way since most users won't be interested in using
# the external default dictionary if it is already compiled in.
# On Windows, the built-in dictionary is default, on Unix the external one.
# It is not possible to use both, built-in plus external default dictionary.
if(WIN32 OR MINGW)
option(DCMTK_ENABLE_BUILTIN_DICTIONARY "Configure DCMTK with compiled-in data dictionary." ON)
option(DCMTK_ENABLE_EXTERNAL_DICTIONARY "Configure DCMTK to load external dictionary from default path on startup." ON)
set(DCMTK_DEFAULT_DICT "builtin" CACHE STRING "Denotes whether DCMTK will use built-in (compiled-in), external (file), or no default dictionary on startup")
else() # built-in dictionary turned off on Unix per default
option(DCMTK_ENABLE_BUILTIN_DICTIONARY "Configure DCMTK with compiled-in data dictionary." OFF)
option(DCMTK_ENABLE_EXTERNAL_DICTIONARY "Configure DCMTK to load external dictionary from default path on startup." ON)
set(DCMTK_DEFAULT_DICT "external" CACHE STRING "Denotes whether DCMTK will use built-in (compiled-in), external (file), or no default dictionary on startup")
endif()
if (NOT DCMTK_ENABLE_EXTERNAL_DICTIONARY AND NOT DCMTK_ENABLE_BUILTIN_DICTIONARY)
message(WARNING "Either external or built-in dictionary should be enabled, otherwise dictionary must be loaded manually on startup!")
set_property(CACHE DCMTK_DEFAULT_DICT PROPERTY STRINGS builtin external none)
if (DCMTK_DEFAULT_DICT EQUAL "none")
message(WARNING "Denotes whether DCMTK will use built-in (compiled-in), external (file), or no default dictionary on startup")
endif()

# Per default, we allow users to load user-defined dictionaries pointed to via
# environment variable DCMDICTPATH.
option(DCMTK_USE_DCMDICTPATH "Enable reading dictionary that is defined through DCMDICTPATH environment variable." ON)


# Mark various settings as "advanced"
mark_as_advanced(DCMTK_USE_DCMDICTPATH)
mark_as_advanced(CMAKE_DEBUG_POSTFIX)
mark_as_advanced(FORCE EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)
mark_as_advanced(SNDFILE_DIR DCMTK_WITH_SNDFILE) # not yet needed in public DCMTK
Expand Down
12 changes: 8 additions & 4 deletions CMake/osconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@
/* Define the default data dictionary path for the dcmdata library package */
#define DCM_DICT_DEFAULT_PATH "@DCM_DICT_DEFAULT_PATH@"

/* Define if we want a populated builtin dictionary */
#cmakedefine ENABLE_BUILTIN_DICTIONARY "@ENABLE_BUILTIN_DICTIONARY@"
/* Define the type of standard dictionary that we want to use:
0 - Do not load any default dictionary on startup
1 - Load builtin dictionary on startup
2 - Load external (i.e. file-based) dictionary on startup
*/
#define DCM_DICT_DEFAULT @DCM_DICT_DEFAULT@

/* Define if we want load external dictionaries */
#cmakedefine ENABLE_EXTERNAL_DICTIONARY "@ENABLE_EXTERNAL_DICTIONARY@"
/* Define whether dictionaries defined through DCMDICTPATH variable should be loaded */
#cmakedefine DCM_DICT_USE_DCMDICTPATH @DCM_DICT_USE_DCMDICTPATH@

/* Define the environment variable path separator */
#define ENVIRONMENT_PATH_SEPARATOR '@ENVIRONMENT_PATH_SEPARATOR@'
Expand Down
14 changes: 7 additions & 7 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,9 @@ variables are:
Default: OFF.
- CMAKE_BUILD_TYPE: Debug or Release build, default: Release.
- CMAKE_INSTALL_PREFIX: Installation prefix, default: /usr/local.
- DCMTK_ENABLE_BUILTIN_DICTIONARY: Activate the built-in DICOM data
dictionary? Default: ON on Windows, OFF on Linux/Posix.
- DCMTK_DEFAULT_DICT: Activate the builtin, external or no DICOM data
dictionary on DCMTK startup? Default: builtin on Windows, external on
Linux/Posix.
- DCMTK_ENABLE_CXX11: Assume the compiler is C++11 compliant. Default: OFF.
- DCMTK_ENABLE_STL: Replace DCMTK's OFString, OFList, OFVector etc. by
the STL classes std::string, std::list, std::vector etc. Default: OFF.
Expand Down Expand Up @@ -914,12 +915,11 @@ options are:
--disable-threads compile without MT support
--enable-lfs=TYPE compile with LFS support (lfs/lfs64/auto=default)
--disable-lfs compile without LFS support
--enable-default-dict=TYPE enable default dictionary and specify type
(external=default/builtin)
--disable-default-dict disable default dictionary
--enable-private-tags enable private tag dictionary
--disable-private-tags don't enable private tag dictionary (default)
--enable-external-dict enable loading of external dictionary (default)
--disable-external-dict don't load external dictionary
--enable-builtin-dict enable loading of built-in dictionary
--disable-builtin-dict don't load built-in dictionary (default)
--disable-rpath do not hardcode runtime library paths
--enable-charconv=TYPE enable character set conversion support
(libiconv/libicu/stdlibc/auto=default)
Expand Down Expand Up @@ -999,4 +999,4 @@ Have fun.
M. Eichelberg, J. Riesmeier, M. Onken, J. Schlamelcher, P. Arizpe Gomez
DCMTK Development Team, Oldenburg, Germany.

Last revised: 2021-02-25 (Riesmeier)
Last revised: 2021-08-31 (Riesmeier)
102 changes: 58 additions & 44 deletions config/configure
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@ enable_option_checking
enable_debug
enable_threads
enable_lfs
enable_default_dict
enable_dcmdictpath
enable_private_tags
enable_external_dict
enable_builtin_dict
enable_rpath
with_opensslinc
with_openssl
Expand Down Expand Up @@ -1403,12 +1403,14 @@ Optional Features:
--disable-threads compile without MT support
--enable-lfs=TYPE compile with LFS support (lfs/lfs64/auto=default)
--disable-lfs compile without LFS support
--enable-default-dict=TYPE
enable default dictionary and specify type
(external=default/builtin)
--disable-default-dict disable default dictionary
--enable-dcmdictpath enable DCMDICTPATH environment variable (default)
--disable-dcmdictpath disable DCMDICTPATH environment variable
--enable-private-tags enable private tag dictionary
--disable-private-tags don't enable private tag dictionary (default)
--enable-external-dict enable loading of external dictionary (default)
--disable-external-dict don't load external dictionary
--enable-builtin-dict enable loading of built-in dictionary
--disable-builtin-dict don't load built-in dictionary (default)
--disable-rpath do not hardcode runtime library paths
--enable-charconv=TYPE enable character set conversion support
(libiconv/libicu/stdlibc/auto=default)
Expand Down Expand Up @@ -12954,7 +12956,7 @@ if ${ac_cv_check_std_namespace+:} false; then :
else
ac_link_o='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.o $LIBS 1>&5'
cat > conftest.$ac_ext <<EOF
#line 12957 "configure"
#line 12959 "configure"
#include "confdefs.h"
#include <iostream>
Expand Down Expand Up @@ -13220,7 +13222,7 @@ if ${ac_cv_check_std_namespace+:} false; then :
else
ac_link_o='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.o $LIBS 1>&5'
cat > conftest.$ac_ext <<EOF
#line 13223 "configure"
#line 13225 "configure"
#include "confdefs.h"
#include <iostream>
Expand Down Expand Up @@ -13485,7 +13487,7 @@ if ${ac_cv_check_class_template+:} false; then :
else
ac_link_o='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.o $LIBS 1>&5'
cat > conftest.$ac_ext <<EOF
#line 13488 "configure"
#line 13490 "configure"
#include "confdefs.h"
template <class T>
Expand Down Expand Up @@ -13557,7 +13559,7 @@ if ${ac_cv_check_static_template_method+:} false; then :
else
ac_link_o='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.o $LIBS 1>&5'
cat > conftest.$ac_ext <<EOF
#line 13560 "configure"
#line 13562 "configure"
#include "confdefs.h"
void additive(int & i)
Expand Down Expand Up @@ -13629,7 +13631,7 @@ if ${ac_cv_check_function_template+:} false; then :
else
ac_link_o='${CXX-g++} -o conftest $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.o $LIBS 1>&5'
cat > conftest.$ac_ext <<EOF
#line 13632 "configure"
#line 13634 "configure"
#include "confdefs.h"
template <class T>
Expand Down Expand Up @@ -13869,79 +13871,90 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable private tag dictionary" >&5
$as_echo_n "checking whether to enable private tag dictionary... " >&6; }
# Check whether --enable-private-tags was given.
if test "${enable_private_tags+set}" = set; then :
enableval=$enable_private_tags; case "$enableval" in
yes)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define ENABLE_PRIVATE_TAGS /**/" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable default dictionary" >&5
$as_echo_n "checking whether to enable default dictionary... " >&6; }
# Check whether --enable-default-dict was given.
if test "${enable_default_dict+set}" = set; then :
enableval=$enable_default_dict; case "$enableval" in
external|yes)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, type=external" >&5
$as_echo "yes, type=external" >&6; }
$as_echo "#define DCM_DICT_DEFAULT 2" >>confdefs.h
cat >>confdefs.h <<_ACEOF
#define DCM_DICT_DEFAULT_PATH "${DATA_DIR}/dicom.dic:${DATA_DIR}/private.dic"
_ACEOF
;;
builtin)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, type=builtin" >&5
$as_echo "yes, type=builtin" >&6; }
$as_echo "#define DCM_DICT_DEFAULT 1" >>confdefs.h
;;
*)
no)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
$as_echo "#define DCM_DICT_DEFAULT 0" >>confdefs.h
;;
esac
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define DCM_DICT_DEFAULT 2" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable loading external dictionary from default path" >&5
$as_echo_n "checking whether to enable loading external dictionary from default path... " >&6; }
# Check whether --enable-external-dict was given.
if test "${enable_external_dict+set}" = set; then :
enableval=$enable_external_dict; case "$enableval" in
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to evaluate DCMDICTPATH environment variable" >&5
$as_echo_n "checking whether to evaluate DCMDICTPATH environment variable... " >&6; }
# Check whether --enable-dcmdictpath was given.
if test "${enable_dcmdictpath+set}" = set; then :
enableval=$enable_dcmdictpath; case "$enableval" in
yes)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define ENABLE_EXTERNAL_DICTIONARY /**/" >>confdefs.h
$as_echo "#define DCM_DICT_USE_DCMDICTPATH 1" >>confdefs.h
;;
*)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
cat >>confdefs.h <<_ACEOF
#define DCM_DICT_DEFAULT_PATH ""
_ACEOF
;;
esac
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define ENABLE_EXTERNAL_DICTIONARY /**/" >>confdefs.h
$as_echo "#define DCM_DICT_USE_DCMDICTPATH 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable built-in dictionary loading" >&5
$as_echo_n "checking whether to enable built-in dictionary loading... " >&6; }
# Check whether --enable-builtin-dict was given.
if test "${enable_builtin_dict+set}" = set; then :
enableval=$enable_builtin_dict; case "$enableval" in
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable private tag dictionary" >&5
$as_echo_n "checking whether to enable private tag dictionary... " >&6; }
# Check whether --enable-private-tags was given.
if test "${enable_private_tags+set}" = set; then :
enableval=$enable_private_tags; case "$enableval" in
yes)
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
$as_echo "#define ENABLE_BUILTIN_DICTIONARY /**/" >>confdefs.h
$as_echo "#define ENABLE_PRIVATE_TAGS 1" >>confdefs.h
cat >>confdefs.h <<_ACEOF
#define DCM_DICT_DEFAULT_PATH "${DATA_DIR}/dicom.dic:${DATA_DIR}/private.dic"
_ACEOF
;;
*)
Expand All @@ -13958,6 +13971,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -Wl,-rpath is supported" >&5
$as_echo_n "checking whether -Wl,-rpath is supported... " >&6; }
if ${dcmtk_cv_rpath_works+:} false; then :
Expand Down
Loading

0 comments on commit 4ab084d

Please sign in to comment.