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 #=============================================================================
33 # Copyright 2001-2009 Kitware, Inc.
35 # Distributed under the OSI-approved BSD License (the "License");
36 # see accompanying file Copyright.txt for details.
38 # This software is distributed WITHOUT ANY WARRANTY; without even the
39 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
40 # See the License for more information.
41 #=============================================================================
42 # (To distribute this file outside of CMake, substitute the full
43 # License text for the above reference.)
45 if(NOT FLTK_SKIP_OPENGL)
49 # Platform dependent libraries required by FLTK
53 set( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
55 set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
62 find_library(FLTK_MATH_LIBRARY m)
63 set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
67 set( FLTK_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
70 # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
72 set(FLTK_DIR ${FLTK_INCLUDE_DIR})
76 # If FLTK has been built using CMake we try to find everything directly
77 set(FLTK_DIR_STRING "directory containing FLTKConfig.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
79 # Search only if the location is not already known.
81 # Get the system search path as a list.
82 file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
84 # Construct a set of paths relative to the system search path.
85 set(FLTK_DIR_SEARCH "")
86 foreach(dir ${FLTK_DIR_SEARCH2})
87 set(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
89 string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
92 # Look for an installation or build tree.
94 find_path(FLTK_DIR FLTKConfig.cmake
95 # Look for an environment variable FLTK_DIR.
99 # Look in places relative to the system executable search path.
103 # Look in standard UNIX install locations.
109 # Read from the CMakeSetup registry entries. It is likely that
110 # FLTK will have been recently built.
111 # TODO: Is this really a good idea? I can already hear the user screaming, "But
112 # it worked when I configured the build LAST week!"
113 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
114 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
115 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
116 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
117 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
118 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
119 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
120 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
121 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
122 [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
124 # Help the user find it if we cannot.
125 DOC "The ${FLTK_DIR_STRING}"
129 # Check if FLTK was built using CMake
130 if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
131 set(FLTK_BUILT_WITH_CMAKE 1)
134 if(FLTK_BUILT_WITH_CMAKE)
136 include(${FLTK_DIR}/FLTKConfig.cmake)
140 set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
142 find_program(FLTK_FLUID_EXECUTABLE fluid PATHS
143 ${FLTK_EXECUTABLE_DIRS}
144 ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
145 ${FLTK_EXECUTABLE_DIRS}/Debug
146 ${FLTK_EXECUTABLE_DIRS}/Release
149 # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
151 set(FLTK_INCLUDE_DIR ${FLTK_DIR})
152 link_directories(${FLTK_LIBRARY_DIRS})
154 set(FLTK_BASE_LIBRARY fltk)
155 set(FLTK_GL_LIBRARY fltk_gl)
156 set(FLTK_FORMS_LIBRARY fltk_forms)
157 set(FLTK_IMAGES_LIBRARY fltk_images)
159 # Add the extra libraries
160 load_cache(${FLTK_DIR}
162 FL FLTK_USE_SYSTEM_JPEG
163 FL FLTK_USE_SYSTEM_PNG
164 FL FLTK_USE_SYSTEM_ZLIB
167 set(FLTK_IMAGES_LIBS "")
168 if(FLFLTK_USE_SYSTEM_JPEG)
169 set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
171 if(FLFLTK_USE_SYSTEM_PNG)
172 set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
174 if(FLFLTK_USE_SYSTEM_ZLIB)
175 set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
177 set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
178 "Extra libraries for fltk_images library.")
182 # if FLTK was not built using CMake
183 # Find fluid executable.
184 find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
186 # Use location of fluid to help find everything else.
187 set(FLTK_INCLUDE_SEARCH_PATH "")
188 set(FLTK_LIBRARY_SEARCH_PATH "")
189 if(FLTK_FLUID_EXECUTABLE)
190 get_filename_component(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
191 set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
192 ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
193 set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
194 ${FLTK_BIN_DIR}/../lib)
199 # Try to find FLTK include dir using fltk-config
202 # Use fltk-config to generate a list of possible include directories
203 find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
204 if(FLTK_CONFIG_SCRIPT)
205 if(NOT FLTK_INCLUDE_DIR)
206 exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
208 string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
209 string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
210 foreach(_dir ${_fltk_temp_dirs})
211 string(STRIP ${_dir} _output)
212 list(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
219 set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
222 ${_FLTK_POSSIBLE_INCLUDE_DIRS}
225 find_path(FLTK_INCLUDE_DIR
226 NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
227 PATHS ${FLTK_INCLUDE_SEARCH_PATH})
230 # Try to find FLTK library
232 if(FLTK_CONFIG_SCRIPT)
233 exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
234 if(_FLTK_POSSIBLE_LIBS)
235 get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
240 set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
243 ${FLTK_INCLUDE_DIR}/lib
244 ${_FLTK_POSSIBLE_LIBRARY_DIR}
247 find_library(FLTK_BASE_LIBRARY NAMES fltk fltkd
248 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
249 find_library(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
250 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
251 find_library(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
252 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
253 find_library(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
254 PATHS ${FLTK_LIBRARY_SEARCH_PATH})
256 # Find the extra libraries needed for the fltk_images library.
258 if(FLTK_CONFIG_SCRIPT)
259 exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
260 OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
261 set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
262 if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
263 string(REGEX REPLACE "${FLTK_LIBS_EXTRACT_REGEX}" "\\1"
264 FLTK_IMAGES_LIBS "${FLTK_IMAGES_LDFLAGS}")
265 string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}")
266 # The EXEC_PROGRAM will not be inherited into subdirectories from
267 # the file that originally included this module. Save the answer.
268 set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
269 "Extra libraries for fltk_images library.")
276 # Append all of the required libraries together (by default, everything)
278 if(NOT FLTK_SKIP_IMAGES)
279 list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
281 if(NOT FLTK_SKIP_FORMS)
282 list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
284 if(NOT FLTK_SKIP_OPENGL)
285 list(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
286 list(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
287 list(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
289 list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
291 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
293 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
295 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
300 set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
302 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
305 # The following deprecated settings are for compatibility with CMake 1.4
306 set (HAS_FLTK ${FLTK_FOUND})
307 set (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
308 set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
309 set (FLTK_LIBRARY ${FLTK_LIBRARIES})