Blame cmake/FindIconv.cmake

Packit Service 50c9f2
# vim:ts=4:sw=4:expandtab:autoindent:
Packit Service 50c9f2
#
Packit Service 50c9f2
# The MIT License
Packit Service 50c9f2
#
Packit Service 50c9f2
# Copyright (c) 2008, 2009 Flusspferd contributors (see "CONTRIBUTORS" or
Packit Service 50c9f2
#                                      http://flusspferd.org/contributors.txt)
Packit Service 50c9f2
#
Packit Service 50c9f2
# Permission is hereby granted, free of charge, to any person obtaining a copy
Packit Service 50c9f2
# of this software and associated documentation files (the "Software"), to deal
Packit Service 50c9f2
# in the Software without restriction, including without limitation the rights
Packit Service 50c9f2
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Packit Service 50c9f2
# copies of the Software, and to permit persons to whom the Software is
Packit Service 50c9f2
# furnished to do so, subject to the following conditions:
Packit Service 50c9f2
#
Packit Service 50c9f2
# The above copyright notice and this permission notice shall be included in
Packit Service 50c9f2
# all copies or substantial portions of the Software.
Packit Service 50c9f2
#
Packit Service 50c9f2
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 50c9f2
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 50c9f2
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit Service 50c9f2
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service 50c9f2
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit Service 50c9f2
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Packit Service 50c9f2
# THE SOFTWARE.
Packit Service 50c9f2
#
Packit Service 50c9f2
Packit Service 50c9f2
Include(CheckFunctionExists)
Packit Service 50c9f2
include(CheckCXXSourceCompiles)
Packit Service 50c9f2
Packit Service 50c9f2
if(ICONV_INCLUDE_DIR)
Packit Service 50c9f2
  set(ICONV_FIND_QUIETLY TRUE)
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
find_path(ICONV_INCLUDE_DIR iconv.h
Packit Service 50c9f2
    HINTS
Packit Service 50c9f2
    ${CMAKE_PREFIX_PATH}
Packit Service 50c9f2
    ${ICONV_DIR}
Packit Service 50c9f2
    $ENV{ICONV_DIR}
Packit Service 50c9f2
    PATH_SUFFIXES include
Packit Service 50c9f2
)
Packit Service 50c9f2
Packit Service 50c9f2
if(NOT ICONV_INCLUDE_DIR STREQUAL "ICONV_INCLUDE_DIR-NOTFOUND")
Packit Service 50c9f2
    set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
Packit Service 50c9f2
    check_function_exists(iconv_open ICONV_IN_GLIBC)
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
if(NOT ICONV_IN_GLIBC)
Packit Service 50c9f2
    if (CMAKE_CL_64)
Packit Service 50c9f2
        find_library(ICONV_LIBRARY
Packit Service 50c9f2
            NAMES iconv64
Packit Service 50c9f2
            HINTS
Packit Service 50c9f2
            ${CMAKE_PREFIX_PATH}
Packit Service 50c9f2
            ${ICONV_DIR}
Packit Service 50c9f2
            $ENV{ICONV_DIR}
Packit Service 50c9f2
            PATH_SUFFIXES lib64 lib
Packit Service 50c9f2
            )
Packit Service 50c9f2
    else()
Packit Service 50c9f2
        find_library(ICONV_LIBRARY
Packit Service 50c9f2
            NAMES iconv
Packit Service 50c9f2
            HINTS
Packit Service 50c9f2
            ${CMAKE_PREFIX_PATH}
Packit Service 50c9f2
            ${ICONV_DIR}
Packit Service 50c9f2
            $ENV{ICONV_DIR}
Packit Service 50c9f2
            PATH_SUFFIXES lib64 lib
Packit Service 50c9f2
            )
Packit Service 50c9f2
    endif()
Packit Service 50c9f2
    set(ICONV_TEST ${ICONV_LIBRARY})
