FindFLTK.cmake 11 KB

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