| 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 |
# workaround the iOS issue where iconv is provided by libc |
| 19 |
# We set it to false to force it add -liconv to the linker flags |
| 20 |
if(CMAKE_SYSTEM_NAME MATCHES "iOS") |
| 21 |
set(libc_has_iconv FALSE) |
| 22 |
endif() |
| 23 |
|
| 24 |
if(ICONV_INCLUDE_DIR AND libc_has_iconv) |
| 25 |
set(ICONV_FOUND TRUE) |
| 26 |
set(ICONV_LIBRARIES "") |
| 27 |
if(NOT ICONV_FIND_QUIETLY) |
| 28 |
message(STATUS "Found Iconv: provided by libc") |
| 29 |
endif(NOT ICONV_FIND_QUIETLY) |
| 30 |
elseif(ICONV_INCLUDE_DIR AND iconv_lib) |
| 31 |
set(ICONV_FOUND TRUE) |
| 32 |
# split iconv into -L and -l linker options, so we can |
| 33 |
# set them for pkg-config |
| 34 |
get_filename_component(iconv_path ${iconv_lib} PATH) |
| 35 |
get_filename_component(iconv_name ${iconv_lib} NAME_WE) |
| 36 |
string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name}) |
| 37 |
set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}") |
| 38 |
|
| 39 |
if(NOT ICONV_FIND_QUIETLY) |
| 40 |
message(STATUS "Found Iconv: ${ICONV_LIBRARIES}") |
| 41 |
endif() |
| 42 |
else() |
| 43 |
if(Iconv_FIND_REQUIRED) |
| 44 |
message(FATAL_ERROR "Could not find Iconv") |
| 45 |
endif(Iconv_FIND_REQUIRED) |
| 46 |
endif() |
| 47 |
|
| 48 |
mark_as_advanced( |
| 49 |
ICONV_INCLUDE_DIR |
| 50 |
ICONV_LIBRARIES |
| 51 |
) |