#


MACRO(FIND_INCLUDEPATH CONFIG_PROG CONFIG_ARGS)
  # Set var to empty
  SET(CONFIG_INCLUDE_PATH)
  SET(CONFIG_DEFINITIONS)
  # Execute *config with proper args
  EXEC_PROGRAM(${CONFIG_PROG}
    ARGS ${CONFIG_ARGS}
    OUTPUT_VARIABLE CONFIG_FLAGS)
  #MESSAGE( ${CONFIG_FLAGS} )
  # Parse output of *config execution
  FOREACH(EL ${CONFIG_FLAGS})
    STRING(REGEX MATCHALL "-I([^ ]+)" 
      CONFIG_SEARCH_PATH "${EL}" )
    STRING(REGEX REPLACE "-I" ";" 
      CONFIG_SEARCH_PATH
      ${CONFIG_SEARCH_PATH} )
    SET(CONFIG_INCLUDE_PATH ${CONFIG_SEARCH_PATH} )
    STRING(REGEX MATCHALL "-D([^ ]+)" 
      CONFIG_DEFINITIONS "${EL}" )
    #STRING(REGEX REPLACE "-D" ";" 
    #  CONFIG_DEFINITIONS
    #  ${CONFIG_DEFINITIONS} )
  ENDFOREACH(EL)
ENDMACRO(FIND_INCLUDEPATH)

MACRO(FIND_LIBPATH CONFIG_PROG CONFIG_ARGS)
  SET(CONFIG_LIBRARIES "")
  EXEC_PROGRAM(${CONFIG_PROG}
    ARGS ${CONFIG_ARGS}
    OUTPUT_VARIABLE CONFIG_LIBS )
  # When executing the special case: wx-config --libs --gl-libs
  # a \n appear in the string which create a lots of troubles...
  STRING(REGEX REPLACE "\n" " " CONFIG_LIBS ${CONFIG_LIBS})
  #MESSAGE( "FULL: ${CONFIG_LIBS}" )
  FOREACH(EL ${CONFIG_LIBS})
    #MESSAGE( "EL: ${EL}" )
    STRING(REGEX MATCHALL "-L([^ ]+)" 
      CONFIG_SEARCH_DIR "${EL}" )
    IF(CONFIG_SEARCH_DIR)
      STRING(REGEX REPLACE "-L" ";" 
        CONFIG_SEARCH_DIR
        ${CONFIG_SEARCH_DIR} )
      #MESSAGE(${CONFIG_SEARCH_DIR})
      STRING(REGEX MATCHALL "-l([^ ]+)" 
        CONFIG_LIBRARY "${EL}" )
      STRING(REGEX REPLACE "-l" ";" 
        CONFIG_LIBRARY
        ${CONFIG_LIBRARY} )
      #MESSAGE(${CONFIG_LIBRARY})
      FOREACH(LIB ${CONFIG_LIBRARY})
        #MESSAGE( "${LIB}")
        FIND_LIBRARY(CONFIG_LIB_${LIB}
          NAMES ${LIB}
          PATHS ${CONFIG_SEARCH_DIR} 
            /usr/lib
          )
        #MESSAGE( "${CONFIG_LIB_${LIB}}")
        SET(CONFIG_LIBRARIES 
          "${CONFIG_LIB_${LIB}};${CONFIG_LIBRARIES}")
      ENDFOREACH(LIB)
    ENDIF(CONFIG_SEARCH_DIR)
  ENDFOREACH(EL)
ENDMACRO(FIND_LIBPATH)


#FIND_PROGRAM(CMAKE_CONFIG_CONFIG wx-config ../wx/bin ../../wx/bin)
#SET(CMAKE_CONFIG_CXX_FLAGS "`${CMAKE_CONFIG_CONFIG} --cflags`")
#SET(CONFIGWINDOWS_LIBRARY "`${CMAKE_CONFIG_CONFIG} --libs --gl-libs`")

#ARGS "--libs --gl-libs"
#FIND_LIBPATH( ${CONFIG_CONFIG_LIBS} )
#FIND_INCLUDEPATH( ${CONFIG_CONFIG_FLAGS})



