[CMake] Make a Find"lib" generic

Xavier Larrode Xavier.Larrode at irisa.fr
Mon Sep 18 10:58:44 EDT 2006


Hi all,
 I have done lots of FindPackage (for linux) for Ogre, Cegui, GLADE2 
etc... And i would like to make it generic.
For now, i juste make a "query replace" from libglade-2.0 for instance 
to OGRE and i would like to  make it better.
Here is an example of my code with REGEX wich separate  a  
pkgconfig--cflags and pkgconfig --libs as i want ( variable for incdir, 
libdir, incflags, libflags and libs.)

I know PKGCONFIG is working similarly but it provides  only 4  variables 
and acting strangly with more than one argument to search,  like a 
pkgconfig --cflags OGRE CEGUI CEGUI-OGRE

So the question is, how to provide an argument to an INCLUDE (file) and 
use it

Thanks


-------------- next part --------------
# This module finds cegui-Ogre 
# and determines where the
# include files and libraries are. 
# On Unix/Linux it relies on the output of pkg-config.
##
# This code sets the following variables:
##
# CEGUI_FOUND       = system has cegui-Ogre lib
##
# CEGUI_INCFLAGS   = Cflags used on gcc
##
# CEGUI_INC      = where to find headers 
##
# CEGUI_LIBS     = libs used by cegui-Ogre
##
# CEGUI_LIBFLAGS   = ldflags used on gcc
##
# CEGUI_LIBDIR   = full path(S) to the libraries
##
# Xavier Larrodé 2006
# xlarrode at irisa.fr 
##


IF(WIN32)
  MESSAGE("Not yet implemented for windows")
ENDIF(WIN32)

# --------------------------------------------------------------

