FindFLTK2.cmake 7.5 KB

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