]> git.proxmox.com Git - libgit2.git/blob - cmake/FindIconv.cmake
New upstream version 1.4.3+dfsg.1
[libgit2.git] / cmake / FindIconv.cmake
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 #
8
9 if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
10 # Already in cache, be silent
11 set(ICONV_FIND_QUIETLY TRUE)
12 endif()
13
14 find_path(ICONV_INCLUDE_DIR iconv.h)
15 check_function_exists(iconv_open libc_has_iconv)
16 find_library(iconv_lib NAMES iconv libiconv libiconv-2 c)
17
18 if(ICONV_INCLUDE_DIR AND libc_has_iconv)
19 set(ICONV_FOUND TRUE)
20 set(ICONV_LIBRARIES "")
21 if(NOT ICONV_FIND_QUIETLY)
22 message(STATUS "Found Iconv: provided by libc")
23 endif(NOT ICONV_FIND_QUIETLY)
24 elseif(ICONV_INCLUDE_DIR AND iconv_lib)
25 set(ICONV_FOUND TRUE)
26 # split iconv into -L and -l linker options, so we can
27 # set them for pkg-config
28 get_filename_component(iconv_path ${iconv_lib} PATH)
29 get_filename_component(iconv_name ${iconv_lib} NAME_WE)
30 string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})
31 set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}")
32
33 if(NOT ICONV_FIND_QUIETLY)
34 message(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
35 endif()
36 else()
37 if(Iconv_FIND_REQUIRED)
38 message(FATAL_ERROR "Could not find Iconv")
39 endif(Iconv_FIND_REQUIRED)
40 endif()
41
42 mark_as_advanced(
43 ICONV_INCLUDE_DIR
44 ICONV_LIBRARIES
45 )