FindFLTK2.cmake 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. # - Find the native FLTK2 includes and library
  2. # The following settings are defined
  3. # FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
  4. # FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
  5. # FLTK2_INCLUDE_DIR, where to find include files
  6. # FLTK2_LIBRARIES, list of fltk2 libraries
  7. # FLTK2_FOUND, Don't use FLTK2 if false.
  8. # The following settings should not be used in general.
  9. # FLTK2_BASE_LIBRARY = the full path to fltk2.lib
  10. # FLTK2_GL_LIBRARY = the full path to fltk2_gl.lib
  11. # FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib
  12. #=============================================================================
  13. # Copyright 2007-2009 Kitware, Inc.
  14. #
  15. # Distributed under the OSI-approved BSD License (the "License");
  16. # see accompanying file Copyright.txt for details.
  17. #
  18. # This software is distributed WITHOUT ANY WARRANTY; without even the
  19. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. # See the License for more information.
  21. #=============================================================================
  22. # (To distributed this file outside of CMake, substitute the full
  23. # License text for the above reference.)
  24. SET (FLTK2_DIR $ENV{FLTK2_DIR} )
  25. # Platform dependent libraries required by FLTK2
  26. IF(WIN32)
  27. IF(NOT CYGWIN)
  28. IF(BORLAND)
  29. SET( FLTK2_PLATFORM_DEPENDENT_LIBS import32 )
  30. ELSE(BORLAND)
  31. SET( FLTK2_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
  32. ENDIF(BORLAND)
  33. ENDIF(NOT CYGWIN)
  34. ENDIF(WIN32)
  35. IF(UNIX)
  36. INCLUDE(${CMAKE_ROOT}/Modules/FindX11.cmake)
  37. SET( FLTK2_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
  38. ENDIF(UNIX)
  39. IF(APPLE)
  40. SET( FLTK2_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
  41. ENDIF(APPLE)
  42. IF(CYGWIN)
  43. SET( FLTK2_PLATFORM_DEPENDENT_LIBS ole32 uuid comctl32 wsock32 supc++ -lm -lgdi32)
  44. ENDIF(CYGWIN)
  45. # If FLTK2_INCLUDE_DIR is already defined we assigne its value to FLTK2_DIR
  46. IF(FLTK2_INCLUDE_DIR)
  47. SET(FLTK2_DIR ${FLTK2_INCLUDE_DIR})
  48. ELSE(FLTK2_INCLUDE_DIR)
  49. SET(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
  50. ENDIF(FLTK2_INCLUDE_DIR)
  51. # If FLTK2 has been built using CMake we try to find everything directly
  52. SET(FLTK2_DIR_STRING "directory containing FLTK2Config.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
  53. # Search only if the location is not already known.
  54. IF(NOT FLTK2_DIR)
  55. # Get the system search path as a list.
  56. IF(UNIX)
  57. STRING(REGEX MATCHALL "[^:]+" FLTK2_DIR_SEARCH1 "$ENV{PATH}")
  58. ELSE(UNIX)
  59. STRING(REGEX REPLACE "\\\\" "/" FLTK2_DIR_SEARCH1 "$ENV{PATH}")
  60. ENDIF(UNIX)
  61. STRING(REGEX REPLACE "/;" ";" FLTK2_DIR_SEARCH2 ${FLTK2_DIR_SEARCH1})
  62. # Construct a set of paths relative to the system search path.
  63. SET(FLTK2_DIR_SEARCH "")
  64. FOREACH(dir ${FLTK2_DIR_SEARCH2})
  65. SET(FLTK2_DIR_SEARCH ${FLTK2_DIR_SEARCH} "${dir}/../lib/fltk")
  66. ENDFOREACH(dir)
  67. #
  68. # Look for an installation or build tree.
  69. #
  70. FIND_PATH(FLTK2_DIR FLTK2Config.cmake
  71. # Look for an environment variable FLTK2_DIR.
  72. $ENV{FLTK2_DIR}
  73. # Look in places relative to the system executable search path.
  74. ${FLTK2_DIR_SEARCH}
  75. # Look in standard UNIX install locations.
  76. /usr/local/lib/fltk2
  77. /usr/lib/fltk2
  78. /usr/local/include
  79. /usr/include
  80. /usr/local/fltk2
  81. /usr/X11R6/include
  82. # Read from the CMakeSetup registry entries. It is likely that
  83. # FLTK2 will have been recently built.
  84. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
  85. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
  86. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
  87. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
  88. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
  89. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
  90. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
  91. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
  92. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
  93. [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
  94. # Help the user find it if we cannot.
  95. DOC "The ${FLTK2_DIR_STRING}"
  96. )
  97. IF(NOT FLTK2_DIR)
  98. FIND_PATH(FLTK2_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
  99. ENDIF(NOT FLTK2_DIR)
  100. ENDIF(NOT FLTK2_DIR)
  101. # If FLTK2 was found, load the configuration file to get the rest of the
  102. # settings.
  103. IF(FLTK2_DIR)
  104. # Check if FLTK2 was built using CMake
  105. IF(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
  106. SET(FLTK2_BUILT_WITH_CMAKE 1)
  107. ENDIF(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
  108. IF(FLTK2_BUILT_WITH_CMAKE)
  109. SET(FLTK2_FOUND 1)
  110. INCLUDE(${FLTK2_DIR}/FLTK2Config.cmake)
  111. # Fluid
  112. IF(FLUID_COMMAND)
  113. SET(FLTK2_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
  114. ELSE(FLUID_COMMAND)
  115. FIND_PROGRAM(FLTK2_FLUID_EXECUTABLE fluid2 PATHS
  116. ${FLTK2_EXECUTABLE_DIRS}
  117. ${FLTK2_EXECUTABLE_DIRS}/RelWithDebInfo
  118. ${FLTK2_EXECUTABLE_DIRS}/Debug
  119. ${FLTK2_EXECUTABLE_DIRS}/Release
  120. NO_SYSTEM_PATH)
  121. ENDIF(FLUID_COMMAND)
  122. MARK_AS_ADVANCED(FLTK2_FLUID_EXECUTABLE)
  123. SET( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
  124. SET(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
  125. LINK_DIRECTORIES(${FLTK2_LIBRARY_DIRS})
  126. SET(FLTK2_BASE_LIBRARY fltk2)
  127. SET(FLTK2_GL_LIBRARY fltk2_gl)
  128. SET(FLTK2_IMAGES_LIBRARY fltk2_images)
  129. # Add the extra libraries
  130. LOAD_CACHE(${FLTK2_DIR}
  131. READ_WITH_PREFIX
  132. FL FLTK2_USE_SYSTEM_JPEG
  133. FL FLTK2_USE_SYSTEM_PNG
  134. FL FLTK2_USE_SYSTEM_ZLIB
  135. )
  136. SET(FLTK2_IMAGES_LIBS "")
  137. IF(FLFLTK2_USE_SYSTEM_JPEG)
  138. SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_jpeg)
  139. ENDIF(FLFLTK2_USE_SYSTEM_JPEG)
  140. IF(FLFLTK2_USE_SYSTEM_PNG)
  141. SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_png)
  142. ENDIF(FLFLTK2_USE_SYSTEM_PNG)
  143. IF(FLFLTK2_USE_SYSTEM_ZLIB)
  144. SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_zlib)
  145. ENDIF(FLFLTK2_USE_SYSTEM_ZLIB)
  146. SET(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
  147. "Extra libraries for fltk2_images library.")
  148. ELSE(FLTK2_BUILT_WITH_CMAKE)
  149. # if FLTK2 was not built using CMake
  150. # Find fluid executable.
  151. FIND_PROGRAM(FLTK2_FLUID_EXECUTABLE fluid2 ${FLTK2_INCLUDE_DIR}/fluid)
  152. # Use location of fluid to help find everything else.
  153. SET(FLTK2_INCLUDE_SEARCH_PATH "")
  154. SET(FLTK2_LIBRARY_SEARCH_PATH "")
  155. IF(FLTK2_FLUID_EXECUTABLE)
  156. SET( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
  157. GET_FILENAME_COMPONENT(FLTK2_BIN_DIR "${FLTK2_FLUID_EXECUTABLE}" PATH)
  158. SET(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
  159. ${FLTK2_BIN_DIR}/../include ${FLTK2_BIN_DIR}/..)
  160. SET(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
  161. ${FLTK2_BIN_DIR}/../lib)
  162. SET(FLTK2_WRAP_UI 1)
  163. ENDIF(FLTK2_FLUID_EXECUTABLE)
  164. SET(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
  165. /usr/local/include
  166. /usr/include
  167. /usr/local/fltk2
  168. /usr/X11R6/include
  169. )
  170. FIND_PATH(FLTK2_INCLUDE_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
  171. SET(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
  172. /usr/lib
  173. /usr/local/lib
  174. /usr/local/fltk2/lib
  175. /usr/X11R6/lib
  176. ${FLTK2_INCLUDE_DIR}/lib
  177. )
  178. FIND_LIBRARY(FLTK2_BASE_LIBRARY NAMES fltk2
  179. PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
  180. FIND_LIBRARY(FLTK2_GL_LIBRARY NAMES fltk2_gl
  181. PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
  182. FIND_LIBRARY(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
  183. PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
  184. # Find the extra libraries needed for the fltk_images library.
  185. IF(UNIX)
  186. FIND_PROGRAM(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR})
  187. IF(FLTK2_CONFIG_SCRIPT)
  188. EXEC_PROGRAM(${FLTK2_CONFIG_SCRIPT} ARGS --use-images --ldflags
  189. OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS)
  190. SET(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*")
  191. IF("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
  192. STRING(REGEX REPLACE "${FLTK2_LIBS_EXTRACT_REGEX}" "\\1"
  193. FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LDFLAGS}")
  194. STRING(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}")
  195. # The EXEC_PROGRAM will not be inherited into subdirectories from
  196. # the file that originally included this module. Save the answer.
  197. SET(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
  198. "Extra libraries for fltk_images library.")
  199. ENDIF("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
  200. ENDIF(FLTK2_CONFIG_SCRIPT)
  201. ENDIF(UNIX)
  202. ENDIF(FLTK2_BUILT_WITH_CMAKE)
  203. ENDIF(FLTK2_DIR)
  204. SET(FLTK2_FOUND 1)
  205. FOREACH(var FLTK2_FLUID_EXECUTABLE FLTK2_INCLUDE_DIR
  206. FLTK2_BASE_LIBRARY FLTK2_GL_LIBRARY
  207. FLTK2_IMAGES_LIBRARY)
  208. IF(NOT ${var})
  209. MESSAGE( STATUS "${var} not found" )
  210. SET(FLTK2_FOUND 0)
  211. ENDIF(NOT ${var})
  212. ENDFOREACH(var)
  213. IF(FLTK2_FOUND)
  214. SET(FLTK2_LIBRARIES ${FLTK2_IMAGES_LIBRARY} ${FLTK2_IMAGES_LIBS} ${FLTK2_BASE_LIBRARY} ${FLTK2_GL_LIBRARY} )
  215. IF(APPLE)
  216. SET(FLTK2_LIBRARIES ${FLTK2_PLATFORM_DEPENDENT_LIBS} ${FLTK2_LIBRARIES})
  217. ELSE(APPLE)
  218. SET(FLTK2_LIBRARIES ${FLTK2_LIBRARIES} ${FLTK2_PLATFORM_DEPENDENT_LIBS})
  219. ENDIF(APPLE)
  220. # The following deprecated settings are for compatibility with CMake 1.4
  221. SET (HAS_FLTK2 ${FLTK2_FOUND})
  222. SET (FLTK2_INCLUDE_PATH ${FLTK2_INCLUDE_DIR})
  223. SET (FLTK2_FLUID_EXE ${FLTK2_FLUID_EXECUTABLE})
  224. SET (FLTK2_LIBRARY ${FLTK2_LIBRARIES})
  225. ELSE(FLTK2_FOUND)
  226. # make FIND_PACKAGE friendly
  227. IF(NOT FLTK2_FIND_QUIETLY)
  228. IF(FLTK2_FIND_REQUIRED)
  229. MESSAGE(FATAL_ERROR
  230. "FLTK2 required, please specify its location with FLTK2_DIR.")
  231. ELSE(FLTK2_FIND_REQUIRED)
  232. MESSAGE(STATUS "FLTK2 was not found.")
  233. ENDIF(FLTK2_FIND_REQUIRED)
  234. ENDIF(NOT FLTK2_FIND_QUIETLY)
  235. ENDIF(FLTK2_FOUND)