Updated addon repository URL and improved debug output on download
[supertux.git] / external / tinygettext / FindICONV.cmake
1 #
2 #  Copyright (c) 2006, Peter Kümmel, <syntheticpp@gmx.net>
3 #
4 #  Redistribution and use in source and binary forms, with or without
5 #  modification, are permitted provided that the following conditions
6 #  are met:
7 #  
8 #  1. Redistributions of source code must retain the copyright
9 #     notice, this list of conditions and the following disclaimer.
10 #  2. Redistributions in binary form must reproduce the copyright
11 #     notice, this list of conditions and the following disclaimer in the
12 #     documentation and/or other materials provided with the distribution.
13 #  3. The name of the author may not be used to endorse or promote products 
14 #     derived from this software without specific prior written permission.
15 #  
16 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 #  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 #  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 #  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 #  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 #  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 #  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #  
27
28 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
29
30 if (ICONV_INCLUDE_DIR)
31   # Already in cache, be silent
32   set(ICONV_FIND_QUIETLY TRUE)
33 endif()
34
35 find_path(ICONV_INCLUDE_DIR iconv.h
36  /usr/include
37  /usr/local/include)
38
39 set(POTENTIAL_ICONV_LIBS iconv libiconv libiconv2)
40
41 find_library(ICONV_LIBRARY NAMES ${POTENTIAL_ICONV_LIBS}
42         PATHS /usr/lib /usr/local/lib)
43
44 if(WIN32)
45         set(ICONV_DLL_NAMES iconv.dll  libiconv.dll libiconv2.dll)
46         find_file(ICONV_DLL   
47                                         NAMES ${ICONV_DLL_NAMES}
48                                         PATHS ENV PATH
49                                         NO_DEFAULT_PATH)
50         find_file(ICONV_DLL_HELP   
51                                         NAMES ${ICONV_DLL_NAMES}
52                                         PATHS ENV PATH
53                                         ${ICONV_INCLUDE_DIR}/../bin)
54         if(ICONV_FIND_REQUIRED)
55                 if(NOT ICONV_DLL AND NOT ICONV_DLL_HELP)
56                         message(FATAL_ERROR "Could not find iconv.dll, please add correct your PATH environment variable")
57                 endif()
58                 if(NOT ICONV_DLL AND ICONV_DLL_HELP)
59                         get_filename_component(ICONV_DLL_HELP ${ICONV_DLL_HELP} PATH)
60                         message(STATUS)
61                         message(STATUS "Could not find iconv.dll in standard search path, please add ")
62                         message(STATUS "${ICONV_DLL_HELP}")
63                         message(STATUS "to your PATH environment variable.")
64                         message(STATUS)
65                         message(FATAL_ERROR "exit cmake")
66                 endif()
67         endif()
68         if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY AND ICONV_DLL)
69                 set(ICONV_FOUND TRUE)
70         endif()
71 else()
72         include(CheckFunctionExists)
73         check_function_exists(iconv HAVE_ICONV_IN_LIBC)
74         if(ICONV_INCLUDE_DIR AND HAVE_ICONV_IN_LIBC)
75                 set(ICONV_FOUND TRUE)
76                 set(ICONV_LIBRARY  CACHE TYPE STRING FORCE)
77         endif()
78         if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)
79                 set(ICONV_FOUND TRUE)
80         endif()
81 endif()
82
83
84
85 if(ICONV_FOUND)
86    if(NOT ICONV_FIND_QUIETLY)
87       message(STATUS "Found iconv library: ${ICONV_LIBRARY}")
88       #message(STATUS "Found iconv   dll  : ${ICONV_DLL}")
89    endif()
90 else()
91    if(ICONV_FIND_REQUIRED)
92       message(STATUS "Looked for iconv library named ${POTENTIAL_ICONV_LIBS}.")
93       message(STATUS "Found no acceptable iconv library. This is fatal.")
94       message(STATUS "iconv header: ${ICONV_INCLUDE_DIR}")
95       message(STATUS "iconv lib   : ${ICONV_LIBRARY}")
96       message(FATAL_ERROR "Could NOT find iconv library")
97    endif()
98 endif()
99
100 mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR)