Fix iconv detection and 'const' qualifier.

issue1247
Kevin Zheng 2014-05-25 12:02:02 -05:00 committed by Günther Brammer
parent 582cabf072
commit 7bc06ad652
3 changed files with 84 additions and 12 deletions

View File

@ -750,11 +750,6 @@ endif()
CHECK_INCLUDE_FILE_CXX(natupnp.h HAVE_NATUPNP_H)
CHECK_INCLUDE_FILES_CXX("X11/Xlib.h;X11/extensions/Xrandr.h" HAVE_X11_EXTENSIONS_XRANDR_H)
CHECK_INCLUDE_FILES_CXX("X11/Xlib.h;X11/keysym.h" HAVE_X11_KEYSYM_H)
CHECK_INCLUDE_FILE_CXX(iconv.h HAVE_ICONV)
if(HAVE_ICONV)
SET(ICONV_CONST ON)
endif()
############################################################################
# Locate necessary libraries
@ -808,11 +803,13 @@ include(CheckCXXSymbolExists)
check_cxx_symbol_exists(vasprintf stdio.h HAVE_VASPRINTF)
check_cxx_symbol_exists(__mingw_vasprintf stdio.h HAVE___MINGW_VASPRINTF)
if(HAVE_ICONV)
check_cxx_symbol_exists(iconv iconv.h HAVE_ICONV_WO_LINK)
mark_as_advanced(HAVE_ICONV_WO_LINK)
if(NOT HAVE_ICONV_WO_LINK)
FINDLIB(ICONV_LIBRARY NAMES iconv)
find_package(ICONV)
if(ICONV_FOUND)
set(HAVE_ICONV true)
if(ICONV_IS_CONST)
set(ICONV_CONST "const")
endif()
endif()
@ -1067,7 +1064,7 @@ target_link_libraries(openclonk
${FREETYPE_LIBRARIES}
${PNG_LIBRARIES}
${JPEG_LIBRARIES}
${ICONV_LIBRARY}
${ICONV_LIBRARIES}
${EXECINFO_LIBRARY}
libc4script
libmisc

View File

@ -0,0 +1,75 @@
# - Try to find Iconv
# Once done this will define
#
# ICONV_FOUND - system has Iconv
# ICONV_INCLUDE_DIR - the Iconv include directory
# ICONV_LIBRARIES - Link these to use Iconv
# ICONV_IS_CONST - the second argument for iconv() is const
#
# This was mostly borrowed from Strigi. LyX also has a (quite
# different) FindICONV: the one in LyX does not check
# second_argument_is_const, but seems to have more fleshed-out support
# for WIN32. There may need to be some merging done.
# Tim Holy, 2008-05-07
include(CheckCXXSourceCompiles)
IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
# Already in cache, be silent
SET(ICONV_FIND_QUIETLY TRUE)
ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
FIND_PATH(ICONV_INCLUDE_DIR iconv.h
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/iconv.h
/Developer/SDKs/MacOSX10.5.sdk/usr/include/iconv.h
/usr/include
)
FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv2 c
PATHS
/Developer/SDKs/MacOSX10.4u.sdk/usr/lib
/Developer/SDKs/MacOSX10.5.sdk/usr/lib
/usr/lib
)
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
SET(ICONV_FOUND TRUE)
ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
IF(ICONV_FOUND)
check_cxx_source_compiles("
#include <iconv.h>
int main(){
iconv_t conv = 0;
const char* in = 0;
size_t ilen = 0;
char* out = 0;
size_t olen = 0;
iconv(conv, &in, &ilen, &out, &olen);
return 0;
}
" ICONV_IS_CONST )
ENDIF(ICONV_FOUND)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_LIBRARIES)
IF(ICONV_FOUND)
IF(NOT ICONV_FIND_QUIETLY)
MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
ENDIF(NOT ICONV_FIND_QUIETLY)
ELSE(ICONV_FOUND)
IF(Iconv_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Iconv")
ENDIF(Iconv_FIND_REQUIRED)
ENDIF(ICONV_FOUND)
MARK_AS_ADVANCED(
ICONV_INCLUDE_DIR
ICONV_LIBRARIES
ICONV_IS_CONST
)

View File

@ -124,7 +124,7 @@
#cmakedefine HAVE_X11_KEYSYM_H 1
/* Define as const if the declaration of iconv() needs const. */
#cmakedefine ICONV_CONST
#define ICONV_CONST @ICONV_CONST@
/* compile without debug options */
#cmakedefine NDEBUG 1