]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/FindICONV.cmake
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / development / cmake / modules / 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 PATHS
36  /usr/include
37  /usr/local/include)
38         
39 find_file(ICONV_HEADER iconv.h
40         PATHS ${ICONV_INCLUDE_DIR} NO_DEFAULT_PATH)
41
42 set(POTENTIAL_ICONV_LIBS iconv libiconv libiconv2)
43
44
45 find_library(ICONV_LIBRARY NAMES ${POTENTIAL_ICONV_LIBS}
46         PATHS
47         ${ICONV_RELATIVE_TO_LIBINTL}
48         NO_DEFAULT_PATH)
49         
50 find_library(ICONV_LIBRARY NAMES ${POTENTIAL_ICONV_LIBS}
51         PATHS ${SYSTEM_LIB_DIRS} )
52
53 if(WIN32)
54         set(ICONV_DLL_NAMES iconv.dll  libiconv.dll libiconv2.dll)
55         find_file(ICONV_DLL   
56                                         NAMES ${ICONV_DLL_NAMES}
57                                         PATHS ENV PATH
58                                         ${ICONV_INCLUDE_DIR}/../bin)
59         find_file(ICONV_DLL_HELP   
60                                         NAMES ${ICONV_DLL_NAMES}
61                                         PATHS ENV PATH
62                                         ${ICONV_INCLUDE_DIR}/../bin)
63         if(ICONV_FIND_REQUIRED)
64                 if(NOT ICONV_DLL AND NOT ICONV_DLL_HELP)
65                         message(FATAL_ERROR "Could not find iconv.dll, please add correct your PATH environment variable")
66                 endif()
67                 if(NOT ICONV_DLL AND ICONV_DLL_HELP)
68                         get_filename_component(ICONV_DLL_HELP ${ICONV_DLL_HELP} PATH)
69                         message(STATUS)
70                         message(STATUS "Could not find iconv.dll in standard search path, please add ")
71                         message(STATUS "${ICONV_DLL_HELP}")
72                         message(STATUS "to your PATH environment variable.")
73                         message(STATUS)
74                         message(FATAL_ERROR "exit cmake")
75                 endif()
76         endif()
77         if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY AND ICONV_DLL)
78                 set(ICONV_FOUND TRUE)
79         endif()
80 else()
81         include(CheckFunctionExists)
82         check_function_exists(iconv HAVE_ICONV_IN_LIBC)
83         if(ICONV_INCLUDE_DIR AND HAVE_ICONV_IN_LIBC)
84                 set(ICONV_FOUND TRUE)
85                 set(ICONV_LIBRARY  CACHE TYPE STRING FORCE)
86         endif()
87         if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)
88                 set(ICONV_FOUND TRUE)
89         endif()
90 endif()
91
92
93
94 if(ICONV_FOUND)
95    if(NOT ICONV_FIND_QUIETLY)
96       message(STATUS "Found iconv library: ${ICONV_LIBRARY}")
97       #message(STATUS "Found iconv   dll  : ${ICONV_DLL}")
98    endif()
99 else()
100    if(ICONV_FIND_REQUIRED)
101       message(STATUS "Looked for iconv library named ${POTENTIAL_ICONV_LIBS}.")
102       message(STATUS "Found no acceptable iconv library. This is fatal.")
103       message(STATUS "iconv header: ${ICONV_INCLUDE_DIR}")
104       message(STATUS "iconv lib   : ${ICONV_LIBRARY}")
105       message(FATAL_ERROR "Could NOT find iconv library")
106    endif()
107 endif()
108
109 mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR ICONV_DLL ICONV_DLL_HELP)