[Insight-users] How to separate the ITK Applicaitons?

Luis Ibanez luis . ibanez at kitware . com
Wed, 30 Jul 2003 08:43:58 -0400


Hi Hon,

In order to separate the Applications in independent projects
you should first separate the common libraries they use.

For example, most of the applications are using the classes in
Auxiliary/FltkImageViewer, some others use the files in
Auxiliary/vtkFLTK,... and so on.

You could separate these libraries by adding the FIND_PACKAGE
command lines for the packages they depend on.

For example, in the CMakeLists.txt of FLTKImageViewer you should
add:

> FIND_PACKAGE(ITK)
> IF(ITK_FOUND)
>   INCLUDE(${ITK_USE_FILE})
> ELSE(ITK_FOUND)
>   MESSAGE(FATAL_ERROR
>           "Cannot build InsightApplications without ITK.  Please set ITK_DIR.")
> ENDIF(ITK_FOUND)
> 


and

>  FIND_PACKAGE(FLTK)
>   IF(FLTK_FOUND)
>     INCLUDE_DIRECTORIES(${FLTK_INCLUDE_DIR})
>   ENDIF(FLTK_FOUND)


Once you build this libraries, you could take one of the
applications, for example the GaussianFilter, and add to its
CMakeLists.txt file the same lines for finding packages ITK
and FLTK.  In addition to that you will have to add commands
for indicating where to find the FltkImageViewer library that
you just created. And easy way to do so could be:

>  FIND_LIBRARY(FLTK_IMAGE_VIEWER_LIBRARY  NAMES FltkImageViewer
>            PATHS /usr/lib /usr/local/lib
>            /usr/local/fltk/lib
>            /usr/X11R6/lib 
>       )
>

The paths indicated after the "PATHS" keyword indicate the
tentative places to look for this library. If CMake doesn't
find the library there, it will be up to you to type the path
when you run the CMake GUI.


The errors that you are getting now, are due to header files
from the FltkImageViewer library that is located in Auxiliary.
Since the isolated project doesn't know what path to search for
these header files, the compiler fails in the process of locating
the headers. By reorganizing the CMakeLists.txt files as described
above you should be able to get around this problem.



Regards,


  Luis


