Fix
[ryzomcore.git] / CMakeModules / FindIconv.cmake
blobe96fe40543056cff5d3764a0d233be47e5ba217a
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(CheckCCompilerFlag)
10 include(CheckCSourceCompiles)
12 IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
13   # Already in cache, be silent
14   SET(ICONV_FIND_QUIETLY TRUE)
15 ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
17 FIND_PATH(ICONV_INCLUDE_DIR iconv.h HINTS /sw/include/ PATHS /opt/local) 
19 FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c PATHS /opt/local)
21 IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
22    SET(ICONV_FOUND TRUE) 
23 ENDIF() 
25 set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
26 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
27 IF(ICONV_FOUND)
28   check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR)
29   set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
30   if(ICONV_HAVE_WERROR)
31     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
32   ENDIF()
33   check_c_source_compiles("
34   #include <iconv.h>
35   int main(){
36     iconv_t conv = 0;
37     const char* in = 0;
38     size_t ilen = 0;
39     char* out = 0;
40     size_t olen = 0;
41     iconv(conv, &in, &ilen, &out, &olen);
42     return 0;
43   }
44 " ICONV_SECOND_ARGUMENT_IS_CONST )
45   set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}")
46 ENDIF()
47 set(CMAKE_REQUIRED_INCLUDES)
48 set(CMAKE_REQUIRED_LIBRARIES)
50 IF(ICONV_FOUND) 
51   IF(NOT ICONV_FIND_QUIETLY) 
52     MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") 
53   ENDIF() 
54 ELSE() 
55   IF(Iconv_FIND_REQUIRED) 
56     MESSAGE(FATAL_ERROR "Could not find Iconv") 
57   ENDIF() 
58 ENDIF() 
60 MARK_AS_ADVANCED(
61   ICONV_INCLUDE_DIR
62   ICONV_LIBRARIES
63   ICONV_SECOND_ARGUMENT_IS_CONST