Skip to content

Commit 262c3fe

Browse files
committed
Refactored config check of iconv
It was messing since on Darwin, FreeBSD there are two versions of iconv available - 'library' one and 'builtin' one, and they were confused between configuration and building.
1 parent cd9bd48 commit 262c3fe

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ else ( WIN32 )
373373
if ( WITH_EXPAT )
374374
option_menu ( ICONV "compile with iconv support" USE_LIBICONV EXTRA_LIBRARIES )
375375
mark_as_advanced ( WITH_ICONV )
376+
memcfgvalues ( USE_LIBICONV )
376377
endif ( WITH_EXPAT )
377378

378379
# test for MYSQL

cmake/FindICONV.cmake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,40 @@
2828
find_path ( ICONV_INCLUDE_DIRS iconv.h )
2929

3030
include ( helpers )
31-
ac_search_libs ( "iconv;libiconv" "iconv" HAVE_LIBICONV LIBICONV_LIBRARY )
31+
32+
set ( _CHECK_ICONVC "
33+
#include <iconv.h>
34+
#include <stdio.h>
35+
int main()
36+
{
37+
iconv_t pDesc = iconv_open ( \"UTF-16\", \"UTF-8\" );
38+
}" )
39+
40+
41+
get_property ( dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES )
42+
SET (CMAKE_REQUIRED_INCLUDES "${dirs}")
43+
CHECK_CXX_SOURCE_COMPILES ( "${_CHECK_ICONVC}" HAVE_LIBICONV )
44+
45+
if ( NOT HAVE_LIBICONV )
46+
foreach ( LIB iconv libiconv )
47+
UNSET ( _LIB_PATH CACHE )
48+
find_library ( _LIB_PATH NAMES ${LIB} )
49+
SET ( CMAKE_REQUIRED_LIBRARIES "${_LIB_PATH}")
50+
UNSET ( HAVE_LIBICONV CACHE )
51+
CHECK_CXX_SOURCE_COMPILES ( "${_CHECK_ICONVC}" HAVE_LIBICONV )
52+
if ( HAVE_LIBICONV )
53+
message ( STATUS "iconv found as is ${_LIB_PATH}" )
54+
set ( LIBICONV_LIBRARY "${_LIB_PATH}" )
55+
break ()
56+
endif ()
57+
endforeach ( LIB )
58+
endif ()
59+
60+
mark_as_advanced(_LIB_PATH)
3261

3362
if ( HAVE_LIBICONV )
3463
set ( _CHECK_ICONV "#include <iconv.h>
35-
#include <stdio.h>
64+
#include <stdio.h>
3665
3766
int main()
3867
{

0 commit comments

Comments
 (0)