Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using ITKElastix in another ITK remote module #86

Closed
dzenanz opened this issue Nov 17, 2020 · 17 comments
Closed

Problem using ITKElastix in another ITK remote module #86

dzenanz opened this issue Nov 17, 2020 · 17 comments

Comments

@dzenanz
Copy link
Member

dzenanz commented Nov 17, 2020

I am trying to use ITKElastix from HASI. To accomplish this, I am adding ITKElastix as a remote module to ITK. ITK builds fine, but HASI runs into link errors (cannot find elastix_lib.lib). In an attempt to fix this, I tried adding CMake export code to ITKElastix, but this causes circular dependency of transformix_lib and elastix_lib when trying to generate ITK project from CMake:

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
Running module dependency checks
Enabled BoneEnhancement, requested by Module_BoneEnhancement.
Enabled Cuberille, requested by Module_Cuberille.
Enabled Elastix, requested by Module_Elastix.
Enabled ITKAnisotropicSmoothing, requested by ITK_BUILD_DEFAULT_MODULES.
Enabled ITKAntiAlias, requested by ITK_BUILD_DEFAULT_MODULES.
...
Enabled ITKVtkGlue, requested by Module_ITKVtkGlue.
Enabled ITKWatersheds, requested by ITK_BUILD_DEFAULT_MODULES.
Enabled ITKZLIB, requested by ITK_BUILD_DEFAULT_MODULES.
Elastix_LIBRARIES: elastix_lib;transformix_lib
elx_BINARY_DIR: C:/Dev/ITK-git-2015/_deps/elx-build
Checking for InitOnceExecuteOnce:
Performing Test InitOnceExecuteOnce - Success
Warnings Configuration:
Filter ZLIB is ON
Could NOT find Perl (missing: PERL_EXECUTABLE) 
Configuring done
CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:184 (add_library):
  Target "transformix_lib" links to itself.

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:184 (add_library):
  Target "transformix_lib" links to itself.

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:154 (add_library):
  Target "elastix_lib" links to itself.

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:154 (add_library):
  Target "elastix_lib" links to itself.

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:154 (add_library):
  Target "elastix_lib" links to itself.

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:184 (add_library):
  Target "transformix_lib" links to itself.

Generating done
@dzenanz
Copy link
Member Author

dzenanz commented Nov 17, 2020

Initial and incremental builds seem to behave differently. The only idea I have is to rename ITKElastix from Elastix into something different (ElastixRM?) to reduce confusion and make debugging this easier.

@thewtex
Copy link
Member

thewtex commented Nov 17, 2020

Initial and incremental builds seem to behave differently. The only idea I have is to rename ITKElastix from Elastix into something different (ElastixRM?) to reduce confusion and make debugging this easier.

I am not following the issue. What is the issue, and how does the proposed change help?

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-src/Core/CMakeLists.txt:184 (add_library):
Target "transformix_lib" links to itself.

We may be able to avoid this be specifying the ITK COMPONENTS required in these locations:

find_package(ITK REQUIRED)

https://github.com/SuperElastix/elastix/blob/90122eff6b37a17adc9f5bb3d7bc08608e9c14a6/CMakeLists.txt#L26

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

Now I see what is the problem: there is a true circular dependency. Elastix depends on ITK, and if ITK tries to depend on it via a remote module, the circle of dependence is complete. Just specifying components does not help, because ITKConfig.cmake contains set(ITK_MODULES_ENABLED "ITKDoubleConversion;...;Elastix;...;ITKWatersheds") and later itk_module_config(ITK ${ITK_MODULES_ENABLED}). The first time ITKElastix is enabled the in-source build can complete. But not subsequently.

One way to resolve this is for HASI to not be an ITK remote module, and just be an application which depends on ITK and Elastix (not good). Maybe another is for Elastix to have its own separate build of ITK (bad). The last is to merge ITKElastix into Elastix, so Elastix can behave as a remote module when being built as part of ITK (requires cooperation of Elastix maintainers).

@thewtex
Copy link
Member

thewtex commented Nov 18, 2020

