FindFLTK.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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()
  52. set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
  53. endif()
  54. endif()
  55. endif()
  56. if(UNIX)
  57. include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
  58. find_library(FLTK_MATH_LIBRARY m)
  59. set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
  60. endif()
  61. if(APPLE)
  62. set( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
  63. endif()
  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()
  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. file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
  74. # Construct a set of paths relative to the system search path.
  75. set(FLTK_DIR_SEARCH "")
  76. foreach(dir ${FLTK_DIR_SEARCH2})
  77. set(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
  78. endforeach()
  79. string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
  80. #
  81. # Look for an installation or build tree.
  82. #
  83. find_path(FLTK_DIR FLTKConfig.cmake
  84. # Look for an environment variable FLTK_DIR.
  85. HINTS
  86. ENV FLTK_DIR
  87. # Look in places relative to the system executable search path.
  88. ${FLTK_DIR_SEARCH}
  89. PATHS
  90. # Look in standard UNIX install locations.
  91. /usr/local/lib/fltk
  92. /usr/lib/fltk
  93. /usr/local/fltk
  94. /usr/X11R6/include
  95. # Read from the CMakeSetup registry entries. It is likely that
  96. # FLTK will have been recently built.
  97. # TODO: Is this really a good idea? I can already hear the user screaming, "But
  98. # it worked when I configured the build LAST week!"
  99. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  100. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  101. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  102. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  103. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  104. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  105. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  106. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  107. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  108. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  109. # Help the user find it if we cannot.
  110. DOC "The ${FLTK_DIR_STRING}"
  111. )
  112. endif()
  113. # Check if FLTK was built using CMake
  114. if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
  115. set(FLTK_BUILT_WITH_CMAKE 1)
  116. endif()
  117. if(FLTK_BUILT_WITH_CMAKE)
  118. set(FLTK_FOUND 1)
  119. include(${FLTK_DIR}/FLTKConfig.cmake)
  120. # Fluid
  121. if(FLUID_COMMAND)
  122. set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
  123. else()
  124. find_program(FLTK_FLUID_EXECUTABLE fluid PATHS
  125. ${FLTK_EXECUTABLE_DIRS}
  126. ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
  127. ${FLTK_EXECUTABLE_DIRS}/Debug
  128. ${FLTK_EXECUTABLE_DIRS}/Release
  129. NO_SYSTEM_PATH)
  130. endif()
  131. # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
  132. set(FLTK_INCLUDE_DIR ${FLTK_DIR})
  133. link_directories(${FLTK_LIBRARY_DIRS})
  134. set(FLTK_BASE_LIBRARY fltk)
  135. set(FLTK_GL_LIBRARY fltk_gl)
  136. set(FLTK_FORMS_LIBRARY fltk_forms)
  137. set(FLTK_IMAGES_LIBRARY fltk_images)
  138. # Add the extra libraries
  139. load_cache(${FLTK_DIR}
  140. READ_WITH_PREFIX
  141. FL FLTK_USE_SYSTEM_JPEG
  142. FL FLTK_USE_SYSTEM_PNG
  143. FL FLTK_USE_SYSTEM_ZLIB
  144. )
  145. set(FLTK_IMAGES_LIBS "")
  146. if(FLFLTK_USE_SYSTEM_JPEG)
  147. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
  148. endif()
  149. if(FLFLTK_USE_SYSTEM_PNG)
  150. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
  151. endif()
  152. if(FLFLTK_USE_SYSTEM_ZLIB)
  153. set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
  154. endif()
  155. set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  156. "Extra libraries for fltk_images library.")
  157. else()
  158. # if FLTK was not built using CMake
  159. # Find fluid executable.
  160. find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
  161. # Use location of fluid to help find everything else.
  162. set(FLTK_INCLUDE_SEARCH_PATH "")
  163. set(FLTK_LIBRARY_SEARCH_PATH "")
  164. if(FLTK_FLUID_EXECUTABLE)
  165. get_filename_component(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
  166. set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  167. ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
  168. set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  169. ${FLTK_BIN_DIR}/../lib)
  170. set(FLTK_WRAP_UI 1)
  171. endif()
  172. #
  173. # Try to find FLTK include dir using fltk-config
  174. #
  175. if(UNIX)
  176. # Use fltk-config to generate a list of possible include directories
  177. find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
  178. if(FLTK_CONFIG_SCRIPT)
  179. if(NOT FLTK_INCLUDE_DIR)
  180. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
  181. if(FLTK_CXXFLAGS)
  182. string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
  183. string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
  184. foreach(_dir ${_fltk_temp_dirs})
  185. string(STRIP ${_dir} _output)
  186. list(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
  187. endforeach()
  188. endif()
  189. endif()
  190. endif()
  191. endif()
  192. set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  193. /usr/local/fltk
  194. /usr/X11R6/include
  195. ${_FLTK_POSSIBLE_INCLUDE_DIRS}
  196. )
  197. find_path(FLTK_INCLUDE_DIR
  198. NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
  199. PATHS ${FLTK_INCLUDE_SEARCH_PATH})
  200. #
  201. # Try to find FLTK library
  202. if(UNIX)
  203. if(FLTK_CONFIG_SCRIPT)
  204. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
  205. if(_FLTK_POSSIBLE_LIBS)
  206. get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
  207. endif()
  208. endif()
  209. endif()
  210. set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  211. /usr/local/fltk/lib
  212. /usr/X11R6/lib
  213. ${FLTK_INCLUDE_DIR}/lib
  214. ${_FLTK_POSSIBLE_LIBRARY_DIR}
  215. )
  216. find_library(FLTK_BASE_LIBRARY NAMES fltk fltkd
  217. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  218. find_library(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
  219. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  220. find_library(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
  221. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  222. find_library(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
  223. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  224. # Find the extra libraries needed for the fltk_images library.
  225. if(UNIX)
  226. if(FLTK_CONFIG_SCRIPT)
  227. exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
  228. OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
  229. set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
  230. if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
  231. string(REGEX REPLACE "${FLTK_LIBS_EXTRACT_REGEX}" "\\1"
  232. FLTK_IMAGES_LIBS "${FLTK_IMAGES_LDFLAGS}")
  233. string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}")
  234. # The EXEC_PROGRAM will not be inherited into subdirectories from
  235. # the file that originally included this module. Save the answer.
  236. set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  237. "Extra libraries for fltk_images library.")
  238. endif()
  239. endif()
  240. endif()
  241. endif()
  242. # Append all of the required libraries together (by default, everything)
  243. set(FLTK_LIBRARIES)
  244. if(NOT FLTK_SKIP_IMAGES)
  245. list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
  246. endif()
  247. if(NOT FLTK_SKIP_FORMS)
  248. list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
  249. endif()
  250. if(NOT FLTK_SKIP_OPENGL)
  251. list(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
  252. list(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
  253. list(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
  254. endif()
  255. list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
  256. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  257. if(FLTK_SKIP_FLUID)
  258. FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
  259. else()
  260. FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
  261. endif()
  262. if(FLTK_FOUND)
  263. if(APPLE)
  264. set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
  265. else()
  266. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
  267. endif()
  268. # The following deprecated settings are for compatibility with CMake 1.4
  269. set (HAS_FLTK ${FLTK_FOUND})
  270. set (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
  271. set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
  272. set (FLTK_LIBRARY ${FLTK_LIBRARIES})
  273. endif()