FindIce.cmake 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. #.rst:
  2. # FindIce
  3. # -------
  4. #
  5. # Find the ZeroC Internet Communication Engine (ICE) programs,
  6. # libraries and datafiles.
  7. #
  8. # This module supports multiple components.
  9. # Components can include any of: ``Freeze``, ``Glacier2``, ``Ice``,
  10. # ``IceBox``, ``IceDB``, ``IceGrid``, ``IcePatch``, ``IceSSL``,
  11. # ``IceStorm``, ``IceUtil``, ``IceXML``, or ``Slice``.
  12. #
  13. # This module reports information about the Ice installation in
  14. # several variables. General variables::
  15. #
  16. # Ice_VERSION - Ice release version
  17. # Ice_FOUND - true if the main programs and libraries were found
  18. # Ice_LIBRARIES - component libraries to be linked
  19. # Ice_INCLUDE_DIRS - the directories containing the Ice headers
  20. # Ice_SLICE_DIRS - the directories containing the Ice slice interface
  21. # definitions
  22. #
  23. # Ice programs are reported in::
  24. #
  25. # Ice_SLICE2CPP_EXECUTABLE - path to slice2cpp executable
  26. # Ice_SLICE2CS_EXECUTABLE - path to slice2cs executable
  27. # Ice_SLICE2FREEZEJ_EXECUTABLE - path to slice2freezej executable
  28. # Ice_SLICE2FREEZE_EXECUTABLE - path to slice2freeze executable
  29. # Ice_SLICE2HTML_EXECUTABLE - path to slice2html executable
  30. # Ice_SLICE2JAVA_EXECUTABLE - path to slice2java executable
  31. # Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable
  32. # Ice_SLICE2PY_EXECUTABLE - path to slice2py executable
  33. # Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable
  34. #
  35. # Ice component libraries are reported in::
  36. #
  37. # Ice_<C>_FOUND - ON if component was found
  38. # Ice_<C>_LIBRARIES - libraries for component
  39. #
  40. # Note that ``<C>`` is the uppercased name of the component.
  41. #
  42. # This module reads hints about search results from::
  43. #
  44. # Ice_HOME - the root of the Ice installation
  45. #
  46. # The environment variable :envvar:`ICE_HOME` may also be used; the
  47. # Ice_HOME variable takes precedence.
  48. #
  49. # The following cache variables may also be set::
  50. #
  51. # Ice_<P>_EXECUTABLE - the path to executable <P>
  52. # Ice_INCLUDE_DIR - the directory containing the Ice headers
  53. # Ice_SLICE_DIR - the directory containing the Ice slice interface
  54. # definitions
  55. # Ice_<C>_LIBRARY - the library for component <C>
  56. #
  57. # .. note::
  58. #
  59. # In most cases none of the above variables will require setting,
  60. # unless multiple Ice versions are available and a specific version
  61. # is required. On Windows, the most recent version of Ice will be
  62. # found through the registry. On Unix, the programs, headers and
  63. # libraries will usually be in standard locations, but Ice_SLICE_DIRS
  64. # might not be automatically detected (commonly known locations are
  65. # searched). All the other variables are defaulted using Ice_HOME,
  66. # if set. It's possible to set Ice_HOME and selectively specify
  67. # alternative locations for the other components; this might be
  68. # required for e.g. newer versions of Visual Studio if the
  69. # heuristics are not sufficient to identify the correct programs and
  70. # libraries for the specific Visual Studio version.
  71. #
  72. # Other variables one may set to control this module are::
  73. #
  74. # Ice_DEBUG - Set to ON to enable debug output from FindIce.
  75. # Written by Roger Leigh <[email protected]>
  76. #=============================================================================
  77. # Copyright 2014 University of Dundee
  78. #
  79. # Distributed under the OSI-approved BSD License (the "License");
  80. # see accompanying file Copyright.txt for details.
  81. #
  82. # This software is distributed WITHOUT ANY WARRANTY; without even the
  83. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  84. # See the License for more information.
  85. #=============================================================================
  86. # (To distribute this file outside of CMake, substitute the full
  87. # License text for the above reference.)
  88. # The Ice checks are contained in a function due to the large number
  89. # of temporary variables needed.
  90. function(_Ice_FIND)
  91. # Released versions of Ice, including generic short forms
  92. set(ice_versions
  93. 3
  94. 3.5
  95. 3.5.1
  96. 3.5.0
  97. 3.4
  98. 3.4.2
  99. 3.4.1
  100. 3.4.0
  101. 3.3
  102. 3.3.1
  103. 3.3.0)
  104. # Set up search paths, taking compiler into account. Search Ice_HOME,
  105. # with ICE_HOME in the environment as a fallback if unset.
  106. if(Ice_HOME)
  107. list(APPEND ice_roots "${Ice_HOME}")
  108. else()
  109. if(NOT "$ENV{ICE_HOME}" STREQUAL "")
  110. file(TO_CMAKE_PATH "$ENV{ICE_HOME}" NATIVE_PATH)
  111. list(APPEND ice_roots "${NATIVE_PATH}")
  112. set(Ice_HOME "${NATIVE_PATH}"
  113. CACHE PATH "Location of the Ice installation" FORCE)
  114. endif()
  115. endif()
  116. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  117. # 64-bit path suffix
  118. set(_x64 "/x64")
  119. # 64-bit library directory
  120. set(_lib64 "lib64")
  121. endif()
  122. if(MSVC_VERSION)
  123. # VS 8.0
  124. if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500)
  125. set(vcver "vc80")
  126. set(vcyear "2005")
  127. # VS 9.0
  128. elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600)
  129. set(vcver "vc90")
  130. set(vcyear "2008")
  131. # VS 10.0
  132. elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700)
  133. set(vcver "vc100")
  134. # VS 11.0
  135. elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800)
  136. set(vcver "vc110")
  137. # VS 12.0
  138. elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900)
  139. set(vcver "vc120")
  140. # VS 14.0
  141. elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 2000)
  142. set(vcver "vc140")
  143. endif()
  144. endif()
  145. # For compatibility with ZeroC Windows builds.
  146. if(vcver)
  147. # Earlier Ice (3.3) builds don't use vcnnn subdirectories, but are harmless to check.
  148. list(APPEND ice_binary_suffixes "bin/${vcver}${_x64}" "bin/${vcver}")
  149. list(APPEND ice_library_suffixes "lib/${vcver}${_x64}" "lib/${vcver}")
  150. endif()
  151. # Generic 64-bit and 32-bit directories
  152. list(APPEND ice_binary_suffixes "bin${_x64}" "bin")
  153. list(APPEND ice_library_suffixes "${_lib64}" "lib${_x64}" "lib")
  154. list(APPEND ice_include_suffixes "include")
  155. list(APPEND ice_slice_suffixes "slice")
  156. # On Windows, look in the registry for install locations. Different
  157. # versions of Ice install support different compiler versions.
  158. if(vcver)
  159. foreach(ice_version ${ice_versions})
  160. # Ice 3.3 releases use a Visual Studio year suffix and value is
  161. # enclosed in double quotes, though only the leading quote is
  162. # returned by get_filename_component.
  163. unset(ice_location)
  164. if(vcyear)
  165. get_filename_component(ice_location
  166. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ZeroC\\Ice ${ice_version} for Visual Studio ${vcyear};InstallDir]"
  167. PATH)
  168. if(ice_location AND NOT ("${ice_location}" STREQUAL "/registry" OR "${ice_location}" STREQUAL "/"))
  169. string(REGEX REPLACE "^\"(.*)\"?$" "\\1" ice_location "${ice_location}")
  170. get_filename_component(ice_location "${ice_location}" ABSOLUTE)
  171. else()
  172. unset(ice_location)
  173. endif()
  174. endif()
  175. # Ice 3.4+ releases don't use a suffix
  176. if(NOT ice_location OR "${ice_location}" STREQUAL "/registry")
  177. get_filename_component(ice_location
  178. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\ZeroC\\Ice ${ice_version};InstallDir]"
  179. ABSOLUTE)
  180. endif()
  181. if(ice_location AND NOT "${ice_location}" STREQUAL "/registry")
  182. list(APPEND ice_roots "${ice_location}")
  183. endif()
  184. endforeach()
  185. else()
  186. foreach(ice_version ${ice_versions})
  187. # Prefer 64-bit variants if present (and using a 64-bit compiler)
  188. list(APPEND ice_roots "/opt/Ice-${ice_version}")
  189. endforeach()
  190. endif()
  191. set(ice_programs
  192. slice2cpp
  193. slice2cs
  194. slice2freezej
  195. slice2freeze
  196. slice2html
  197. slice2java
  198. slice2php
  199. slice2py
  200. slice2rb)
  201. # Find all Ice programs
  202. foreach(program ${ice_programs})
  203. string(TOUPPER "${program}" program_upcase)
  204. set(cache_var "Ice_${program_upcase}_EXECUTABLE")
  205. set(program_var "Ice_${program_upcase}_EXECUTABLE")
  206. find_program("${cache_var}" "${program}"
  207. HINTS ${ice_roots}
  208. PATH_SUFFIXES ${ice_binary_suffixes}
  209. DOC "Ice ${program} executable")
  210. mark_as_advanced(cache_var)
  211. set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
  212. endforeach()
  213. # Get version.
  214. if(Ice_SLICE2CPP_EXECUTABLE)
  215. # Execute in C locale for safety
  216. set(_Ice_SAVED_LC_ALL "$ENV{LC_ALL}")
  217. set(ENV{LC_ALL} C)
  218. execute_process(COMMAND ${Ice_SLICE2CPP_EXECUTABLE} --version
  219. ERROR_VARIABLE Ice_VERSION_SLICE2CPP_FULL
  220. ERROR_STRIP_TRAILING_WHITESPACE)
  221. # restore the previous LC_ALL
  222. set(ENV{LC_ALL} ${_Ice_SAVED_LC_ALL})
  223. # Make short version
  224. string(REGEX REPLACE "^(.*)\\.[^.]*$" "\\1" Ice_VERSION_SLICE2CPP_SHORT "${Ice_VERSION_SLICE2CPP_FULL}")
  225. set(Ice_VERSION "${Ice_VERSION_SLICE2CPP_FULL}" PARENT_SCOPE)
  226. endif()
  227. if(NOT Ice_FIND_QUIETLY)
  228. message(STATUS "Ice version: ${Ice_VERSION_SLICE2CPP_FULL}")
  229. endif()
  230. # Find include directory
  231. find_path(Ice_INCLUDE_DIR
  232. NAMES "Ice/Ice.h"
  233. HINTS ${ice_roots}
  234. PATH_SUFFIXES ${ice_include_suffixes}
  235. DOC "Ice include directory")
  236. set(Ice_INCLUDE_DIR "${Ice_INCLUDE_DIR}" PARENT_SCOPE)
  237. # In common use on Linux, MacOS X (homebrew) and FreeBSD; prefer
  238. # version-specific dir
  239. list(APPEND ice_slice_paths
  240. /usr/local/share /usr/share)
  241. list(APPEND ice_slice_suffixes
  242. "Ice-${Ice_VERSION_SLICE2CPP_FULL}/slice"
  243. "Ice-${Ice_VERSION_SLICE2CPP_SHORT}/slice"
  244. Ice)
  245. # Find slice directory
  246. find_path(Ice_SLICE_DIR
  247. NAMES "Ice/Connection.ice"
  248. HINTS ${ice_roots}
  249. ${ice_slice_paths}
  250. PATH_SUFFIXES ${ice_slice_suffixes}
  251. NO_DEFAULT_PATH
  252. DOC "Ice slice directory")
  253. set(Ice_SLICE_DIR "${Ice_SLICE_DIR}" PARENT_SCOPE)
  254. # Find all Ice libraries
  255. set(Ice_REQUIRED_LIBS_FOUND ON)
  256. foreach(component ${Ice_FIND_COMPONENTS})
  257. string(TOUPPER "${component}" component_upcase)
  258. set(component_cache "Ice_${component_upcase}_LIBRARY")
  259. set(component_found "${component_upcase}_FOUND")
  260. find_library("${component_cache}" "${component}"
  261. HINTS ${ice_roots}
  262. PATH_SUFFIXES ${ice_library_suffixes}
  263. DOC "Ice ${component} library")
  264. mark_as_advanced("${component_cache}")
  265. if("${component_cache}")
  266. set("${component_found}" ON)
  267. list(APPEND Ice_LIBRARY "${${component_cache}}")
  268. endif()
  269. mark_as_advanced("${component_found}")
  270. set("${component_cache}" "${${component_cache}}" PARENT_SCOPE)
  271. set("${component_found}" "${${component_found}}" PARENT_SCOPE)
  272. if("${component_found}")
  273. if ("Ice_FIND_REQUIRED_${component}")
  274. list(APPEND Ice_LIBS_FOUND "${component} (required)")
  275. else()
  276. list(APPEND Ice_LIBS_FOUND "${component} (optional)")
  277. endif()
  278. else()
  279. if ("Ice_FIND_REQUIRED_${component}")
  280. set(Ice_REQUIRED_LIBS_FOUND OFF)
  281. list(APPEND Ice_LIBS_NOTFOUND "${component} (required)")
  282. else()
  283. list(APPEND Ice_LIBS_NOTFOUND "${component} (optional)")
  284. endif()
  285. endif()
  286. endforeach()
  287. set(_Ice_REQUIRED_LIBS_FOUND "${Ice_REQUIRED_LIBS_FOUND}" PARENT_SCOPE)
  288. set(Ice_LIBRARY "${Ice_LIBRARY}" PARENT_SCOPE)
  289. if(NOT Ice_FIND_QUIETLY)
  290. if(Ice_LIBS_FOUND)
  291. message(STATUS "Found the following Ice libraries:")
  292. foreach(found ${Ice_LIBS_FOUND})
  293. message(STATUS " ${found}")
  294. endforeach()
  295. endif()
  296. if(Ice_LIBS_NOTFOUND)
  297. message(STATUS "The following Ice libraries were not found:")
  298. foreach(notfound ${Ice_LIBS_NOTFOUND})
  299. message(STATUS " ${notfound}")
  300. endforeach()
  301. endif()
  302. endif()
  303. if(Ice_DEBUG)
  304. message(STATUS "--------FindIce.cmake search debug--------")
  305. message(STATUS "ICE binary path search order: ${ice_roots}")
  306. message(STATUS "ICE include path search order: ${ice_roots}")
  307. message(STATUS "ICE slice path search order: ${ice_roots} ${ice_slice_paths}")
  308. message(STATUS "ICE library path search order: ${ice_roots}")
  309. message(STATUS "----------------")
  310. endif()
  311. endfunction()
  312. _Ice_FIND()
  313. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  314. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ice
  315. FOUND_VAR Ice_FOUND
  316. REQUIRED_VARS Ice_SLICE2CPP_EXECUTABLE
  317. Ice_INCLUDE_DIR
  318. Ice_SLICE_DIR
  319. Ice_LIBRARY
  320. _Ice_REQUIRED_LIBS_FOUND
  321. VERSION_VAR Ice_VERSION
  322. FAIL_MESSAGE "Failed to find all Ice components")
  323. unset(_Ice_REQUIRED_LIBS_FOUND)
  324. if(Ice_FOUND)
  325. set(Ice_INCLUDE_DIRS "${Ice_INCLUDE_DIR}")
  326. set(Ice_SLICE_DIRS "${Ice_SLICE_DIR}")
  327. set(Ice_LIBRARIES "${Ice_LIBRARY}")
  328. foreach(_Ice_component ${Ice_FIND_COMPONENTS})
  329. string(TOUPPER "${_Ice_component}" _Ice_component_upcase)
  330. set(_Ice_component_cache "Ice_${_Ice_component_upcase}_LIBRARY")
  331. set(_Ice_component_lib "Ice_${_Ice_component_upcase}_LIBRARIES")
  332. set(_Ice_component_found "${_Ice_component_upcase}_FOUND")
  333. if("${_Ice_component_found}")
  334. set("${_Ice_component_lib}" "${${_Ice_component_cache}}")
  335. endif()
  336. unset(_Ice_component_upcase)
  337. unset(_Ice_component_cache)
  338. unset(_Ice_component_lib)
  339. unset(_Ice_component_found)
  340. endforeach()
  341. endif()
  342. if(Ice_DEBUG)
  343. message(STATUS "--------FindIce.cmake results debug--------")
  344. message(STATUS "Ice_VERSION number: ${Ice_VERSION}")
  345. message(STATUS "Ice_HOME directory: ${Ice_HOME}")
  346. message(STATUS "Ice_INCLUDE_DIR directory: ${Ice_INCLUDE_DIR}")
  347. message(STATUS "Ice_SLICE_DIR directory: ${Ice_SLICE_DIR}")
  348. message(STATUS "Ice_LIBRARIES: ${Ice_LIBRARIES}")
  349. message(STATUS "slice2cpp executable: ${Ice_SLICE2CPP_EXECUTABLE}")
  350. message(STATUS "slice2cs executable: ${Ice_SLICE2CS_EXECUTABLE}")
  351. message(STATUS "slice2freezej executable: ${Ice_SLICE2FREEZEJ_EXECUTABLE}")
  352. message(STATUS "slice2freeze executable: ${Ice_SLICE2FREEZE_EXECUTABLE}")
  353. message(STATUS "slice2html executable: ${Ice_SLICE2HTML_EXECUTABLE}")
  354. message(STATUS "slice2java executable: ${Ice_SLICE2JAVA_EXECUTABLE}")
  355. message(STATUS "slice2php executable: ${Ice_SLICE2PHP_EXECUTABLE}")
  356. message(STATUS "slice2py executable: ${Ice_SLICE2PY_EXECUTABLE}")
  357. message(STATUS "slice2rb executable: ${Ice_SLICE2RB_EXECUTABLE}")
  358. foreach(component ${Ice_FIND_COMPONENTS})
  359. string(TOUPPER "${component}" component_upcase)
  360. set(component_lib "Ice_${component_upcase}_LIBRARIES")
  361. set(component_found "${component_upcase}_FOUND")
  362. message(STATUS "${component} library found: ${${component_found}}")
  363. message(STATUS "${component} library: ${${component_lib}}")
  364. endforeach()
  365. message(STATUS "----------------")
  366. endif()