Blame cmake/modules/FindICONV.cmake

Packit ed3af9
# - Try to find Iconv 
Packit ed3af9
# Once done this will define 
Packit ed3af9
# 
Packit ed3af9
#  ICONV_FOUND - system has Iconv 
Packit ed3af9
#  ICONV_INCLUDE_DIR - the Iconv include directory 
Packit ed3af9
#  ICONV_LIBRARIES - Link these to use Iconv 
Packit ed3af9
#  ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
Packit ed3af9
# 
Packit ed3af9
include(CheckCCompilerFlag)
Packit ed3af9
include(CheckCSourceCompiles)
Packit ed3af9
Packit ed3af9
IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
Packit ed3af9
  # Already in cache, be silent
Packit ed3af9
  SET(ICONV_FIND_QUIETLY TRUE)
Packit ed3af9
ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
Packit ed3af9
Packit ed3af9
FIND_PATH(ICONV_INCLUDE_DIR iconv.h HINTS /sw/include/ PATHS /opt/local) 
Packit ed3af9
 
Packit ed3af9
FIND_LIBRARY(ICONV_LIBRARIES NAMES libiconv_a iconv libiconv c PATHS /opt/local)
Packit ed3af9
 
Packit ed3af9
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
Packit ed3af9
   SET(ICONV_FOUND TRUE) 
Packit ed3af9
ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
Packit ed3af9
Packit ed3af9
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
Packit ed3af9
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
Packit ed3af9
IF(ICONV_FOUND)
Packit ed3af9
  check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR)
Packit ed3af9
  set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
Packit ed3af9
  if(ICONV_HAVE_WERROR)
Packit ed3af9
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
Packit ed3af9
  endif(ICONV_HAVE_WERROR)
Packit ed3af9
  check_c_source_compiles("
Packit ed3af9
  #include <iconv.h>
Packit ed3af9
  int main(){
Packit ed3af9
    iconv_t conv = 0;
Packit ed3af9
    const char* in = 0;
Packit ed3af9
    size_t ilen = 0;
Packit ed3af9
    char* out = 0;
Packit ed3af9
    size_t olen = 0;
Packit ed3af9
    iconv(conv, &in, &ilen, &out, &olen);
Packit ed3af9
    return 0;
Packit ed3af9
  }
Packit ed3af9
" ICONV_SECOND_ARGUMENT_IS_CONST )
Packit ed3af9
  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}")
Packit ed3af9
ENDIF(ICONV_FOUND)
Packit ed3af9
set(CMAKE_REQUIRED_INCLUDES)
Packit ed3af9
set(CMAKE_REQUIRED_LIBRARIES)
Packit ed3af9
Packit ed3af9
IF(ICONV_FOUND) 
Packit ed3af9
  IF(NOT ICONV_FIND_QUIETLY) 
Packit ed3af9
    MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") 
Packit ed3af9
  ENDIF(NOT ICONV_FIND_QUIETLY) 
Packit ed3af9
ELSE(ICONV_FOUND) 
Packit ed3af9
  IF(Iconv_FIND_REQUIRED) 
Packit ed3af9
    MESSAGE(FATAL_ERROR "Could not find Iconv") 
Packit ed3af9
  ENDIF(Iconv_FIND_REQUIRED) 
Packit ed3af9
ENDIF(ICONV_FOUND) 
Packit ed3af9
Packit ed3af9
MARK_AS_ADVANCED(
Packit ed3af9
  ICONV_INCLUDE_DIR
Packit ed3af9
  ICONV_LIBRARIES
Packit ed3af9
  ICONV_SECOND_ARGUMENT_IS_CONST
Packit ed3af9
)