Packit Service 50c9f2
else()
Packit Service 50c9f2
    set(ICONV_TEST "In glibc")
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
Packit Service 50c9f2
set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
Packit Service 50c9f2
Packit Service 50c9f2
if(MSVC_VERSION GREATER 1800)
Packit Service 50c9f2
    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} legacy_stdio_definitions.lib)
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
check_cxx_source_compiles(
Packit Service 50c9f2
    "#include <iconv.h>
Packit Service 50c9f2
     int main() {
Packit Service 50c9f2
        iconv(iconv_t(-1), 0, 0, 0, 0);
Packit Service 50c9f2
     }"
Packit Service 50c9f2
    ICONV_COMPILES)
Packit Service 50c9f2
Packit Service 50c9f2
include(FindPackageHandleStandardArgs)
Packit Service 50c9f2
find_package_handle_standard_args(ICONV DEFAULT_MSG ICONV_TEST ICONV_INCLUDE_DIR ICONV_COMPILES)
Packit Service 50c9f2
Packit Service 50c9f2
if(ICONV_FOUND)
Packit Service 50c9f2
  set(ICONV_LIBRARIES ${ICONV_LIBRARY})
Packit Service 50c9f2
else(ICONV_FOUND)
Packit Service 50c9f2
  set(ICONV_LIBRARIES)
Packit Service 50c9f2
endif(ICONV_FOUND)
Packit Service 50c9f2
Packit Service 50c9f2
if(ICONV_FOUND)
Packit Service 50c9f2
    set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR})
Packit Service 50c9f2
    set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
Packit Service 50c9f2
Packit Service 50c9f2
    if(MSVC_VERSION GREATER 1800)
Packit Service 50c9f2
        set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} legacy_stdio_definitions.lib)
Packit Service 50c9f2
    endif()
Packit Service 50c9f2
Packit Service 50c9f2
    if (NOT DEFINED ICONV_ACCEPTS_NONCONST_INPUT)
Packit Service 50c9f2
        # Display a useful message first time we come through here
Packit Service 50c9f2
        message(STATUS "One (and only one) of the ICONV_ACCEPTS_... tests must pass")
Packit Service 50c9f2
    endif()
Packit Service 50c9f2
    check_cxx_source_compiles(
Packit Service 50c9f2
        "#include <iconv.h>
Packit Service 50c9f2
         int main() {
Packit Service 50c9f2
            char *p = 0;
Packit Service 50c9f2
            iconv(iconv_t(-1), &p, 0, 0, 0);
Packit Service 50c9f2
         }"
Packit Service 50c9f2
        ICONV_ACCEPTS_NONCONST_INPUT)
Packit Service 50c9f2
Packit Service 50c9f2
    check_cxx_source_compiles(
Packit Service 50c9f2
        "#include <iconv.h>
Packit Service 50c9f2
         int main() {
Packit Service 50c9f2
            char const *p = 0;
Packit Service 50c9f2
            iconv(iconv_t(-1), &p, 0, 0, 0);
Packit Service 50c9f2
         }"
Packit Service 50c9f2
        ICONV_ACCEPTS_CONST_INPUT)
Packit Service 50c9f2
Packit Service 50c9f2
    if (ICONV_LIBRARY)
Packit Service 50c9f2
        list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
Packit Service 50c9f2
        list(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
Packit Service 50c9f2
    endif()
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
if(NOT ICONV_ACCEPTS_CONST_INPUT AND NOT ICONV_ACCEPTS_NONCONST_INPUT)
Packit Service 50c9f2
  MESSAGE(FATAL_ERROR "Unable to determine iconv() signature")
Packit Service 50c9f2
elseif(ICONV_ACCEPTS_CONST_INPUT AND ICONV_ACCEPTS_NONCONST_INPUT)
Packit Service 50c9f2
  MESSAGE(FATAL_ERROR "Unable to determine iconv() signature - both test cases passed!")
Packit Service 50c9f2
endif()
Packit Service 50c9f2
Packit Service 50c9f2
mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR)