FindFLTK.cmake 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #
  2. # Find the native FLTK includes and library
  3. #
  4. # The following settings are defined
  5. # FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
  6. # FLTK_WRAP_UI, This allows the FLTK_WRAP_UI command to work.
  7. # FLTK_INCLUDE_DIR, where to find include files
  8. # FLTK_LIBRARIES, list of fltk libraries
  9. # FLTK_FOUND, Don't use FLTK if false.
  10. # The following settings should not be used in general.
  11. # FLTK_BASE_LIBRARY = the full path to fltk.lib
  12. # FLTK_GL_LIBRARY = the full path to fltk_gl.lib
  13. # FLTK_FORMS_LIBRARY = the full path to fltk_forms.lib
  14. # FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
  15. # Platform dependent libraries required by FLTK
  16. IF(WIN32)
  17. IF(NOT CYGWIN)
  18. IF(BORLAND)
  19. SET( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
  20. ELSE(BORLAND)
  21. SET( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
  22. ENDIF(BORLAND)
  23. ENDIF(NOT CYGWIN)
  24. ENDIF(WIN32)
  25. IF(UNIX)
  26. INCLUDE(${CMAKE_ROOT}/Modules/FindX11.cmake)
  27. SET( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
  28. ENDIF(UNIX)
  29. IF(APPLE)
  30. SET( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
  31. ENDIF(APPLE)
  32. IF(CYGWIN)
  33. SET( FLTK_PLATFORM_DEPENDENT_LIBS ole32 uuid comctl32 wsock32 supc++ -lm -lgdi32)
  34. ENDIF(CYGWIN)
  35. # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
  36. IF(FLTK_INCLUDE_DIR)
  37. SET(FLTK_DIR ${FLTK_INCLUDE_DIR})
  38. ENDIF(FLTK_INCLUDE_DIR)
  39. # If FLTK has been built using CMake we try to find everything directly
  40. SET(FLTK_DIR_STRING "directory containing FLTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
  41. # Search only if the location is not already known.
  42. IF(NOT FLTK_DIR)
  43. # Get the system search path as a list.
  44. IF(UNIX)
  45. STRING(REGEX MATCHALL "[^:]+" FLTK_DIR_SEARCH1 "$ENV{PATH}")
  46. ELSE(UNIX)
  47. STRING(REGEX REPLACE "\\\\" "/" FLTK_DIR_SEARCH1 "$ENV{PATH}")
  48. ENDIF(UNIX)
  49. STRING(REGEX REPLACE "/;" ";" FLTK_DIR_SEARCH2 ${FLTK_DIR_SEARCH1})
  50. # Construct a set of paths relative to the system search path.
  51. SET(FLTK_DIR_SEARCH "")
  52. FOREACH(dir ${FLTK_DIR_SEARCH2})
  53. SET(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
  54. ENDFOREACH(dir)
  55. #
  56. # Look for an installation or build tree.
  57. #
  58. FIND_PATH(FLTK_DIR FLTKConfig.cmake
  59. # Look for an environment variable FLTK_DIR.
  60. $ENV{FLTK_DIR}
  61. # Look in places relative to the system executable search path.
  62. ${FLTK_DIR_SEARCH}
  63. # Look in standard UNIX install locations.
  64. /usr/local/lib/fltk
  65. /usr/lib/fltk
  66. /usr/local/include
  67. /usr/include
  68. /usr/local/fltk
  69. /usr/X11R6/include
  70. # Read from the CMakeSetup registry entries. It is likely that
  71. # FLTK will have been recently built.
  72. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  73. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  74. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  75. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  76. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  77. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  78. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  79. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  80. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  81. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  82. # Help the user find it if we cannot.
  83. DOC "The ${FLTK_DIR_STRING}"
  84. )
  85. ENDIF(NOT FLTK_DIR)
  86. # If FLTK was found, load the configuration file to get the rest of the
  87. # settings.
  88. IF(FLTK_DIR)
  89. # Check if FLTK was built using CMake
  90. IF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
  91. SET(FLTK_BUILT_WITH_CMAKE 1)
  92. ENDIF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
  93. IF(FLTK_BUILT_WITH_CMAKE)
  94. SET(FLTK_FOUND 1)
  95. INCLUDE(${FLTK_DIR}/FLTKConfig.cmake)
  96. # Fluid
  97. IF(FLUID_COMMAND)
  98. SET(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
  99. ELSE(FLUID_COMMAND)
  100. FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid PATHS
  101. ${FLTK_EXECUTABLE_DIRS}
  102. ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
  103. ${FLTK_EXECUTABLE_DIRS}/Debug
  104. ${FLTK_EXECUTABLE_DIRS}/Release
  105. NO_SYSTEM_PATH)
  106. ENDIF(FLUID_COMMAND)
  107. # MARK_AS_ADVANCED(FLTK_FLUID_EXECUTABLE)
  108. SET(FLTK_INCLUDE_DIR ${FLTK_DIR})
  109. LINK_DIRECTORIES(${FLTK_LIBRARY_DIRS})
  110. SET(FLTK_BASE_LIBRARY fltk)
  111. SET(FLTK_GL_LIBRARY fltk_gl)
  112. SET(FLTK_FORMS_LIBRARY fltk_forms)
  113. SET(FLTK_IMAGES_LIBRARY fltk_images)
  114. # Add the extra libraries
  115. LOAD_CACHE(${FLTK_DIR}
  116. READ_WITH_PREFIX
  117. FL FLTK_USE_SYSTEM_JPEG
  118. FL FLTK_USE_SYSTEM_PNG
  119. FL FLTK_USE_SYSTEM_ZLIB
  120. )
  121. SET(FLTK_IMAGES_LIBS "")
  122. IF(FLFLTK_USE_SYSTEM_JPEG)
  123. SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
  124. ENDIF(FLFLTK_USE_SYSTEM_JPEG)
  125. IF(FLFLTK_USE_SYSTEM_PNG)
  126. SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
  127. ENDIF(FLFLTK_USE_SYSTEM_PNG)
  128. IF(FLFLTK_USE_SYSTEM_ZLIB)
  129. SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
  130. ENDIF(FLFLTK_USE_SYSTEM_ZLIB)
  131. SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  132. "Extra libraries for fltk_images library.")
  133. ELSE(FLTK_BUILT_WITH_CMAKE)
  134. # if FLTK was not built using CMake
  135. # Find fluid executable.
  136. FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
  137. # Use location of fluid to help find everything else.
  138. SET(FLTK_INCLUDE_SEARCH_PATH "")
  139. SET(FLTK_LIBRARY_SEARCH_PATH "")
  140. IF(FLTK_FLUID_EXECUTABLE)
  141. GET_FILENAME_COMPONENT(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
  142. SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  143. ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
  144. SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  145. ${FLTK_BIN_DIR}/../lib)
  146. SET(FLTK_WRAP_UI 1)
  147. ENDIF(FLTK_FLUID_EXECUTABLE)
  148. SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
  149. /usr/local/include
  150. /usr/include
  151. /usr/local/fltk
  152. /usr/X11R6/include
  153. )
  154. FIND_PATH(FLTK_INCLUDE_DIR FL/Fl.h ${FLTK_INCLUDE_SEARCH_PATH})
  155. SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
  156. /usr/lib
  157. /usr/local/lib
  158. /usr/local/fltk/lib
  159. /usr/X11R6/lib
  160. ${FLTK_INCLUDE_DIR}/lib
  161. )
  162. FIND_LIBRARY(FLTK_BASE_LIBRARY NAMES fltk fltkd
  163. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  164. FIND_LIBRARY(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
  165. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  166. FIND_LIBRARY(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
  167. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  168. FIND_LIBRARY(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
  169. PATHS ${FLTK_LIBRARY_SEARCH_PATH})
  170. # Find the extra libraries needed for the fltk_images library.
  171. IF(UNIX)
  172. FIND_PROGRAM(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
  173. IF(FLTK_CONFIG_SCRIPT)
  174. EXEC_PROGRAM(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
  175. OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
  176. SET(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
  177. IF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
  178. STRING(REGEX REPLACE "${FLTK_LIBS_EXTRACT_REGEX}" "\\1"
  179. FLTK_IMAGES_LIBS "${FLTK_IMAGES_LDFLAGS}")
  180. STRING(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}")
  181. # The EXEC_PROGRAM will not be inherited into subdirectories from
  182. # the file that originally included this module. Save the answer.
  183. SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
  184. "Extra libraries for fltk_images library.")
  185. ENDIF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
  186. ENDIF(FLTK_CONFIG_SCRIPT)
  187. ENDIF(UNIX)
  188. ENDIF(FLTK_BUILT_WITH_CMAKE)
  189. ENDIF(FLTK_DIR)
  190. SET(FLTK_FOUND 1)
  191. FOREACH(var FLTK_FLUID_EXECUTABLE FLTK_INCLUDE_DIR
  192. FLTK_BASE_LIBRARY FLTK_GL_LIBRARY
  193. FLTK_FORMS_LIBRARY FLTK_IMAGES_LIBRARY)
  194. IF(NOT ${var})
  195. SET(FLTK_FOUND 0)
  196. ENDIF(NOT ${var})
  197. ENDFOREACH(var)
  198. IF(FLTK_FOUND)
  199. SET(FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY} ${FLTK_IMAGES_LIBS} ${FLTK_BASE_LIBRARY} ${FLTK_GL_LIBRARY}
  200. ${FLTK_FORMS_LIBRARY} )
  201. IF(APPLE)
  202. SET(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
  203. ELSE(APPLE)
  204. SET(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
  205. ENDIF(APPLE)
  206. # The following deprecated settings are for compatibility with CMake 1.4
  207. SET (HAS_FLTK ${FLTK_FOUND})
  208. SET (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
  209. SET (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
  210. SET (FLTK_LIBRARY ${FLTK_LIBRARIES})
  211. ENDIF(FLTK_FOUND)