FindICONV.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
  28. if (ICONV_INCLUDE_DIR)
  29. # Already in cache, be silent
  30. set(ICONV_FIND_QUIETLY TRUE)
  31. endif()
  32. find_path(ICONV_INCLUDE_DIR iconv.h
  33. /usr/include
  34. /usr/local/include)
  35. set(POTENTIAL_ICONV_LIBS iconv libiconv libiconv2)
  36. find_library(ICONV_LIBRARY NAMES ${POTENTIAL_ICONV_LIBS}
  37. PATHS /usr/lib /usr/local/lib)
  38. if(WIN32)
  39. set(ICONV_DLL_NAMES iconv.dll libiconv.dll libiconv2.dll)
  40. find_file(ICONV_DLL
  41. NAMES ${ICONV_DLL_NAMES}
  42. PATHS ENV PATH
  43. NO_DEFAULT_PATH)
  44. find_file(ICONV_DLL_HELP
  45. NAMES ${ICONV_DLL_NAMES}
  46. PATHS ENV PATH
  47. ${ICONV_INCLUDE_DIR}/../bin)
  48. if(ICONV_FIND_REQUIRED)
  49. if(NOT ICONV_DLL AND NOT ICONV_DLL_HELP)
  50. message(FATAL_ERROR "Could not find iconv.dll, please add correct your PATH environment variable")
  51. endif()
  52. if(NOT ICONV_DLL AND ICONV_DLL_HELP)
  53. get_filename_component(ICONV_DLL_HELP ${ICONV_DLL_HELP} PATH)
  54. message(STATUS)
  55. message(STATUS "Could not find iconv.dll in standard search path, please add ")
  56. message(STATUS "${ICONV_DLL_HELP}")
  57. message(STATUS "to your PATH environment variable.")
  58. message(STATUS)
  59. message(FATAL_ERROR "exit cmake")
  60. endif()
  61. endif()
  62. if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY AND ICONV_DLL)
  63. set(ICONV_FOUND TRUE)
  64. endif()
  65. else()
  66. include(CheckFunctionExists)
  67. check_function_exists(iconv HAVE_ICONV_IN_LIBC)
  68. if(ICONV_INCLUDE_DIR AND HAVE_ICONV_IN_LIBC)
  69. set(ICONV_FOUND TRUE)
  70. set(ICONV_LIBRARY CACHE TYPE STRING FORCE)
  71. endif()
  72. if(ICONV_INCLUDE_DIR AND ICONV_LIBRARY)
  73. set(ICONV_FOUND TRUE)
  74. endif()
  75. endif()
  76. if(ICONV_FOUND)
  77. if(NOT ICONV_FIND_QUIETLY)
  78. message(STATUS "Found iconv library: ${ICONV_LIBRARY}")
  79. #message(STATUS "Found iconv dll : ${ICONV_DLL}")
  80. endif()
  81. else()
  82. if(ICONV_FIND_REQUIRED)
  83. message(STATUS "Looked for iconv library named ${POTENTIAL_ICONV_LIBS}.")
  84. message(STATUS "Found no acceptable iconv library. This is fatal.")
  85. message(STATUS "iconv header: ${ICONV_INCLUDE_DIR}")
  86. message(STATUS "iconv lib : ${ICONV_LIBRARY}")
  87. message(FATAL_ERROR "Could NOT find iconv library")
  88. endif()
  89. endif()
  90. mark_as_advanced(ICONV_LIBRARY ICONV_INCLUDE_DIR)