Debian Codegraph @

cmake_modules/FindIconv.cmake

raw
1 #
2 # Copyright (C) 2010 Michael Bell <[email protected]>
3 # 2015-2016 MariaDB Corporation AB
4 #
5 # Redistribution and use is allowed according to the terms of the New
6 # BSD license.
7 # For details see the COPYING-CMAKE-SCRIPTS file.
8 #
9 # ICONV_EXTERNAL - Iconv is an external library (not libc)
10 # ICONV_FOUND - system has Iconv
11 # ICONV_INCLUDE_DIR - the Iconv include directory
12 # ICONV_LIBRARIES - Link these to use Iconv
13 # ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const
14 # ICONV_VERSION - Iconv version string
15
16 if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
17 # Already in cache, be silent
18 set(ICONV_FIND_QUIETLY TRUE)
19 endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
20
21 find_path(ICONV_INCLUDE_DIR iconv.h)
22
23 IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
24 # There is some libiconv.so in /usr/local that must
25 # be avoided, iconv routines are in libc
26 ELSEIF(APPLE)
27 find_library(ICONV_LIBRARIES NAMES iconv libiconv PATHS
28 /usr/lib/
29 NO_CMAKE_SYSTEM_PATH)
30 SET(ICONV_EXTERNAL TRUE)
31 ELSE()
32 find_library(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2)
33 IF(ICONV_LIBRARIES)
34 SET(ICONV_EXTERNAL TRUE)
35 ENDIF()
36 ENDIF()
37
38 if (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
39 set (ICONV_FOUND TRUE)
40 endif (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
41
42 set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
43 IF(ICONV_EXTERNAL)
44 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
45 ENDIF()
46
47 if (ICONV_FOUND)
48 include(CheckCSourceCompiles)
49 CHECK_C_SOURCE_COMPILES("
50 #include <iconv.h>
51 int main(){
52 iconv_t conv = 0;
53 const char* in = 0;
54 size_t ilen = 0;
55 char* out = 0;
56 size_t olen = 0;
57 iconv(conv, &in, &ilen, &out, &olen);
58 return 0;
59 }
60 " ICONV_SECOND_ARGUMENT_IS_CONST )
61 endif (ICONV_FOUND)
62
63 set (CMAKE_REQUIRED_INCLUDES)
64 set (CMAKE_REQUIRED_LIBRARIES)
65
66 if (ICONV_FOUND)
67 if (NOT ICONV_FIND_QUIETLY)
68 message (STATUS "Found Iconv: ${ICONV_LIBRARIES}")
69 endif (NOT ICONV_FIND_QUIETLY)
70 else (ICONV_FOUND)
71 if (Iconv_FIND_REQUIRED)
72 message (FATAL_ERROR "Could not find Iconv")
73 endif (Iconv_FIND_REQUIRED)
74 endif (ICONV_FOUND)
75
76 MARK_AS_ADVANCED(
77 ICONV_INCLUDE_DIR
78 ICONV_LIBRARIES
79 ICONV_EXTERNAL
80 ICONV_SECOND_ARGUMENT_IS_CONST
81 )