Skip to content

Commit 8f684b1

Browse files
committed
DOC: find_package component example with itk_generate_factory_registration()
Approach with ITK 6 CMake targets.
1 parent 3374fe4 commit 8f684b1

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

SoftwareGuide/Latex/Introduction/Installation.tex

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,28 +574,75 @@ \section{Using ITK as an External Library}%
574574

575575
\small
576576
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cmake}
577-
set(MINIMUM_ITK_VERSION 5.4)
577+
set(MINIMUM_ITK_VERSION 6.0)
578578
find_package(ITK ${MINIMUM_ITK_VERSION} REQUIRED COMPONENTS Module1 Module2)
579-
include(${ITK_USE_FILE})
579+
580+
add_executable(Example Example.cxx)
581+
target_link_libraries(Example ITK::Module1 ITK::Module2)
580582
\end{minted}
581583
\normalsize
582584
583585
e.g.
584586
585587
\small
586588
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cmake}
587-
set(MINIMUM_ITK_VERSION 5.4)
589+
set(MINIMUM_ITK_VERSION 6.0)
588590
find_package(ITK ${MINIMUM_ITK_VERSION} REQUIRED
589591
COMPONENTS
590592
MorphologicalContourInterpolation
591593
ITKSmoothing
592594
ITKIOImageBase
593595
ITKIONRRD
594596
)
595-
include(${ITK_USE_FILE})
597+
598+
add_executable(Example Example.cxx)
599+
target_link_libraries(Example
600+
ITK::MorphologicalContourInterpolation
601+
ITK::ITKSmoothing
602+
ITK::ITKIOImageBase
603+
ITK::ITKIONRRD
604+
)
605+
# or
606+
target_link_libraries(Example ${ITK_INTERFACE_LIBRARIES})
596607
\end{minted}
597608
\normalsize
598609
610+
ITK uses factory registration to load IO formats and pluggable components at runtime.
611+
ITK 6 uses meta-modules that simplify factory registration by grouping related modules together.
612+
613+
Factory meta-modules include:
614+
615+
\begin{description}
616+
\item[ITKImageIO] All image IO modules (JPEG, PNG, NIFTI, DICOM, etc.).
617+
\item[ITKMeshIO] All mesh IO modules.
618+
\item[ITKTransformIO] Transform IO modules.
619+
\item[ITKFFTImageFilterInit] FFT implementations.
620+
\end{description}
621+
622+
To register all factories:
623+
624+
\small
625+
\begin{minted}[baselinestretch=1,fontsize=\footnotesize,linenos=false,bgcolor=ltgray]{cmake}
626+
set(MINIMUM_ITK_VERSION 6.0)
627+
find_package(ITK ${MINIMUM_ITK_VERSION} REQUIRED
628+
COMPONENTS
629+
MorphologicalContourInterpolation
630+
ITKSmoothing
631+
ITKIOImageBase
632+
ITKIONRRD
633+
)
634+
itk_generate_factory_registration()
635+
636+
add_executable(Example Example.cxx)
637+
target_link_libraries(Example ${ITK_INTERFACE_LIBRARIES} ITK::ITKImageIO)
638+
\end{minted}
639+
\normalsize
640+
641+
The \code{itk\_generate\_factory\_registration()} macro must be called before adding executables.
642+
The CMake macro generates registration code for the IO modules and factory-enabled components from
643+
the modules loaded in \code{find\_package()}. The meta-module must be linked to the target to
644+
include and enable the generated registration code.
645+
599646
If you would like to use the CMake ExternalProject
600647
Module\footnote{\url{https://cmake.org/cmake/help/latest/module/ExternalProject.html}}
601648
to download ITK source code when building your ITK application (a.k.a.

0 commit comments

Comments
 (0)