IF(UNIX) 
  INCLUDE(UsePkgConfig)
  PKGCONFIG("CEGUI CEGUI-OGRE"
    CEGUI_INCLUDE_DIR CEGUI_LIB_DIR CEGUI_LDFLAGS CEGUI_CFLAGS) 
  SET(CEGUI_LIBDIR_EXTRACT_REGEX "[-][l]([a-zA-Z0-9/._+-]*)")
  SET(CEGUI_LIBS_EXTRACT_REGEX "[-][L]([ a-zA-Z0-9/._+-]*)")

  #add new delimiters % and handle -I /titi and -L /titi 
  STRING(REGEX REPLACE "-L " "-L" CEGUI_LDFLAGS ${CEGUI_LDFLAGS})
  STRING(REGEX REPLACE " " "%" CEGUI_LDFLAGS ${CEGUI_LDFLAGS})
  STRING(REGEX REPLACE "-I " "-I" CEGUI_CFLAGS ${CEGUI_CFLAGS})
  STRING(REGEX REPLACE " " "%" CEGUI_CFLAGS ${CEGUI_CFLAGS})
  #Get CEGUI_LINK Property : LIBFLAGS LIBDIR LIBS 
  ##  LDFLAGS_MINUS_LIB  :   erase -l*
  STRING(REGEX REPLACE "${CEGUI_LIBDIR_EXTRACT_REGEX}" ""
    CEGUI_LDFLAGS_MINUS_LIB "${CEGUI_LDFLAGS}")
  ### AREVI_LIBFLAGS = CEGUI_LDFLAGS_MINUS_LIB MINUS LIBDIR -space
  #erase -L and space
  STRING(REGEX REPLACE "${CEGUI_LIBS_EXTRACT_REGEX}" ""
    CEGUI_LIBFLAGS "${CEGUI_LDFLAGS_MINUS_LIB}")
  STRING(REGEX REPLACE "%" "" CEGUI_LIBFLAGS "${CEGUI_LIBFLAGS}")
  #Handle if there is no libFlags
  IF(CEGUI_LIBFLAGS)
  ELSE(CEGUI_LIBFLAGS)
    SET(CEGUI_LIBFLAGS " ")
  ENDIF(CEGUI_LIBFLAGS)
  ### CEGUI_LIBDIR = CEGUI_LDFLAGS_MINUS_LIB - CEGUI_LIBFLAGS -space
  #erase libFlags - space -L
  STRING(REGEX REPLACE "${CEGUI_LIBFLAGS}" ""
    CEGUI_LIBDIR "${CEGUI_LDFLAGS_MINUS_LIB}")
  STRING(REGEX REPLACE "%" "" CEGUI_LIBDIR "${CEGUI_LIBDIR}")
  STRING(REGEX REPLACE "-L" ";" CEGUI_LIBDIR "${CEGUI_LIBDIR}")
  #add PATH done by pkgconfig
  SET(CEGUI_LIBDIR 
    ${CEGUI_LIBDIR}
    ${CEGUI_LIB_DIR})

  ### CEGUI_LIBS = CEGUI_LDFLAGS - LIBS -libFlags -space -l 
  
  STRING(REGEX REPLACE "${CEGUI_LIBS_EXTRACT_REGEX}" ""
    CEGUI_LIBS "${CEGUI_LDFLAGS}")
  STRING(REGEX REPLACE "${CEGUI_LIBFLAGS}" ""
    CEGUI_LIBS "${CEGUI_LIBS}")
  STRING(REGEX REPLACE "%" "" CEGUI_LIBS "${CEGUI_LIBS}")
  STRING(REGEX REPLACE "-l" ";" CEGUI_LIBS "${CEGUI_LIBS}")

  SET(CEGUI_INCDIR_EXTRACT_REGEX "[-][I]([ a-zA-Z0-9/._+-]*)")
  #extract flags and include dir
  IF("${CEGUI_CFLAGS}" MATCHES "${CEGUI_INCDIR_EXTRACT_REGEX}")
    STRING(REGEX REPLACE "${CEGUI_INCDIR_EXTRACT_REGEX}" ""
      CEGUI_INCFLAGS "${CEGUI_CFLAGS}")
    STRING(REGEX MATCHALL "${CEGUI_INCDIR_EXTRACT_REGEX}"
      CEGUI_INC "${CEGUI_CFLAGS}")
    #carefull space make strnge \
    STRING(REGEX REPLACE "%" " " CEGUI_INC "${CEGUI_INC}")
    STRING(REGEX REPLACE "-I" "" CEGUI_INC "${CEGUI_INC}")
    STRING(REGEX REPLACE "%" " " CEGUI_INCFLAGS "${CEGUI_INCFLAGS}")
  #add PATH done by pkgconfig
  SET(CEGUI_INC 
    ${CEGUI_INC}
    ${CEGUI_INCLUDE_DIR})

  ENDIF("${CEGUI_CFLAGS}" MATCHES "${CEGUI_INCDIR_EXTRACT_REGEX}")

  IF(CEGUI_INC AND CEGUI_LIBS AND CEGUI_LIBDIR)
    SET(CEGUI_FOUND ON)
  ELSE(CEGUI_INC AND CEGUI_LIBS AND CEGUI_LIBDIR)
    MESSAGE("Error Parsing pkg-config CEGUI,")
    MESSAGE("Got  CEGUI_INC : ${CEGUI_INC}") 
    MESSAGE("Got  CEGUI_LIBS : ${CEGUI_LIBS}") 
    MESSAGE("Got  CEGUI_LIBFLAGS : ${CEGUI_LIBFLAGS}") 
    MESSAGE("Got  CEGUI_LIBDIR : ${CEGUI_LIBDIR}") 
  ENDIF(CEGUI_INC AND CEGUI_LIBS AND CEGUI_LIBDIR)


ENDIF(UNIX)
MARK_AS_ADVANCED(
  CEGUI_FOUND
  CEGUI_INCFLAGS
  CEGUI_INC
  CEGUI_LIBS
  CEGUI_LIBDIR
  CEGUI_LIBFLAGS
  )

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Xavier.Larrode.vcf
Type: text/x-vcard
Size: 169 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060918/01f50471/Xavier.Larrode-0001.vcf


More information about the CMake mailing list