[Insight-users] Using ITK externally
Brad King
brad.king@kitware.com
Thu, 12 Dec 2002 15:13:41 -0500 (EST)
> However, I installed these files by copying them from where
> the ITK install process
>
> % make install
This is the proper way to install it. Set ITK's CMAKE_INSTALL_PREFIX
cache entry to the prefix you want to use. If you are trying to install
ITK, don't turn on the VTK-specific features (or tell it where to find
VTK). These features are only for testing, and are not part of the
install anyway. This should give you control over CMAKE_INSTALL_PREFIX
for ITK. The reason the VTK one is forced upon ITK is because of a bug in
VTK's UseVTK.cmake file. It has been fixed in the CVS version of VTK.
> 2) The ITK include tree is hierarchical in /usr/local/include
When you include the "${ITK_USE_FILE}" in your project's CMake code, it
will set the include directories to include all of the ones in the
hierarchy. We decided to install them this way in case we decide to
require the kit name when including files in the future. The full list is
also available from ITKConfig.cmake (which is installed in the
prefix/lib/itk directory) in a variable called ITK_INCLUDE_DIRS.
> # Configure ITK
> SET (ITK_DIR /nfs/source/itk) # Tell it where to find ITK source tree
> INCLUDE(${ITK_DIR}/ITKConfig.cmake.in) # Invoke configure
> INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS}) # Set include directories
ITK_DIR should be a cache entry in your project so the user can tell it
where to find ITK. It should point at the prefix/lib/itk directory of the
installation, or at ITK's build tree.
Read Insight/Documentation/InsightStart.pdf from the source tree. It
includes information on how to use ITK from your project. Here is a quick
start if you don't want to use FindITK.cmake:
FIND_PATH(ITK_DIR ITKConfig.cmake)
IF(ITK_DIR)
INCLUDE(${ITK_DIR}/ITKConfig.cmake)
SET(ITK_FOUND 1)
ENDIF(ITK_DIR)
IF(ITK_FOUND)
# Add include/link directories.
INCLUDE(${ITK_USE_FILE})
ENDIF(ITK_FOUND)
# your code here.
ADD_EXECUTABLE(foo foo.cxx)
TARGET_LINK_LIBRARIES(foo ITKCommon)
# ...
> 4) I don't actually see how the statement
>
> INCLUDE(${ITK_DIR}/ITKConfig.cmake.in) # Invoke ITK configure
>
> could ever work, becuase the install location is in the cmake Cache
> file in the binary tree, not anywhere in the source tree.
[snip]
> Perhaps there is something simple I am just failing to understand.
> I hope so :-)
There is: ITKConfig.cmake.in is configured by ITK's build process into
the build tree to a file called ITKConfig.cmake. That is the one that
should be included. There is also a separate copy that is configured and
installed by "make install". This one should be included to use ITK from
the install tree.
> 3) In many of the install include directories, there are files with
> .txx extensions. What are they ? They hold C++ code.
ITK is written largely as class templates. These cannot be pre-compiled,
so it does not make sense to have a ".cxx" file containing the
implementations of the methods of the class template. However, instead of
writing the method implementations inline in the header file (as is done
by STL's headers), we provide the opportunity for a user to simulate
separate compilation by using explicit instantiation of the types needed.
The ".txx" files hold the implementations of the corresponding headers'
class template methods. By default, the headers include them, but the
user can define a macro to prevent this. I can explain in more detail if
you are interested.
-Brad