FindGLEW.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindGLEW
  5. --------
  6. Find the OpenGL Extension Wrangler Library (GLEW)
  7. Input Variables
  8. ^^^^^^^^^^^^^^^
  9. The following variables may be set to influence this module’s behavior:
  10. ``GLEW_USE_STATIC_LIBS``
  11. to find and create :prop_tgt:`IMPORTED` target for static linkage.
  12. ``GLEW_VERBOSE``
  13. to output a detailed log of this module.
  14. Imported Targets
  15. ^^^^^^^^^^^^^^^^
  16. This module defines the following :ref:`Imported Targets <Imported Targets>`:
  17. ``GLEW::glew``
  18. The GLEW shared library.
  19. ``GLEW::glew_s``
  20. The GLEW static library, if ``GLEW_USE_STATIC_LIBS`` is set to ``TRUE``.
  21. ``GLEW::GLEW``
  22. Duplicates either ``GLEW::glew`` or ``GLEW::glew_s`` based on availability.
  23. Result Variables
  24. ^^^^^^^^^^^^^^^^
  25. This module defines the following variables:
  26. ``GLEW_INCLUDE_DIRS``
  27. include directories for GLEW
  28. ``GLEW_LIBRARIES``
  29. libraries to link against GLEW
  30. ``GLEW_SHARED_LIBRARIES``
  31. libraries to link against shared GLEW
  32. ``GLEW_STATIC_LIBRARIES``
  33. libraries to link against static GLEW
  34. ``GLEW_FOUND``
  35. true if GLEW has been found and can be used
  36. ``GLEW_VERSION``
  37. GLEW version
  38. ``GLEW_VERSION_MAJOR``
  39. GLEW major version
  40. ``GLEW_VERSION_MINOR``
  41. GLEW minor version
  42. ``GLEW_VERSION_MICRO``
  43. GLEW micro version
  44. #]=======================================================================]
  45. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  46. find_package(GLEW CONFIG QUIET)
  47. if(GLEW_FOUND)
  48. find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_CONFIG)
  49. return()
  50. endif()
  51. if(GLEW_VERBOSE)
  52. message(STATUS "FindGLEW: did not find GLEW CMake config file. Searching for libraries.")
  53. endif()
  54. if(APPLE)
  55. find_package(OpenGL QUIET)
  56. if(OpenGL_FOUND)
  57. if(GLEW_VERBOSE)
  58. message(STATUS "FindGLEW: Found OpenGL Framework.")
  59. message(STATUS "FindGLEW: OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")
  60. endif()
  61. else()
  62. if(GLEW_VERBOSE)
  63. message(STATUS "FindGLEW: could not find GLEW library.")
  64. endif()
  65. return()
  66. endif()
  67. endif()
  68. function(__glew_set_find_library_suffix shared_or_static)
  69. if((UNIX AND NOT APPLE) AND "${shared_or_static}" MATCHES "SHARED")
  70. set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" PARENT_SCOPE)
  71. elseif((UNIX AND NOT APPLE) AND "${shared_or_static}" MATCHES "STATIC")
  72. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
  73. elseif(APPLE AND "${shared_or_static}" MATCHES "SHARED")
  74. set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib;.so" PARENT_SCOPE)
  75. elseif(APPLE AND "${shared_or_static}" MATCHES "STATIC")
  76. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
  77. elseif(WIN32 AND "${shared_or_static}" MATCHES "SHARED")
  78. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" PARENT_SCOPE)
  79. elseif(WIN32 AND "${shared_or_static}" MATCHES "STATIC")
  80. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll.a" PARENT_SCOPE)
  81. endif()
  82. if(GLEW_VERBOSE)
  83. message(STATUS "FindGLEW: CMAKE_FIND_LIBRARY_SUFFIXES for ${shared_or_static}: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
  84. endif()
  85. endfunction()
  86. if(GLEW_VERBOSE)
  87. if(DEFINED GLEW_USE_STATIC_LIBS)
  88. message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS: ${GLEW_USE_STATIC_LIBS}.")
  89. else()
  90. message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS is undefined. Treated as FALSE.")
  91. endif()
  92. endif()
  93. find_path(GLEW_INCLUDE_DIR GL/glew.h)
  94. mark_as_advanced(GLEW_INCLUDE_DIR)
  95. set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
  96. if(GLEW_VERBOSE)
  97. message(STATUS "FindGLEW: GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}")
  98. message(STATUS "FindGLEW: GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}")
  99. endif()
  100. if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64" OR "${CMAKE_GENERATOR}" MATCHES "Win64")
  101. set(_arch "x64")
  102. else()
  103. set(_arch "Win32")
  104. endif()
  105. set(__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  106. __glew_set_find_library_suffix(SHARED)
  107. find_library(GLEW_SHARED_LIBRARY_RELEASE
  108. NAMES GLEW glew glew32
  109. PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch}
  110. PATHS ENV GLEW_ROOT)
  111. find_library(GLEW_SHARED_LIBRARY_DEBUG
  112. NAMES GLEWd glewd glew32d
  113. PATH_SUFFIXES lib lib64
  114. PATHS ENV GLEW_ROOT)
  115. __glew_set_find_library_suffix(STATIC)
  116. find_library(GLEW_STATIC_LIBRARY_RELEASE
  117. NAMES GLEW glew glew32s
  118. PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch}
  119. PATHS ENV GLEW_ROOT)
  120. find_library(GLEW_STATIC_LIBRARY_DEBUG
  121. NAMES GLEWds glewds glew32ds
  122. PATH_SUFFIXES lib lib64
  123. PATHS ENV GLEW_ROOT)
  124. set(CMAKE_FIND_LIBRARY_SUFFIXES ${__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES})
  125. unset(__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES)
  126. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  127. select_library_configurations(GLEW_SHARED)
  128. select_library_configurations(GLEW_STATIC)
  129. if(NOT GLEW_USE_STATIC_LIBS)
  130. set(GLEW_LIBRARIES ${GLEW_SHARED_LIBRARY})
  131. else()
  132. set(GLEW_LIBRARIES ${GLEW_STATIC_LIBRARY})
  133. endif()
  134. if(GLEW_VERBOSE)
  135. message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_RELEASE: ${GLEW_SHARED_LIBRARY_RELEASE}")
  136. message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_RELEASE: ${GLEW_STATIC_LIBRARY_RELEASE}")
  137. message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_DEBUG: ${GLEW_SHARED_LIBRARY_DEBUG}")
  138. message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_DEBUG: ${GLEW_STATIC_LIBRARY_DEBUG}")
  139. message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY: ${GLEW_SHARED_LIBRARY}")
  140. message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY: ${GLEW_STATIC_LIBRARY}")
  141. message(STATUS "FindGLEW: GLEW_LIBRARIES: ${GLEW_LIBRARIES}")
  142. endif()
  143. # Read version from GL/glew.h file
  144. if(EXISTS "${GLEW_INCLUDE_DIR}/GL/glew.h")
  145. file(STRINGS "${GLEW_INCLUDE_DIR}/GL/glew.h" _contents REGEX "^VERSION_.+ [0-9]+")
  146. if(_contents)
  147. string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MAJOR "${_contents}")
  148. string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MINOR "${_contents}")
  149. string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MICRO "${_contents}")
  150. set(GLEW_VERSION "${GLEW_VERSION_MAJOR}.${GLEW_VERSION_MINOR}.${GLEW_VERSION_MICRO}")
  151. endif()
  152. endif()
  153. if(GLEW_VERBOSE)
  154. message(STATUS "FindGLEW: GLEW_VERSION_MAJOR: ${GLEW_VERSION_MAJOR}")
  155. message(STATUS "FindGLEW: GLEW_VERSION_MINOR: ${GLEW_VERSION_MINOR}")
  156. message(STATUS "FindGLEW: GLEW_VERSION_MICRO: ${GLEW_VERSION_MICRO}")
  157. message(STATUS "FindGLEW: GLEW_VERSION: ${GLEW_VERSION}")
  158. endif()
  159. find_package_handle_standard_args(GLEW
  160. REQUIRED_VARS GLEW_INCLUDE_DIRS GLEW_LIBRARIES
  161. VERSION_VAR GLEW_VERSION)
  162. if(NOT GLEW_FOUND)
  163. if(GLEW_VERBOSE)
  164. message(STATUS "FindGLEW: could not find GLEW library.")
  165. endif()
  166. return()
  167. endif()
  168. if(NOT TARGET GLEW::glew AND NOT GLEW_USE_STATIC_LIBS)
  169. if(GLEW_VERBOSE)
  170. message(STATUS "FindGLEW: Creating GLEW::glew imported target.")
  171. endif()
  172. add_library(GLEW::glew UNKNOWN IMPORTED)
  173. set_target_properties(GLEW::glew
  174. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
  175. if(APPLE)
  176. set_target_properties(GLEW::glew
  177. PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
  178. endif()
  179. if(GLEW_SHARED_LIBRARY_RELEASE)
  180. set_property(TARGET GLEW::glew
  181. APPEND
  182. PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  183. set_target_properties(GLEW::glew
  184. PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}")
  185. endif()
  186. if(GLEW_SHARED_LIBRARY_DEBUG)
  187. set_property(TARGET GLEW::glew
  188. APPEND
  189. PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  190. set_target_properties(GLEW::glew
  191. PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}")
  192. endif()
  193. elseif(NOT TARGET GLEW::glew_s AND GLEW_USE_STATIC_LIBS)
  194. if(GLEW_VERBOSE)
  195. message(STATUS "FindGLEW: Creating GLEW::glew_s imported target.")
  196. endif()
  197. add_library(GLEW::glew_s UNKNOWN IMPORTED)
  198. set_target_properties(GLEW::glew_s
  199. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
  200. if(APPLE)
  201. set_target_properties(GLEW::glew_s
  202. PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
  203. endif()
  204. if(GLEW_STATIC_LIBRARY_RELEASE)
  205. set_property(TARGET GLEW::glew_s
  206. APPEND
  207. PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  208. set_target_properties(GLEW::glew_s
  209. PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}")
  210. endif()
  211. if(GLEW_STATIC_LIBRARY_DEBUG)
  212. set_property(TARGET GLEW::glew_s
  213. APPEND
  214. PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  215. set_target_properties(GLEW::glew_s
  216. PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}")
  217. endif()
  218. endif()
  219. if(NOT TARGET GLEW::GLEW)
  220. if(GLEW_VERBOSE)
  221. message(STATUS "FindGLEW: Creating GLEW::GLEW imported target.")
  222. endif()
  223. add_library(GLEW::GLEW UNKNOWN IMPORTED)
  224. set_target_properties(GLEW::GLEW
  225. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
  226. if(APPLE)
  227. set_target_properties(GLEW::GLEW
  228. PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
  229. endif()
  230. if(TARGET GLEW::glew)
  231. if(GLEW_SHARED_LIBRARY_RELEASE)
  232. set_property(TARGET GLEW::GLEW
  233. APPEND
  234. PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  235. set_target_properties(GLEW::GLEW
  236. PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}")
  237. endif()
  238. if(GLEW_SHARED_LIBRARY_DEBUG)
  239. set_property(TARGET GLEW::GLEW
  240. APPEND
  241. PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  242. set_target_properties(GLEW::GLEW
  243. PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}")
  244. endif()
  245. elseif(TARGET GLEW::glew_s)
  246. if(GLEW_STATIC_LIBRARY_RELEASE)
  247. set_property(TARGET GLEW::GLEW
  248. APPEND
  249. PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  250. set_target_properties(GLEW::GLEW
  251. PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}")
  252. endif()
  253. if(GLEW_STATIC_LIBRARY_DEBUG AND GLEW_USE_STATIC_LIBS)
  254. set_property(TARGET GLEW::GLEW
  255. APPEND
  256. PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  257. set_target_properties(GLEW::GLEW
  258. PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}")
  259. endif()
  260. elseif(GLEW_VERBOSE)
  261. message(WARNING "FindGLEW: no `GLEW::glew` or `GLEW::glew_s` target was created. Something went wrong in FindGLEW target creation.")
  262. endif()
  263. endif()