FindFLTK2.cmake 8.0 KB

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