FindFLTK.cmake 12 KB

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