[Insight-developers] cmake

Stephen R. Aylward aylward@unc.edu
Wed, 25 Sep 2002 13:15:17 -0400


Hi

That's exactly the question...do we expect someone to try to find ITK 
and then not use it?   If so, then we should keep things as is.   But, 
if we want the default case of Find implying Include to hold, then the 
CMakeLists.txt file for your case would have to become

PROJECT (MyProject)

OPTION(ENABLE_ITK_USE "Enable ITK" FALSE)

IF (ENABLE_ITK_USE)
   INCLUDE (...FindITK.cmake)
   ADD_EXCECUTABLE(...)
   TARGET_LINK_LIBBRARIES(...)
ENDIF (ENABLE_ITK_USE)

and the more common case would be

PROJECT (MyProject)

INCLUDE (...FindITK.cmake)

ADD_EXECUTABLE(...)
TARGET_LINK_LIBRARIES(...) ## do we need this?


Stephen

Bill Hoffman wrote:
> OK, I gave a bad example, what if I want to do this:
> 
> PROJECT (MyProject)
> 
> INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake) 
> 
> # if we can find ITK , then add an option that allows itk 
> # to be enabled.
> IF (USE_ITK_FILE) 
>    OPTION(ENABLE_ITK_USE "Enable ITK " FALSE)
> ENDIF (USE_ITK_FILE)
> 
> IF( ENABLE_ITK_USE AND USE_ITK_FILE)
>    INCLUDE(${USE_ITK_FILE}) 
>    ADD_EXECUTABLE(itkExample main.cxx) 
>    TARGET_LINK_LIBRARIES(itkExample ITKIO ITKNumerics)
> ENDIF( ENABLE_ITK_USE AND USE_ITK_FILE)
> 
> 
> The point is Find should only Find, and give the user the flexibility
> to decide if they want to change the include flags or not.
> 
> As more projects start using CMake, I think this will be a good standard to
> follow.  
> 
> 
> -Bill
> 
> 
> 
> 
> At 12:12 PM 9/25/2002 -0400, Miller, James V (Research) wrote:
> 
>>Wouldn't it make sense for the 
>>
>>IF (USE_ITK_FILE)
>>  INCLUDE(${USE_ITK_FILE})
>>ENDIF (USE_ITK_FILE)
>>
>>to be at the end of the FindITK.cmake file? 
>>
>>An app would still have the option of doing something like
>>
>>IF (USE_ITK_FILE)
>>   SET (HAS_ITK TRUE)
>>ENDIF (USE_ITK_FILE)
>>
>>if that is what they want to do.
>>
>>
>>
>>
>>
>>>-----Original Message-----
>>>From: Bill Hoffman [mailto:bill.hoffman@kitware.com]
>>>Sent: Wednesday, September 25, 2002 11:12 AM
>>>To: Mark Foskey
>>>Cc: Miller, James V (Research); Stephen R. Aylward; Insight-Developers
>>>(E-mail)
>>>Subject: Re: [Insight-developers] cmake
>>>
>>>
>>>I think it is important to separate the Find from the Use.
>>>It makes it much easier to deal with a failed Find.
>>>
>>>
>>>So, you can do things like this:
>>>
>>>IF (USE_ITK_FILE)
>>>  INCLUDE(${USE_ITK_FILE})
>>>  SET(HAS_ITK TRUE)
>>>ENDIF (USE_ITK_FILE)
>>>
>>>IF(HAS_ITK)
>>>...
>>>
>>>-Bill
>>>
>>>
>>>At 11:04 AM 9/25/2002 -0400, Mark Foskey wrote:
>>>
>>>>And, just to make sure I have this straight, Stephen's point 
>>>
>>>was that we ought to be able to arrange things so that the three lines
>>>
>>>>>IF (USE_ITK_FILE)
>>>>>  INCLUDE(${USE_ITK_FILE})
>>>>>ENDIF (USE_ITK_FILE)
>>>>
>>>>are unnecessary, right?
>>>>
>>>>Bill Hoffman wrote:
>>>>
>>>>>Your right, I missed that.
>>>>>It should look like this:
>>>>>PROJECT (MyProject)
>>>>>INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake)
>>>>>IF (USE_ITK_FILE)
>>>>> INCLUDE(${USE_ITK_FILE})
>>>>>ENDIF (USE_ITK_FILE)
>>>>>ADD_EXECUTABLE(MyProject main.cxx)
>>>>>TARGET_LINK_LIBRARIES(MyProject ITKIO ITKNumerics)
>>>>>
>>>>>-Bill
>>>>>At 10:45 AM 9/25/2002 -0400, Miller, James V (Research) wrote:
>>>>>
>>>>>
>>>>>>The include paths and library paths are in UseITK.cmake 
>>>>>
>>>not FindITK.cmake
>>>
>>>>>>
>>>>>>>-----Original Message-----
>>>>>>>From: Bill Hoffman [mailto:bill.hoffman@kitware.com]
>>>>>>>Sent: Wednesday, September 25, 2002 10:39 AM
>>>>>>>To: Stephen R. Aylward; Insight-Developers (E-mail)
>>>>>>>Subject: Re: [Insight-developers] cmake
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>It should add all the include paths and library paths, 
>>>>>>
>>>but not the libraries.
>>>
>>>>>>>The users should specifiy only the libraries directly 
>>>>>>
>>>used by the application.
>>>
>>>>>>>CMake now knows which libraries need each other.  So, the 
>>>>>>
>>>above should work with
>>>
>>>>>>>one added line:
>>>>>>>
>>>>>>>TARGET_LINK_LIBRARIES(MyProject ITKNumerics ITKIO)
>>>>>>>
>>>>>>>(Assuming the project used ITKNumerics and ITKIO directly.   
>>>>>>>Cmake will
>>>>>>>add all the other libraries used by ITKNumerics and ITKIO.)  
>>>>>>>We don't want
>>>>>>>to force folks to link in libraries they are not using.
>>>>>>>
>>>>>>>If the include paths and library path is not being added, 
>>>>>>
>>>I will fix it.
>>>
>>>>>>>-Bill
>>>>>>>
>>>>>>>
>>>>>>>At 10:14 AM 9/25/2002 -0400, Stephen R. Aylward wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>Hi,
>>>>>>>>
>>>>>>>>If someone does a FindITK.cmake, shouldn't we assume that 
>>>>>>>
>>>>>>>they want to include ITK paths and libraries?
>>>>>>>
>>>>>>>
>>>>>>>>There are arguments against this, but perhaps it would be 
>>>>>>>
>>>>>>>nice if the following CMakeLists.txt file was sufficient 
>>>>>>
>>>to compile an ITK program out of source...
>>>
>>>>>>>>PROJECT(MyProject)
>>>>>>>>
>>>>>>>>INCLUDE (${CMAKE_ROOT}/Modules/FindITK.cmake)
>>>>>>>>
>>>>>>>>SET ( MYPROJECT_SRCS
>>>>>>>>main.cxx
>>>>>>>>)
>>>>>>>>
>>>>>>>>ADD_EXECUTABLE( MyProject MYPROJECT_SRCS )
>>>>>>>
>>>>>>>
>>>>>>>_______________________________________________
>>>>>>>Insight-developers mailing list
>>>>>>>Insight-developers@public.kitware.com
>>>>>>>http://public.kitware.com/mailman/listinfo/insight-developers
>>>>>>
>>>>>>_______________________________________________
>>>>>>Insight-developers mailing list
>>>>>>Insight-developers@public.kitware.com
>>>>>>http://public.kitware.com/mailman/listinfo/insight-developers 
>>>>>
>>>>>_______________________________________________
>>>>>Insight-developers mailing list
>>>>>Insight-developers@public.kitware.com
>>>>>http://public.kitware.com/mailman/listinfo/insight-developers
>>>>
>>>>
>>>>-- 
>>>>Mark Foskey    (919) 843-5436  Computer-Aided Diagnosis and 
>>>
>>>Display Lab
>>>
>>>>mark_foskey@unc.edu            Department of Radiology, CB 7515, UNC
>>>>http://www.cs.unc.edu/~foskey  Chapel Hill, NC  27599-7515
>>>
>>_______________________________________________
>>Insight-developers mailing list
>>Insight-developers@public.kitware.com
>>http://public.kitware.com/mailman/listinfo/insight-developers 
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers


-- 
===============================================
Dr. Stephen R. Aylward
Assistant Professor of Radiology
Adjunct Assistant Professor of Computer Science
http://caddlab.rad.unc.edu
aylward@unc.edu
(919) 966-9695