[Cmake] Empty include and library variables

William A. Hoffman billlist at nycap . rr . com
Mon, 20 Oct 2003 14:09:47 -0400


A space is a valid name in cmake, (with spaces in paths it has to be....).
Also, if you refer to a variable that is NOTFOUND or uninitialized in
a LINK or INCLUDE command cmake will warn that you are using a variable that should
have been set.

You may be able to do what you want like this:

SET(MY_INCLUDE_DIRS 
${MEDSLICE_SOURCE_DIR}
  ${CAVE_INCLUDE_DIR}
  ${INVENTOR_INCLUDE_DIR}
  ${COINEVENTS_INCLUDE_DIR}
  ${OPENGL_INCLUDE_DIR})

IF (USE_COIN_EVENTS)
  FIND(...)  # find the include and lib stuff
  SET(MY_INCLUDE_DIRS ${MY_INCLUDE_DIRS} ${COINEVENTS_INCLUDE_DIR})
  SET(MY_LIBS ${MY_LIBS} ${COINEVENTS_LIBRARY})
ENDIF(USE_COIN_EVENTS) 


INCLUDE_DIRECTORIES(${MY_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES (medslice ${MY_LIBS})


At 01:27 PM 10/20/2003, Chris Scharver wrote:
>Hello,
>
>I am trying to conditionally include a certain set of files. I have an OPTION to indicate whether the user needs to set include and library variables. If the option is on, set the variables, otherwise clear them. My current approach doesn't work (CMake 1.8-1 with MSVC6):
>
>OPTION(USE_COIN_EVENTS "Use custom event library." OFF)
>IF (USE_COIN_EVENTS)
>  FIND_PATH( COINEVENTS_INCLUDE_DIR SbTrackerInfo.h ../coinevents
>    DOC "Location for the SbTrackerInfo header.")
>  FIND_LIBRARY( COINEVENTS_LIBRARY coinevents ${COINEVENTS_INCLUDE_DIR})
>ELSE (USE_COIN_EVENTS)
>  SET(COINEVENTS_INCLUDE_DIR " " STRING FORCE)
>  SET(COINEVENTS_LIBRARY " " STRING FORCE)
>ENDIF (USE_COIN_EVENTS)
>
>INCLUDE_DIRECTORIES(
>  ${MEDSLICE_SOURCE_DIR}
>  ${CAVE_INCLUDE_DIR}
>  ${INVENTOR_INCLUDE_DIR}
>  ${COINEVENTS_INCLUDE_DIR}
>  ${OPENGL_INCLUDE_DIR}
>)
>
>...
>
>TARGET_LINK_LIBRARIES (medslice
>  ${CAVE_LIBRARIES}
>  ${INVENTOR_LIBRARIES}
>  ${COINEVENTS_LIBRARY}
>  ${OPENGL_LIBRARIES}
>)
>
>Am I just trying to make things too simple? The idea is that if USE_COIN_EVENTS is off, the variables will contain empty strings, and thus will not be included in the include or library build settings. However, when configuring to build with MSVC6, I get an error that " .lib" cannot be opened for linking. Or do I need to create the variables lists separately? It seems like CMake should detect an empty value and not try to append a new library or include entry.
>
>This event library is conditional on the Inventor library being used, so maybe I should add some other variable that indicates the specific Inventor library type (eg. Coin3D, TGS, SGI) rather than try to control its inclusion manually.
>
>Chris
>--
>Chris Scharver
>Electronic Visualization Laboratory
>The University of Illinois at Chicago
>Ph: 312-996-3002   FAX: 312-413-7585
><http://www . evl . uic . edu/scharver/>
>_______________________________________________
>Cmake mailing list
>Cmake at www . cmake . org
>http://www . cmake . org/mailman/listinfo/cmake