FindFLTK.cmake 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. #.rst:
  2. # FindFLTK
  3. # --------
  4. #
  5. # Find the native FLTK includes and library
  6. #
  7. #
  8. #
  9. # By default FindFLTK.cmake will search for all of the FLTK components
  10. # and add them to the FLTK_LIBRARIES variable.
  11. #
  12. # ::
  13. #
  14. # You can limit the components which get placed in FLTK_LIBRARIES by
  15. # defining one or more of the following three options:
  16. #
  17. #
  18. #
  19. # ::
  20. #
  21. # FLTK_SKIP_OPENGL, set to true to disable searching for opengl and
  22. # the FLTK GL library
  23. # FLTK_SKIP_FORMS, set to true to disable searching for fltk_forms
  24. # FLTK_SKIP_IMAGES, set to true to disable searching for fltk_images
  25. #
  26. #
  27. #
  28. # ::
  29. #
  30. # FLTK_SKIP_FLUID, set to true if the fluid binary need not be present
  31. # at build time
  32. #
  33. #
  34. #
  35. # The following variables will be defined:
  36. #
  37. # ::
  38. #
  39. # FLTK_FOUND, True if all components not skipped were found
  40. # FLTK_INCLUDE_DIR, where to find include files
  41. # FLTK_LIBRARIES, list of fltk libraries you should link against
  42. # FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
  43. # FLTK_WRAP_UI, This enables the FLTK_WRAP_UI command
  44. #
  45. #
  46. #
  47. # The following cache variables are assigned but should not be used.
  48. # See the FLTK_LIBRARIES variable instead.
  49. #
  50. # ::
  51. #
  52. # FLTK_BASE_LIBRARY = the full path to fltk.lib
  53. # FLTK_GL_LIBRARY = the full path to fltk_gl.lib
  54. # FLTK_FORMS_LIBRARY = the full path to fltk_forms.lib
  55. # FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
  56. #=============================================================================
  57. # Copyright 2001-2009 Kitware, Inc.
  58. #
  59. # Distributed under the OSI-approved BSD License (the "License");
  60. # see accompanying file Copyright.txt for details.
  61. #
  62. # This software is distributed WITHOUT ANY WARRANTY; without even the
  63. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  64. # See the License for more information.
  65. #=============================================================================
  66. # (To distribute this file outside of CMake, substitute the full
  67. # License text for the above reference.)
  68. if(NOT FLTK_SKIP_OPENGL)
  69. find_package(OpenGL)
  70. endif()
  71. # Platform dependent libraries required by FLTK
  72. if(WIN32)
  73. if(NOT CYGWIN)
  74. if(BORLAND)
  75. set( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
  76. else()
  77. set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
  78. endif()
  79. endif()
  80. endif()
  81. if(UNIX)
  82. include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
  83. find_library(FLTK_MATH_LIBRARY m)
  84. set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
  85. endif()
  86. if(APPLE)
  87. set( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
  88. endif()
  89. # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
  90. if(FLTK_INCLUDE_DIR)
  91. set(FLTK_DIR ${FLTK_INCLUDE_DIR})
  92. endif()
  93. # If FLTK has been built using CMake we try to find everything directly
  94. set(FLTK_DIR_STRING "directory containing FLTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
  95. # Search only if the location is not already known.
  96. if(NOT FLTK_DIR)
  97. # Get the system search path as a list.
  98. file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
  99. # Construct a set of paths relative to the system search path.
  100. set(FLTK_DIR_SEARCH "")
  101. foreach(dir ${FLTK_DIR_SEARCH2})
  102. set(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
  103. endforeach()
  104. string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
  105. #
  106. # Look for an installation or build tree.
  107. #
  108. find_path(FLTK_DIR FLTKConfig.cmake
  109. # Look for an environment variable FLTK_DIR.
  110. HINTS
  111. ENV FLTK_DIR
  112. # Look in places relative to the system executable search path.
  113. ${FLTK_DIR_SEARCH}
  114. PATHS
  115. # Look in standard UNIX install locations.
  116. /usr/local/lib/fltk
  117. /usr/lib/fltk
  118. /usr/local/fltk
  119. /usr/X11R6/include
  120. # Help the user find it if we cannot.
  121. DOC "The ${FLTK_DIR_STRING}"
  122. )
  123. endif()
  124. # Check if FLTK was built using CMake
  125. if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
  126. set(FLTK_BUILT_WITH_CMAKE 1)
  127. endif()
  128. if(FLTK_BUILT_WITH_CMAKE)
  129. set(FLTK_FOUND 1)
  130. include(${FLTK_DIR}/FLTKConfig.cmake)
  131. # Fluid
  132. if(FLUID_COMMAND)
  133. set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
  134. else()
  135. find_program(FLTK_FLUID_EXECUTABLE fluid PATHS
  136. ${FLTK_EXECUTABLE_DIRS}
  137. ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
  138. ${FLTK_EXECUTABLE_DIRS}/Debug
  139. ${FLTK_EXECUTABLE_DIRS}/Release
  140. NO_SYSTEM_PATH)
  141. endif()
  142. # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
  143. set(FLTK_INCLUDE_DIR ${FLTK_DIR})
  144. link_directories(${FLTK_LIBRARY_DIRS})
  145. set(FLTK_BASE_LIBRARY fltk)
  146. set(FLTK_GL_LIBRARY fltk_gl)
  147. set(FLTK_FORMS_LIBRARY fltk_forms)
  148. set(FLTK_IMAGES_LIBRARY fltk_images)
  149. # Add the extra libraries
  150. load_cache(${FLTK_DIR}
  151. READ_WITH_PREFIX
  152. FL FLTK_USE_SYSTEM_JPEG
  153. FL FLTK_USE_SYSTEM_PNG
  154. FL FLTK_USE_SYSTEM_ZLIB
  155. )
  156. set(FLTK_IMAGES_LIBS "")
  157. if(FLFLTK_USE_SYSTEM_JPEG)
  158. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
  159. endif()
  160. if(FLFLTK_USE_SYSTEM_PNG)
  161. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
  162. endif()
  163. if(FLFLTK_USE_SYSTEM_ZLIB)
  164. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
  165. endif()
  166. set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  167. "Extra libraries for fltk_images library.")
  168. else()
  169. # if FLTK was not built using CMake
  170. # Find fluid executable.
  171. find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
  172. # Use location of fluid to help find everything else.
  173. set(FLTK_INCLUDE_SEARCH_PATH "")
  174. set(FLTK_LIBRARY_SEARCH_PATH "")
  175. if(FLTK_FLUID_EXECUTABLE)
  176. get_filename_component(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
  177. set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  178. ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
  179. set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  180. ${FLTK_BIN_DIR}/../lib)
  181. set(FLTK_WRAP_UI 1)
  182. endif()
  183. #
  184. # Try to find FLTK include dir using fltk-config
  185. #
  186. if(UNIX)
  187. # Use fltk-config to generate a list of possible include directories
  188. find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
  189. if(FLTK_CONFIG_SCRIPT)
  190. if(NOT FLTK_INCLUDE_DIR)
  191. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
  192. if(FLTK_CXXFLAGS)
  193. string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
  194. string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
  195. foreach(_dir ${_fltk_temp_dirs})
  196. string(STRIP ${_dir} _output)
  197. list(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
  198. endforeach()
  199. endif()
  200. endif()
  201. endif()
  202. endif()
  203. set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  204. /usr/local/fltk
  205. /usr/X11R6/include
  206. ${_FLTK_POSSIBLE_INCLUDE_DIRS}
  207. )
  208. find_path(FLTK_INCLUDE_DIR
  209. NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
  210. PATHS ${FLTK_INCLUDE_SEARCH_PATH})
  211. #
  212. # Try to find FLTK library
  213. if(UNIX)
  214. if(FLTK_CONFIG_SCRIPT)
  215. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
  216. if(_FLTK_POSSIBLE_LIBS)
  217. get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
  218. endif()
  219. endif()
  220. endif()
  221. set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  222. /usr/local/fltk/lib
  223. /usr/X11R6/lib
  224. ${FLTK_INCLUDE_DIR}/lib
  225. ${_FLTK_POSSIBLE_LIBRARY_DIR}
  226. )
  227. find_library(FLTK_BASE_LIBRARY NAMES fltk fltkd
  228. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  229. find_library(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
  230. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  231. find_library(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
  232. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  233. find_library(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
  234. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  235. # Find the extra libraries needed for the fltk_images library.
  236. if(UNIX)
  237. if(FLTK_CONFIG_SCRIPT)
  238. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
  239. OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
  240. set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
  241. if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
  242. string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${CMAKE_MATCH_1}")
  243. # The EXEC_PROGRAM will not be inherited into subdirectories from
  244. # the file that originally included this module. Save the answer.
  245. set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  246. "Extra libraries for fltk_images library.")
  247. endif()
  248. endif()
  249. endif()
  250. endif()
  251. # Append all of the required libraries together (by default, everything)
  252. set(FLTK_LIBRARIES)
  253. if(NOT FLTK_SKIP_IMAGES)
  254. list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
  255. endif()
  256. if(NOT FLTK_SKIP_FORMS)
  257. list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
  258. endif()
  259. if(NOT FLTK_SKIP_OPENGL)
  260. list(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
  261. list(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
  262. list(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
  263. endif()
  264. list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
  265. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  266. if(FLTK_SKIP_FLUID)
  267. FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
  268. else()
  269. FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
  270. endif()
  271. if(FLTK_FOUND)
  272. if(APPLE)
  273. set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
  274. else()
  275. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
  276. endif()
  277. # The following deprecated settings are for compatibility with CMake 1.4
  278. set (HAS_FLTK ${FLTK_FOUND})
  279. set (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
  280. set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
  281. set (FLTK_LIBRARY ${FLTK_LIBRARIES})
  282. endif()