blob: cf268ea0214da6138afeb9d3225515ed8e0b2ecf [file] [log] [blame]
Pierre Ossmanb232b5f2011-04-28 14:38:04 +00001# From: http://gitorious.org/gammu/mainline/blobs/master/cmake/FindIconv.cmake
2
3# - Try to find Iconv
4# Once done this will define
5#
6# ICONV_FOUND - system has Iconv
7# ICONV_INCLUDE_DIR - the Iconv include directory
8# ICONV_LIBRARIES - Link these to use Iconv
9# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
10#
11include(CheckCCompilerFlag)
12include(CheckCXXSourceCompiles)
13
14IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
15 # Already in cache, be silent
16 SET(ICONV_FIND_QUIETLY TRUE)
17ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
18
19FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
20
21FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c)
22
23IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
24 SET(ICONV_FOUND TRUE)
25ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
26
27set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
28set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
29IF(ICONV_FOUND)
30 check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR)
31 set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
32 if(ICONV_HAVE_WERROR)
33 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
34 endif(ICONV_HAVE_WERROR)
35 check_c_source_compiles("
36 #include <iconv.h>
37 int main(){
38 iconv_t conv = 0;
39 const char* in = 0;
40 size_t ilen = 0;
41 char* out = 0;
42 size_t olen = 0;
43 iconv(conv, &in, &ilen, &out, &olen);
44 return 0;
45 }
46" ICONV_SECOND_ARGUMENT_IS_CONST )
47 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}")
48ENDIF(ICONV_FOUND)
49set(CMAKE_REQUIRED_INCLUDES)
50set(CMAKE_REQUIRED_LIBRARIES)
51
52IF(ICONV_FOUND)
53 IF(NOT ICONV_FIND_QUIETLY)
54 MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
55 ENDIF(NOT ICONV_FIND_QUIETLY)
56ELSE(ICONV_FOUND)
57 IF(Iconv_FIND_REQUIRED)
58 MESSAGE(FATAL_ERROR "Could not find Iconv")
59 ENDIF(Iconv_FIND_REQUIRED)
60ENDIF(ICONV_FOUND)
61
62MARK_AS_ADVANCED(
63 ICONV_INCLUDE_DIR
64 ICONV_LIBRARIES
65 ICONV_SECOND_ARGUMENT_IS_CONST
66)