cmake/macros.cmake
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 7182 1089a8a701c3
child 9465 bf1da29c9509
permissions -rw-r--r--
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

src/main/windows/SDL_windows_main.c:137:
cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
     1 macro(SET_OPTION _NAME _DESC)
     2   list(APPEND ALLOPTIONS ${_NAME})
     3   if(${ARGC} EQUAL 3)
     4     set(_DEFLT ${ARGV2})
     5   else()
     6     set(_DEFLT OFF)
     7   endif()
     8   option(${_NAME} ${_DESC} ${_DEFLT})
     9 endmacro()
    10 
    11 macro(DEP_OPTION _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
    12   list(APPEND ALLOPTIONS ${_NAME})
    13   cmake_dependent_option(${_NAME} ${_DESC} ${_DEFLT} ${_DEPTEST} ${_FAILDFLT})
    14 endmacro()
    15 
    16 macro(OPTION_STRING _NAME _DESC _VALUE)
    17   list(APPEND ALLOPTIONS ${_NAME})
    18   set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
    19   set(HAVE_${_NAME} ${_VALUE})
    20 ENDMACRO()
    21 
    22 # Message Output
    23 macro(MESSAGE_WARN _TEXT)
    24   message(STATUS "*** WARNING: ${_TEXT}")
    25 endmacro()
    26 
    27 macro(MESSAGE_ERROR _TEXT)
    28   message(FATAL_ERROR "*** ERROR: ${_TEXT}")
    29 endmacro()
    30 
    31 macro(MESSAGE_BOOL_OPTION _NAME _VALUE)
    32   if(${_VALUE})
    33     message(STATUS "  ${_NAME}:\tON")
    34   else()
    35     message(STATUS "  ${_NAME}:\tOFF")
    36   endif()
    37 endmacro()
    38 
    39 macro(MESSAGE_TESTED_OPTION _NAME)
    40   set(_REQVALUE ${${_NAME}})
    41   set(_PAD " ")
    42   if(${ARGC} EQUAL 2)
    43     set(_PAD ${ARGV1})
    44   endif()
    45   if(NOT HAVE_${_NAME})
    46     set(HAVE_${_NAME} OFF)
    47   elseif("${HAVE_${_NAME}}" MATCHES "1|TRUE|YES|Y")
    48     set(HAVE_${_NAME} ON)
    49   endif()
    50   message(STATUS "  ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_NAME}}")
    51 endmacro()
    52 
    53 macro(LISTTOSTR _LIST _OUTPUT)
    54   if(${ARGC} EQUAL 3)
    55     # prefix for each element
    56     set(_LPREFIX ${ARGV2})
    57   else()
    58     set(_LPREFIX "")
    59   endif()
    60   # Do not use string(REPLACE ";" " ") here to avoid messing up list
    61   # entries
    62   foreach(_ITEM ${${_LIST}})
    63     set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}")
    64   endforeach()
    65 endmacro()
    66 
    67 macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
    68   set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
    69   set(CMAKE_REQUIRED_DEFINITIONS "-ObjC ${PREV_REQUIRED_DEFS}")
    70   CHECK_C_SOURCE_COMPILES(${SOURCE} ${VAR})
    71   set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
    72 endmacro()
    73