1 # - Find the native FLTK includes and library
3 # By default FindFLTK.cmake will search for all of the FLTK components and
4 # add them to the FLTK_LIBRARIES variable.
6 # You can limit the components which get placed in FLTK_LIBRARIES by
7 # defining one or more of the following three options:
9 # FLTK_SKIP_OPENGL, set to true to disable searching for opengl and
11 # FLTK_SKIP_FORMS, set to true to disable searching for fltk_forms
12 # FLTK_SKIP_IMAGES, set to true to disable searching for fltk_images
14 # FLTK_SKIP_FLUID, set to true if the fluid binary need not be present
17 # The following variables will be defined:
18 # FLTK_FOUND, True if all components not skipped were found
19 # FLTK_INCLUDE_DIR, where to find include files
20 # FLTK_LIBRARIES, list of fltk libraries you should link against
21 # FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
22 # FLTK_WRAP_UI, This enables the FLTK_WRAP_UI command
24 # The following cache variables are assigned but should not be used.
25 # See the FLTK_LIBRARIES variable instead.
27 # FLTK_BASE_LIBRARY = the full path to fltk.lib
28 # FLTK_GL_LIBRARY = the full path to fltk_gl.lib
29 # FLTK_FORMS_LIBRARY = the full path to fltk_forms.lib
30 # FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
32 IF(NOT FLTK_SKIP_OPENGL)
36 # Platform dependent libraries required by FLTK
40 SET( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
42 SET( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
49 FIND_LIBRARY(FLTK_MATH_LIBRARY m)
50 SET( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
54 SET( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
58 FIND_LIBRARY(FLTK_MATH_LIBRARY m)
59 SET( FLTK_PLATFORM_DEPENDENT_LIBS ole32 uuid comctl32 wsock32 supc++ ${FLTK_MATH_LIBRARY} -lgdi32)
62 # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
64 SET(FLTK_DIR ${FLTK_INCLUDE_DIR})
65 ENDIF(FLTK_INCLUDE_DIR)
68 # If FLTK has been built using CMake we try to find everything directly
69 SET(FLTK_DIR_STRING "directory containing FLTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
71 # Search only if the location is not already known.
73 # Get the system search path as a list.
75 STRING(REGEX MATCHALL "[^:]+" FLTK_DIR_SEARCH1 "$ENV{PATH}")
77 STRING(REGEX REPLACE "\\\\" "/" FLTK_DIR_SEARCH1 "$ENV{PATH}")
79 STRING(REGEX REPLACE "/;" ";" FLTK_DIR_SEARCH2 ${FLTK_DIR_SEARCH1})
81 # Construct a set of paths relative to the system search path.
82 SET(FLTK_DIR_SEARCH "")
83 FOREACH(dir ${FLTK_DIR_SEARCH2})
84 SET(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
88 # Look for an installation or build tree.
90 FIND_PATH(FLTK_DIR FLTKConfig.cmake
91 # Look for an environment variable FLTK_DIR.
94 # Look in places relative to the system executable search path.
97 # Look in standard UNIX install locations.
105 # Read from the CMakeSetup registry entries. It is likely that
106 # FLTK will have been recently built.
107 # TODO: Is this really a good idea? I can already hear the user screaming, "But
108 # it worked when I configured the build LAST week!"
109 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
110 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
111 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
112 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
113 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
114 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
115 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
116 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
117 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
118 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
120 # Help the user find it if we cannot.
121 DOC "The ${FLTK_DIR_STRING}"
125 # Check if FLTK was built using CMake
126 IF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
127 SET(FLTK_BUILT_WITH_CMAKE 1)
128 ENDIF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
130 IF(FLTK_BUILT_WITH_CMAKE)
132 INCLUDE(${FLTK_DIR}/FLTKConfig.cmake)
136 SET(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
138 FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid PATHS
139 ${FLTK_EXECUTABLE_DIRS}
140 ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
141 ${FLTK_EXECUTABLE_DIRS}/Debug
142 ${FLTK_EXECUTABLE_DIRS}/Release
145 # MARK_AS_ADVANCED(FLTK_FLUID_EXECUTABLE)
147 SET(FLTK_INCLUDE_DIR ${FLTK_DIR})
148 LINK_DIRECTORIES(${FLTK_LIBRARY_DIRS})
150 SET(FLTK_BASE_LIBRARY fltk)
151 SET(FLTK_GL_LIBRARY fltk_gl)
152 SET(FLTK_FORMS_LIBRARY fltk_forms)
153 SET(FLTK_IMAGES_LIBRARY fltk_images)
155 # Add the extra libraries
156 LOAD_CACHE(${FLTK_DIR}
158 FL FLTK_USE_SYSTEM_JPEG
159 FL FLTK_USE_SYSTEM_PNG
160 FL FLTK_USE_SYSTEM_ZLIB
163 SET(FLTK_IMAGES_LIBS "")
164 IF(FLFLTK_USE_SYSTEM_JPEG)
165 SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
166 ENDIF(FLFLTK_USE_SYSTEM_JPEG)
167 IF(FLFLTK_USE_SYSTEM_PNG)
168 SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
169 ENDIF(FLFLTK_USE_SYSTEM_PNG)
170 IF(FLFLTK_USE_SYSTEM_ZLIB)
171 SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
172 ENDIF(FLFLTK_USE_SYSTEM_ZLIB)
173 SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
174 "Extra libraries for fltk_images library.")
176 ELSE(FLTK_BUILT_WITH_CMAKE)
178 # if FLTK was not built using CMake
179 # Find fluid executable.
180 FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
182 # Use location of fluid to help find everything else.
183 SET(FLTK_INCLUDE_SEARCH_PATH "")
184 SET(FLTK_LIBRARY_SEARCH_PATH "")
185 IF(FLTK_FLUID_EXECUTABLE)
186 GET_FILENAME_COMPONENT(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
187 SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
188 ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
189 SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
190 ${FLTK_BIN_DIR}/../lib)
192 ENDIF(FLTK_FLUID_EXECUTABLE)
195 # Try to find FLTK include dir using fltk-config
198 # Use fltk-config to generate a list of possible include directories
199 FIND_PROGRAM(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
200 IF(FLTK_CONFIG_SCRIPT)
201 IF(NOT FLTK_INCLUDE_DIR)
202 EXEC_PROGRAM(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
204 STRING(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
205 STRING(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
206 FOREACH(_dir ${_fltk_temp_dirs})
207 STRING(STRIP ${_dir} _output)
208 LIST(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
215 SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
218 ${_FLTK_POSSIBLE_INCLUDE_DIRS}
221 FIND_PATH(FLTK_INCLUDE_DIR
222 NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
223 PATHS ${FLTK_INCLUDE_SEARCH_PATH})
226 # Try to find FLTK library
228 IF(FLTK_CONFIG_SCRIPT)
229 EXEC_PROGRAM(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
230 IF(_FLTK_POSSIBLE_LIBS)
231 GET_FILENAME_COMPONENT(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
236 SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
239 ${FLTK_INCLUDE_DIR}/lib
240 ${_FLTK_POSSIBLE_LIBRARY_DIR}
243 FIND_LIBRARY(FLTK_BASE_LIBRARY NAMES fltk fltkd
244 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
245 FIND_LIBRARY(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
246 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
247 FIND_LIBRARY(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
248 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
249 FIND_LIBRARY(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
250 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
252 # Find the extra libraries needed for the fltk_images library.
254 IF(FLTK_CONFIG_SCRIPT)
255 EXEC_PROGRAM(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
256 OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
257 SET(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
258 IF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
259 STRING(REGEX REPLACE "${FLTK_LIBS_EXTRACT_REGEX}" "\\1"
260 FLTK_IMAGES_LIBS "${FLTK_IMAGES_LDFLAGS}")
261 STRING(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}")
262 # The EXEC_PROGRAM will not be inherited into subdirectories from
263 # the file that originally included this module. Save the answer.
264 SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
265 "Extra libraries for fltk_images library.")
266 ENDIF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
267 ENDIF(FLTK_CONFIG_SCRIPT)
270 ENDIF(FLTK_BUILT_WITH_CMAKE)
272 # Append all of the required libraries together (by default, everything)
274 IF(NOT FLTK_SKIP_IMAGES)
275 LIST(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
277 IF(NOT FLTK_SKIP_FORMS)
278 LIST(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
280 IF(NOT FLTK_SKIP_OPENGL)
281 LIST(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
282 LIST(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
283 LIST(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
285 LIST(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
287 INCLUDE(FindPackageHandleStandardArgs)
289 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
291 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
296 SET(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
298 SET(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
301 # The following deprecated settings are for compatibility with CMake 1.4
302 SET (HAS_FLTK ${FLTK_FOUND})
303 SET (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
304 SET (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
305 SET (FLTK_LIBRARY ${FLTK_LIBRARIES})