FindIconv.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # - Try to find Iconv
  2. # Once done this will define
  3. #
  4. # ICONV_FOUND - system has Iconv
  5. # ICONV_INCLUDE_DIR - the Iconv include directory
  6. # ICONV_LIBRARIES - Link these to use Iconv
  7. # ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
  8. #
  9. include(CheckCXXSourceCompiles)
  10. IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
  11. # Already in cache, be silent
  12. SET(ICONV_FIND_QUIETLY TRUE)
  13. ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
  14. FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
  15. FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
  16. IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
  17. SET(ICONV_FOUND TRUE)
  18. ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
  19. set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
  20. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  21. IF(ICONV_FOUND)
  22. check_cxx_source_compiles("
  23. #include <iconv.h>
  24. int main(){
  25. iconv_t conv = 0;
  26. const char* in = 0;
  27. size_t ilen = 0;
  28. char* out = 0;
  29. size_t olen = 0;
  30. iconv(conv, &in, &ilen, &out, &olen);
  31. return 0;
  32. }
  33. " ICONV_SECOND_ARGUMENT_IS_CONST )
  34. ENDIF(ICONV_FOUND)
  35. set(CMAKE_REQUIRED_INCLUDES)
  36. set(CMAKE_REQUIRED_LIBRARIES)
  37. IF(ICONV_FOUND)
  38. IF(NOT ICONV_FIND_QUIETLY)
  39. MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
  40. ENDIF(NOT ICONV_FIND_QUIETLY)
  41. ELSE(ICONV_FOUND)
  42. IF(Iconv_FIND_REQUIRED)
  43. MESSAGE(FATAL_ERROR "Could not find Iconv")
  44. ENDIF(Iconv_FIND_REQUIRED)
  45. ENDIF(ICONV_FOUND)
  46. MARK_AS_ADVANCED(
  47. ICONV_INCLUDE_DIR
  48. ICONV_LIBRARIES
  49. ICONV_SECOND_ARGUMENT_IS_CONST
  50. )