FindLibIconv.cmake 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# - Try to find LibIconv
# Once done this will define
#
#  LIBICONV_FOUND - system has LibIconv
#  LIBICONV_INCLUDE_DIR - the LibIconv include directory
#  LIBICONV_LIBRARIES - the libraries needed to use LibIconv
#  LIBICONV_DEFINITIONS - Compiler switches required for using LibIconv

if (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)

    # in cache already
    SET(LIBICONV_FOUND TRUE)

else (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)

    IF (NOT WIN32)
        MESSAGE(FATAL_ERROR "Please set this to the correct values!")
        # use pkg-config to get the directories and then use these values
        # in the FIND_PATH() and FIND_LIBRARY() calls
        INCLUDE(UsePkgConfig)
        PKGCONFIG(libiconv-1.9 _LibIconvIncDir _LibIconvLinkDir _LibIconvLinkFlags _LiIconvCflags)
        SET(LIBICONV_DEFINITIONS ${_LibIconvCflags})
    ENDIF (NOT WIN32)

    FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h
      PATHS
     ${_LibIconvIncDir}
      PATH_SUFFIXES libiconv
    )

    FIND_LIBRARY(LIBICONV_LIBRARIES NAMES iconv libiconv
      PATHS
      ${_LibIconvLinkDir}
    )

    if (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)
       set(LIBICONV_FOUND TRUE)
    endif (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)

    if (LIBICONV_FOUND)
      if (NOT LibIconv_FIND_QUIETLY)
        message(STATUS "Found LibIconv: ${LIBICONV_LIBRARIES}")
      endif (NOT LibIconv_FIND_QUIETLY)
    else (LIBICONV_FOUND)
      if (LibIconv_FIND_REQUIRED)
        message(SEND_ERROR "Could NOT find LibIconv")
      endif (LibIconv_FIND_REQUIRED)
    endif (LIBICONV_FOUND)

    MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARIES)

endif (LIBICONV_INCLUDE_DIR AND LIBICONV_LIBRARIES)