---------------------------
Hon-Cheng Wong wrote:
> Dear Luis and all ITK users,
> 
>          I have compiled the ITK Applications successfully, however, I 
> want to separate
> 
> each application, for example, GaussianFilter from the whole ITK 
> Applications. Then it
> 
> will be an independent project (has its own *.dsw instead of the 
> ITKApplications.dsw).
> 
> Making each application can be compiled independently, I have tried to 
> edit the
> 
> CMakeList.txt to do my task, however, I haven¡¦t succeeded. I got the 
> following wrong
> 
> message:
> 
>  
> 
> --------------------Configuration: GaussianFilter - Win32 
> Release--------------------
> 
> Building Custom Rule "D:\ITK Research\GaussianFilter\liFilterConsoleGUI.fl"
> 
> Compiling...
> 
> GaussianFilter.cxx
> 
> D:\ITK Research\GaussianFilter\liFilterConsole.h(20) : fatal error 
> C1083: Cannot open
> 
> include file: 'fltkImageViewer.h': No such file or directory 
> liFilterConsole.cxx
> 
> D:\ITK Research\GaussianFilter\liFilterConsole.h(20) : fatal error 
> C1083: Cannot open
> 
> include file: 'fltkImageViewer.h': No such file or directory 
> liFilterConsoleBase.cxx
> 
> liFilterConsoleGUI.cxx
> 
> D:/ITK Research/GaussianFilter/liFilterConsoleGUI.h(8) : fatal error 
> C1083: Cannot open
> 
> include file: 'fltkLightButton.h': No such file or directory
> 
> Generating Code...
> 
> Error executing cl.exe.
> 
>  
> 
> GaussianFilter.exe - 3 error(s), 0 warning(s)
> 
>  
> 
> And here is my CMakeList.txt
> 
>  
> 
> # This project is intended to be built outside the Insight source tree
> 
> PROJECT(GAUSSIANFILTER)
> 
>  
> 
> # Find ITK.
> 
> FIND_PACKAGE(ITK)
> 
> IF(ITK_FOUND)
> 
>   INCLUDE(${ITK_USE_FILE})
> 
> ELSE(ITK_FOUND)
> 
>   MESSAGE(FATAL_ERROR
> 
>           "Cannot build without ITK.  Please set ITK_DIR.")
> 
> ENDIF(ITK_FOUND)
> 
>  
> 
> # Determine what packages are available
> 
> # Add an option to use or not use VTK
> 
> OPTION(USE_VTK "Use VTK (The Visualization Toolkit) (some applications 
> need this)" OFF)
> 
> IF(USE_VTK)
> 
>   FIND_PACKAGE(VTK)
> 
>   IF (VTK_FOUND)
> 
>     INCLUDE (${VTK_USE_FILE})
> 
>  
> 
>     # Test for VTK using std libs
> 
>     IF(NOT VTK_USE_ANSI_STDLIB)
> 
>       MESSAGE("Warning.  Your VTK was not built with the 
> VTK_USE_ANSI_STDLIB "
> 
>               "option ON.  Link errors may occur.  Consider re-building 
> VTK "
> 
>               "with this option ON.  For MSVC 6, you MUST turn on the VTK "
> 
>               "option.  ITK will not link otherwise.")
> 
>     ENDIF(NOT VTK_USE_ANSI_STDLIB)
> 
>  
> 
>     # Test for VTK building Hybrid
> 
>     IF(NOT VTK_USE_HYBRID)
> 
>       MESSAGE("Your VTK was not built with the VTK_USE_HYBRID option ON.  "
> 
>               "Please reconfigure and recompile VTK with this option 
> before "
> 
>               "trying to use it with ITK.")
> 
>       SET(VTK_FOUND 0)
> 
>     ENDIF(NOT VTK_USE_HYBRID)
> 
>   ENDIF (VTK_FOUND)
> 
> ENDIF(USE_VTK)
> 
>  
> 
> # Look for OpenGL.
> 
> FIND_PACKAGE(OpenGL)
> 
>  
> 
> IF(OPENGL_INCLUDE_PATH)
> 
>   INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_PATH})
> 
> ENDIF(OPENGL_INCLUDE_PATH)
> 
>  
> 
> # Add an option to use or not use FLTK (http://www . fltk . org)
> 
> OPTION(USE_FLTK "Use FLTK (The Fast Light Toolkit) for GUI (some 
> applications need this)" OFF)
> 
> IF(USE_FLTK)
> 
>   FIND_PACKAGE(FLTK)
> 
>   IF(FLTK_FOUND)
> 
>     INCLUDE_DIRECTORIES(${FLTK_INCLUDE_DIR})
> 
>   ENDIF(FLTK_FOUND)
> 
> ENDIF(USE_FLTK)
> 
>  
> 
> # Applications requiring MetaImages and Fltk GUI
> 
> IF(FLTK_FOUND)
> 
>   IF(WIN32)
> 
>     ADD_DEFINITIONS(-DWIN32)
> 
>   ENDIF(WIN32)
> 
>   #SUBDIRS(OperatingRoom)
> 
>   IF(VTK_FOUND)
> 
> ENDIF(VTK_FOUND)
> 
> ENDIF(FLTK_FOUND)
> 
>  
> 
> INCLUDE_DIRECTORIES(
> 
>   ${InsightApplications_SOURCE_DIR}/Auxiliary/FltkImageViewer
> 
>   ${InsightApplications_BINARY_DIR}/Auxiliary/FltkImageViewer
> 
>   ${InsightApplications_SOURCE_DIR}/GaussianFilter
> 
>   ${InsightApplications_BINARY_DIR}/GaussianFilter
> 
> )
> 
>  
> 
> ADD_EXECUTABLE(GaussianFilter liFilterConsole.cxx
> 
>                liFilterConsoleBase.cxx GaussianFilter.cxx)
> 
> ADD_EXECUTABLE(GaussianFilter2D liFilterConsole2D.cxx
> 
>                liFilterConsole2DBase.cxx GaussianFilter2D.cxx)
> 
>  
> 
> FLTK_WRAP_UI(GaussianFilter liFilterConsoleGUI.fl)
> 
> FLTK_WRAP_UI(GaussianFilter2D liFilterConsole2DGUI.fl)
> 
>  
> 
> TARGET_LINK_LIBRARIES(GaussianFilter ITKFltkImageViewer ITKIO 
> ITKBasicFilters)
> 
> TARGET_LINK_LIBRARIES(GaussianFilter2D ITKFltkImageViewer ITKIO 
> ITKBasicFilters)
> 
>  
> 
> Could you tell me what¡¦s wrong in my CMakeList.txt?
> 
>  
> 
> Thank you very much in advance!!
> 
>  
> 
> Regards,
> 
> Hugo
> 
>  
> 
> Hon-Cheng Wong, Hugo
> 
> Faculty of Information Technology,
> 
> Macao University of Science and Technology,
> 
> Macao, China
>