Cross-compiling DCMTK with CMake¶
1. Introduction¶
The main challenge when cross-compiling DCMTK is that some of the feature tests performed by CMake require certain small test programs to be compiled and run, which does not work in a cross-compilation setting. Starting with DCMTK 3.6.7, basic support for cross-compilation has been added. This can be enabled by setting the CMake variable DCMTK_NO_TRY_RUN
:
cmake -DDCMTK_NO_TRY_RUN:BOOL=TRUE
In this case, CMake expects all test results that are normally achieved by executing certain test programs to be provided by the user on the command line. In detail, these are the variables that need to be provided:
libiconv related variables¶
The following variables are only used when compiling with libiconv support and can otherwise be set to default values:DCMTK_ICONV_FLAGS_ANALYZED
: should always be set toTRUE
DCMTK_FIXED_ICONV_CONVERSION_FLAGS
: The output printed by the test programconfig/tests/iconv.cc
, when run on the target platform. This value is only used when compiling with old libiconv versions (older than libiconv 1.8) and determines the iconv behaviour when encountering illegal byte sequences during a character set conversion. Possible values are:
"AbortTranscodingOnIllegalSequence"
(use as default)"DiscardIllegalSequences"
DCMTK_STDLIBC_ICONV_HAS_DEFAULT_ENCODING
: true if the test programconfig/tests/lciconv.cc
exits with a return code of zero, false otherwise. This test determines if libiconv has a default encoding, i.e. if@iconv_open()accepts
""@ as an argument. Use FALSE as default.
STL related variables¶
The following variables are only used when compiling withDCMTK_ENABLE_STL
and can otherwise be set to 0:
HAVE_STL_VECTOR_TEST_RESULT
: 1 if the platform provides a working<vector>
implementation, 0 otherwiseHAVE_STL_ALGORITHM_TEST_RESULT
: 1 if the platform provides a working<algorithm>
implementation, 0 otherwiseHAVE_STL_LIMITS_TEST_RESULT
: 1 if the platform provides a working<limits>
implementation, 0 otherwiseHAVE_STL_LIST_TEST_RESULT
: 1 if the platform provides a working<list>
implementation, 0 otherwiseHAVE_STL_MAP_TEST_RESULT
: 1 if the platform provides a working<map>
implementation, 0 otherwiseHAVE_STL_MEMORY_TEST_RESULT
: 1 if the platform provides a working<memory>
implementation, 0 otherwiseHAVE_STL_STACK_TEST_RESULT
: 1 if the platform provides a working<stack>
implementation, 0 otherwiseHAVE_STL_STRING_TEST_RESULT
: 1 if the platform provides a working<string>
implementation, 0 otherwiseHAVE_STL_TYPE_TRAITS_TEST_RESULT
: 1 if the platform provides a working<type_traits>
implementation, 0 otherwiseHAVE_STL_TUPLE_TEST_RESULT
: 1 if the platform provides a working<tuple>
implementation, 0 otherwiseHAVE_STL_SYSTEM_ERROR_TEST_RESULT
: 1 if the platform provides a working<system_error>
implementation, 0 otherwise
Generated file "arith.h"¶
Furthermore, the file "arith.h" must be generated and copied to config/include/dcmtk/config/arith.h
in the build directory. This file can be generated by compiling config/tests/arith.cc
and running the executable on the target platform.
2. Sample Yocto Project for building dcmtk into an ARM64 and x86-64 Linux image¶
DCMTK user Claus Stovgaard has provided a sample project on GitHub (https://github.com/frosteyes/yocto-dcmtk) that shows how to cross-compile DCMTK using the Yocto Project (https://www.yoctoproject.org/), a toolchain for cross-compiling a custom Linux image. The sample project creates Linux images for ARM64 or x86-64 CPUs that include DCMTK and can be run with QEmu. The sample project provides "arith.h" files for a QEmu emulation of ARM64 and x86-64 CPU.