set(ITK_MODULES_ENABLED "ITKDoubleConversion;...;Elastix;...;ITKWatersheds") and later

Right - if COMPONENTS is specified, Elastix will not be included per:

https://github.com/InsightSoftwareConsortium/ITK/blob/71c0bb375a3fcbc909e20e20c57bbfe6a672dd0b/CMake/ITKConfig.cmake.in#L81-L85

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

Specifying components indeed resolves circular dependency when building ITK.

But the link error LINK : fatal error LNK1104: cannot open file 'elastix_lib.lib' in HASI (log below) persists even with CMake export code. elastix_lib.lib does not exists, but C:\Dev\ITK-git-2015\lib\Debug\elastix-5.0.lib does. Maybe we need to do something different from this?

Build started...
1>------ Build started: Project: HASIHeaderTest1, Configuration: Debug x64 ------
2>------ Build started: Project: HASITestDriver, Configuration: Debug x64 ------
3>------ Build started: Project: ITKData, Configuration: Debug x64 ------
4>------ Build started: Project: ClangFormat, Configuration: Debug x64 ------
5>------ Build started: Project: HASIHeaderTestClean, Configuration: Debug x64 ------
6>------ Skipped Build: Project: Continuous, Configuration: Debug x64 ------
6>Project not selected to build for this solution configuration 
7>------ Skipped Build: Project: Experimental, Configuration: Debug x64 ------
7>Project not selected to build for this solution configuration 
8>------ Skipped Build: Project: Nightly, Configuration: Debug x64 ------
8>Project not selected to build for this solution configuration 
9>------ Skipped Build: Project: NightlyMemoryCheck, Configuration: Debug x64 ------
9>Project not selected to build for this solution configuration 
10>------ Skipped Build: Project: RUN_TESTS, Configuration: Debug x64 ------
10>Project not selected to build for this solution configuration 
11>------ Skipped Build: Project: ITKHeaderTests, Configuration: Debug x64 ------
11>Project not selected to build for this solution configuration 
1>LINK : fatal error LNK1104: cannot open file 'elastix_lib.lib'
1>Done building project "HASIHeaderTest1.vcxproj" -- FAILED.
2>LINK : fatal error LNK1104: cannot open file 'elastix_lib.lib'
2>Done building project "HASITestDriver.vcxproj" -- FAILED.
12>------ Skipped Build: Project: INSTALL, Configuration: Debug x64 ------
12>Project not selected to build for this solution configuration 
========== Build: 3 succeeded, 2 failed, 3 up-to-date, 7 skipped ==========

@thewtex
Copy link
Member

thewtex commented Nov 18, 2020

Great!

Does the ElastixTargets.cmake file have the elastix_lib.lib configuration, and does it set its path?

https://github.com/SuperElastix/elastix/blob/4b3ca0b27260e6ca4480a2edf074c6d32be1b8de/ElastixConfig.cmake.in#L15

Is ElastixTarget.cmake getting sourced in the configuration?

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

ElastixTargets.cmake does have elastix_lib target and sets its path as so:

# Import target "elastix_lib" for configuration "Debug"
set_property(TARGET elastix_lib APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(elastix_lib PROPERTIES
  IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  IMPORTED_LOCATION_DEBUG "C:/Dev/ITK-git-2015/lib/Debug/elastix-5.0.lib"
  )

ElastixConfig.cmake has this line: set( ELASTIX_CONFIG_TARGETS_FILE "${Elastix_DIR}/ElastixTargets.cmake" ). Is ElastixTargets.cmake supposed to be referenced by ITK? C:\Dev\ITK-git-2015\lib\cmake\ITK-5.2\Modules\Elastix.cmake has this content:

set(Elastix_LOADED 1)
set(Elastix_ENABLE_SHARED "0")
set(Elastix_DEPENDS "ITKCommon;ITKIOImageBase;ITKImageGrid;ITKImageSources;ITKSmoothing")
set(Elastix_PUBLIC_DEPENDS "ITKCommon;ITKIOImageBase;ITKImageGrid;ITKSmoothing")
set(Elastix_TRANSITIVE_DEPENDS "ITKCommon;ITKIOImageBase;ITKImageGrid;ITKImageSources;ITKSmoothing")
set(Elastix_PRIVATE_DEPENDS "")
set(Elastix_LIBRARIES "elastix_lib;transformix_lib")
set(Elastix_INCLUDE_DIRS "")
set(Elastix_LIBRARY_DIRS "")
set(Elastix_RUNTIME_LIBRARY_DIRS "C:/Dev/ITK-git-2015/bin")
set(Elastix_TARGETS_FILE "")
set(Elastix_FACTORY_NAMES "")

set(Elastix_DIR "C:/Dev/ITK-git-2015/_deps/elx-build")
find_package(Elastix REQUIRED)

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

If I manually change set(Elastix_TARGETS_FILE "") to set(Elastix_TARGETS_FILE "C:/Dev/ITK-git-2015/_deps/elx-build/ElastixTargets.cmake") the build of HASI succeeds.

@thewtex
Copy link
Member

thewtex commented Nov 18, 2020

Is ElastixTargets.cmake supposed to be referenced by ITK?

Yes

The route should be:

  1. ITK module configuration
  2. C:\Dev\ITK-git-2015\lib\cmake\ITK-5.2\Modules\Elastix.cmake
  3. find_package(Elastix REQUIRED)
  4. ElastixConfig.cmake
  5. ElastixTargets.cmake

If I manually change set(Elastix_TARGETS_FILE "") to set(Elastix_TARGETS_FILE "C:/Dev/ITK-git-2015/_deps/elx-build/ElastixTargets.cmake") the build of HASI succeeds.

Can we patch elastix/ElastixConfig.cmake.in to address this?

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

My attempt dzenanz@9f21804 does not work. How would modifying elastix/ElastixConfig.cmake.in affect C:\Dev\ITK-git-2015\lib\cmake\ITK-5.2\Modules\Elastix.cmake?

@dzenanz
Copy link
Member Author

dzenanz commented Nov 18, 2020

Uncommenting

#include(${ELASTIX_USE_FILE})
causes CMake error in ITK:

...
Enabled ITKZLIB, requested by ITK_BUILD_DEFAULT_MODULES.
CMake Error at C:/Dev/ITK-git-2015/_deps/elx-build/UseElastix.cmake:22 (include):
  The file

    C:/Dev/ITK-git-2015/_deps/elx-build/ElastixTargets.cmake

  was generated by the export() command.  It may not be used as the argument
  to the include() command.  Use ALIAS targets instead to refer to targets by
  alternative names.

Call Stack (most recent call first):
  Modules/Remote/Elastix/CMakeLists.txt:64 (include)


Checking for InitOnceExecuteOnce:
...

@thewtex
Copy link
Member

thewtex commented Nov 19, 2020

My attempt dzenanz/ITKElastix@9f21804 does not work. How would modifying elastix/ElastixConfig.cmake.in affect C:\Dev\ITK-git-2015\lib\cmake\ITK-5.2\Modules\Elastix.cmake?

The change needs to be made in upstream elastix.

@dzenanz
Copy link
Member Author

dzenanz commented Nov 19, 2020

CMake Error at C:/Dev/ITK-git-2015/_deps/elx-build/ElastixConfig.cmake:19 (include):
The file

C:/Dev/ITK-git-2015/_deps/elx-build/ElastixTargets.cmake

was generated by the export() command. It may not be used as the argument
to the include() command. Use ALIAS targets instead to refer to targets by
alternative names.

Call Stack (most recent call first):
Modules/Remote/Elastix/CMakeLists.txt:61 (find_package)

@dzenanz
Copy link
Member Author

dzenanz commented Nov 19, 2020

Update: we have a version of the involved software which compiles. I will follow up (this week or next) in respective repositories.

@thewtex
Copy link
Member

thewtex commented Dec 21, 2020

Has this been addressed?

@dzenanz
Copy link
Member Author

dzenanz commented Dec 22, 2020

Partly addressed, partly abandoned.

@dzenanz dzenanz closed this as completed Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants