FindFLTK.cmake 11 KB

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