OSDN Git Service

2ec389ce2681130b5527e2b02b1b28842f5fc00f
[csp-qt/common_source_project-fm7.git] / source / build-cmake / 3rdparty / FindIconv.cmake
1 # Originally found here:
2 # https://github.com/onyx-intl/cmake_modules/blob/master/FindIconv.cmake
3 #
4 # - Try to find Iconv 
5 # Once done this will define 
6
7 # ICONV_FOUND - system has Iconv 
8 # ICONV_INCLUDE_DIR - the Iconv include directory 
9 # ICONV_LIBRARIES - Link these to use Iconv 
10 # ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
11
12 include(CheckCXXSourceCompiles)
13
14 IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
15   # Already in cache, be silent
16   SET(ICONV_FIND_QUIETLY TRUE)
17 ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
18
19 FIND_PATH(ICONV_INCLUDE_DIR iconv.h) 
20  
21 FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c)
22  
23 IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
24    SET(ICONV_FOUND TRUE) 
25 ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) 
26
27 set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
28 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
29 IF(ICONV_FOUND)
30   check_cxx_source_compiles("
31   #include <iconv.h>
32   int main(){
33     iconv_t conv = 0;
34     const char* in = 0;
35     size_t ilen = 0;
36     char* out = 0;
37     size_t olen = 0;
38     iconv(conv, &in, &ilen, &out, &olen);
39     return 0;
40   }
41 " ICONV_SECOND_ARGUMENT_IS_CONST )
42 ENDIF(ICONV_FOUND)
43 set(CMAKE_REQUIRED_INCLUDES)
44 set(CMAKE_REQUIRED_LIBRARIES)
45
46 IF(ICONV_FOUND) 
47   IF(NOT ICONV_FIND_QUIETLY) 
48     MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") 
49   ENDIF(NOT ICONV_FIND_QUIETLY) 
50 ELSE(ICONV_FOUND) 
51   IF(Iconv_FIND_REQUIRED) 
52     MESSAGE(FATAL_ERROR "Could not find Iconv") 
53   ENDIF(Iconv_FIND_REQUIRED) 
54 ENDIF(ICONV_FOUND)
55
56 MARK_AS_ADVANCED(
57   ICONV_INCLUDE_DIR
58   ICONV_LIBRARIES
59   ICONV_SECOND_ARGUMENT_IS_CONST
60 )