patches to improve cross compilation - please review

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Posts: 1
Joined: Mon, 2021-10-04, 16:28

patches to improve cross compilation - please review

#1 Post by frosteyes » Mon, 2021-10-11, 10:33

I will like to propose 2 patches for improving the cross compilation capability of dcmtk.
First I will just share the link to the patches on github, and next add the background info the patches.

The patches is located here ... le-options

Part of the dcmtk cmake configuration is 5 places of DCMTK_TRY_RUN in CMake/GenerateDCMTKConfigure.cmake.
DCMTK_TRY_RUN ends up calling the the cmake try_run. In practice this means that the cmake configuration before compilation needs to compile some code, run the code and use the output to set some cmake variables. This is only possible if the target where you want to compile the code for is available for running this test code.
In many situation this requirement is not feasible to respect. A common example would be compilation on a development workstation for running on a dedicated medical device. The device could be based on another architecture like ARM64. The other way around is also possible - e.g. developing on a Apple M1, but compilation for x86_64.

You can see the issue if you try to compile the dcmtk like this. Notice setting CMAKE_SYSTEM_NAME sets the CMAKE_CROSSCOMPILING.
mkdir build && cd build && cmake -DCMAKE_SYSTEM_NAME:STRING=Linux ..

It shows the issues for each DCMTK_TRY_RUN.
-- Checking signedness of char
CMake Warning at CMake/dcmtkTryRun.cmake:78 (message):
Emulation for your target platform is not available, please fill in the
required configure test results manually.
Call Stack (most recent call first):
CMake/dcmtkTryRun.cmake:89 (DCMTK_TRY_RUN_CROSS)
CMake/GenerateDCMTKConfigure.cmake:765 (DCMTK_TRY_RUN)
CMake/dcmtkPrepare.cmake:558 (include)
CMakeLists.txt:52 (include)

CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
C_CHAR_SIGNED (advanced)
For details see /home/x/Git/Github/frosteyes/dcmtk/build/TryRunResults.cmake
The solution in the proposed patches is to introduce a boolean variable DCMTK_NO_TRY_RUN:BOOL.
Setting it to true or 1 prevent the DCMTK_TRY_RUN from running and instead asking the user to set the result from running the try_run directly.
This means that the user will set a number of variables already present in the CMAKE system manually instead of relying on the compilation and running of a test program for determining the results.
Default is to be exactly like dcmtk currently is - so adding the patches does not change anything for the default.

The minimum setup for compilation when CMAKE_SYSTEM_NAME is set with the proposed patches is to set the following variables. Notice we only set the results for the 3 cases of TRY_RUN here.
The number 4 TRY_RUN is part of generating an arith.h file. This currently need to be provided of the user after cmake. (Further info about arith.h later).
You can typically get the values for those variables by running the cmake systems once on a equivalent hardware as the final target.

Code: Select all

The last (5 TRY_RUN) is handled by the second patch, and is if you enable STL. So here the setup is if you enable STL you also need to handle all the STL testing result.

Code: Select all

Currently the output from using DCMTK_NO_TRY_RUN regarding arith.h is the following status message.
Be sure to copy arith.h to /home/frosteyes/Golf/FrostEyes/Git/Github/frosteyes/dcmtk/build/config/include/dcmtk/config/arith.h before build
CMake Warning at CMakeLists.txt:78 (message):
Emulation for your target platform is not available, CTest will not be able
to execute the unit tests!
I am working on a patch to provide a default arith.h for some specific platforms, and introduce some new variables for specifying this.
Something like the variable names below. Here the idea is that if DCMTK_NO_TRY_RUN is set, the cmake system do a fatal error if not one of those is specified.
It would still be possible to have a custom setup for a custom platform, but dcmtk would also provide a default for the common platforms (x86_64 and ARM64)
Will try to follow up with an Yocto example when I have time. So for now - please comment on the patches, and the idea about providing some "standard" arith.h" for some common platforms.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest