[Cmake] INCLUDE_DIRECTORIES and empty strings

Amitha Perera perera at cs.rpi.edu
Mon Jun 24 16:01:17 EDT 2002


On Mon, Jun 24, 2002 at 03:46:20PM -0400, Sebastien BARRE wrote:
> You can test if your var is empty before trying to "include" it.
> 
> CMake 1.2, 1.4beta and CVS always had the same behaviour regarding 
> OPENGL_INCLUDE_PATH in the FindOpenGL.cmake module: it is not defined for 
> Win32 system.

Fair enough, but IMO Fred's suggestion is still a worthwhile
modification. CMake already skips empty variables in many commands, so
this won't be doing anything unexpected. And including an empty
directory does not make sense in any circumstance, so this feature
will not create future problems. On the other hand, it will simplify
many CMakeLists.txt files, including the one you mentioned for vtk:

> IF (OPENGL_INCLUDE_PATH)
>    INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_PATH})
> ENDIF(OPENGL_INCLUDE_PATH)

would become simply

  INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_PATH})

For vxl, we are trying to get a consistent set of Find*.cmake modules,
so that

   INCLUDE( ${MODULE_PATH}/FindXXX.cmake )

will set HAS_XXX to "yes" if XXX is available and to "no"
otherwise. If XXX is available, then it will additionally set
XXX_INCLUDE_PATH and XXX_LIBRARIES, so that we can do

   INCLUDE( ${MODULE_PATH}/FindXXX.cmake )
   IF(HAS_XXX)
     INCLUDE_DIRECTORIES( ${XXX_INCLUDE_PATH} )
     ...
     TARGET_LINK_LIBRARIES( ${XXX_LIBRARIES} )
   ENDIF(HAS_XXX)

which I think is a pretty clear and straightforward solution, but
doesn't work for empty include directories. The current way, you'd
have to do instead

   INCLUDE( ${MODULE_PATH}/FindXXX.cmake )
   IF(HAS_XXX)
     IF(XXX_INCLUDE_PATH)
       INCLUDE_DIRECTORIES( ${XXX_INCLUDE_PATH} )
     ENDIF(HAS_XXX_INCLUDE_PATH)
     ...
     IF(XXX_LIBRARIES)
       TARGET_LINK_LIBRARIES( ${XXX_LIBRARIES} )
     ENDIF(XXX_LIBRARIES)
   ENDIF(HAS_XXX)

which I think introduces unnecessary clutter.

Amitha.



More information about the CMake mailing list