Page MenuHomePhabricator

Use different variable to work around DCMTK config mode problems
Closed, ResolvedPublic

Assigned To
Authored By
espak
Nov 18 2015, 8:42 PM
Referenced Files
F25194: ep.patch
Nov 18 2016, 3:06 PM
F25189: ep.patch
Nov 18 2016, 3:04 PM

Description

TL;DR

Pull request follows. :)

MITKConfig uses module mode to find DCMTK. So that the module finds DCMTK, the DCMTK_DIR variable has to be set to the root of the DCMTK install directory. However, at other places config mode is used, and config mode overwrites DCMTK_DIR to point it to the directory that contains DCMTKConfig.cmake (.../share/dcmtk).

As a workaround, MITKConfig.cmake uses a helper variable, '_dcmtk_dir_original' that is supposed to point to the DCMTK root directory, and sets DCMTK_DIR to this value before using the module mode.

_dcmtk_dir_original is propagated with the value of DCMTK_DIR when MITK is configured. This results in the awkward situation that when we first build MITK, everything is fine, MITKConfig.cmake has the correct DCMTK_DIR. However, when we reconfigure MITK again, the value changes to .../share/dcmtk, and the configuration of our external application fails.

You guys probably did not encounter this problem because DCMTK is installed in the EP install folder, and this is handled as a special case in MITKConfig.cmake. We, however, build DCMTK somewhere else.

So, the workaround is to use another variable to restore the DCMTK root folder, not DCMTK_DIR because that gets overwritten, and messes up everything.

Event Timeline

Doesn't work out of the box (anymore?). I wasn't able to configure MITK when I built the superbuild with an external DCMTK. DCMTK_ROOT was empty on the MITK level and DCMTK_DIR was set to NOTFOUND.

kislinsk triaged this task as Normal priority.Aug 10 2016, 3:41 AM

It doesn't work. Removing all the special DCMTK CMake handling including the custom FIndDCMTK worked for me. CMake ships a working FindDCMTK.

kislinsk edited projects, added MITK (2016-11); removed MITK.

It was not working that time (v2015.05.2) because of the reason I detailed above. I did not try it again with the current master.

@weihs

Which version of CMake has a good FindDCMTK.cmake? Or which version you use?
Do you also have an external application based on MITK?

If FindDCMTK.cmake can be removed from the MITK sources that is good, because it is simpler, but I do not think that it resolves the problem. I think, the problem was not not in FindDCMTK.cmake but in DCMTKConfig.cmake (in the DCMTK install folder) that overwrote the DCMTK_DIR variable.

If you upgraded DCMTK since 2015.05.2 then the new version may provide a good DCMTKConfig.cmake. Then, the best would be to use config mode everywhere.

Sorry, my last comment was not on your new patch.

I see that the master has a new patched version of DCMTK, 3.6.1_20160216, while v2015.05.2 had 3.6.1_20121102. I think, if it installs a correct DCMTKConfig.cmake then your change is good because it simplifies things, but it does not really address the original problem as such.

The error came not in the MITK build, that went fine. The problem was that the DCMTK_DIR in the generated MITKConfig.cmake was incorrect, and it caused problem when configuring an external application based on MITK.

But I will give it a try anyway and let you know how it goes.

I cannot really test it, since we use a snapshot of mitk which is a few months old now. But I compared the diffs and it's nearly the same. I left behind a

if(MITK_USE_DCMTK)
find_package(DCMTK REQUIRED)
endif()

in MITKConfig.cmake.in and CMakeLists.txt. Not sure if that's necessary though.

I tried this with at least CMake 3.6 and 3.7 and DCMTK-3.6.1_20161102, DCMTK-3.6.1_20160630 and DCMTK-3.6.1_20160216. And yes, we use MITK as external dependency.

And just to mention it, I have pretty much the same problems with Eigen and boost. If I build those libraries separately and tell the MITK superbuild to use them as external projects instead of building them again, the MITK-build fails to find Eigen and our application fails to find Eigen and boost. I attached a patch which works for me

. EDIT: wrong patch

Are you sure that this is the right patch? I do not see any reference to boost or eigen.

Yes, MITKConfig.cmake overwrites some boost variables as well, so what we do is that we save the values before finding MITK and then restore the saved values. Something like this:

set(_boost_root ${BOOST_ROOT})
set(_mitk_use_boost ${MITK_USE_Boost})
set(_mitk_use_system_boost ${MITK_USE_SYSTEM_Boost})
set(_mitk_use_boost_libraries ${MITK_USE_Boost_LIBRARIES})
set(_mitk_legacy_export_macro_name ${MITK_LEGACY_EXPORT_MACRO_NAME})

find_package(MITK REQUIRED)
if(MITK_FOUND)
  message("Found MITK")
  set(CMAKE_MODULE_PATH
    ${MITK_SOURCE_DIR}/CMake
    ${CMAKE_MODULE_PATH}
  )
  link_directories(${MITK_LINK_DIRECTORIES})
endif(MITK_FOUND)
    
set(BOOST_ROOT ${_boost_root})
set(MITK_USE_Boost ${_mitk_use_boost})
set(MITK_USE_SYSTEM_Boost ${_mitk_use_system_boost})
set(MITK_USE_Boost_LIBRARIES ${_mitk_use_boost_libraries})
set(MITK_LEGACY_EXPORT_MACRO_NAME ${_mitk_legacy_export_macro_name})

Ya sorry, was the wrong patch. I edited my previous post.