Skip to content

Commit 2e2d8c6

Browse files
committed
cmake: detect and use libc-provided iconv
While most systems provide a separate iconv library against which applications can link, musl based systems do not provide such a library. Instead, iconv functions are directly included in the C library. As our current CMake module to locate the iconv library only checks whether a library exists somewhere in the typical library directories, we will never build libgit2 with libiconv support on such systems. Extend the iconv module to also search whether libc provides iconv functions, which we do by checking whether the `iconv_open` function exists inside of libc. If this is the case, we will default to use the libc provided one instead of trying to use a separate libiconv. While this changes which iconv we use on systems where both libc and an external libiconv exist, to the best of my knowledge common systems only provide either one or the other. Note that libiconv support in musl is held kind of basic. To quote musl libc's page on functional differences from glibc [1]: The iconv implementation musl is very small and oriented towards being unobtrusive to static link. Its character set/encoding coverage is very strong for its size, but not comprehensive like glibc’s. As we assume iconv to be a lot more capable than what musl provides, some of our tests will fail if using iconv on musl-based platforms. [1]: https://wiki.musl-libc.org/functional-differences-from-glibc.html
1 parent 5b0258a commit 2e2d8c6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cmake/Modules/FindIconv.cmake

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
1212
ENDIF()
1313

1414
FIND_PATH(ICONV_INCLUDE_DIR iconv.h)
15+
CHECK_FUNCTION_EXISTS(iconv_open libc_has_iconv)
1516
FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c)
1617

17-
IF(ICONV_INCLUDE_DIR AND iconv_lib)
18-
SET(ICONV_FOUND TRUE)
19-
ENDIF()
20-
21-
IF(ICONV_FOUND)
22-
# split iconv into -L and -l linker options, so we can set them for pkg-config
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
2328
GET_FILENAME_COMPONENT(iconv_path ${iconv_lib} PATH)
2429
GET_FILENAME_COMPONENT(iconv_name ${iconv_lib} NAME_WE)
2530
STRING(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})

0 commit comments

Comments
 (0)