Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindFLTK.cmake
1 # - Find the native FLTK includes and library
2 #
3 # By default FindFLTK.cmake will search for all of the FLTK components and
4 # add them to the FLTK_LIBRARIES variable.
5 #
6 #   You can limit the components which get placed in FLTK_LIBRARIES by
7 #   defining one or more of the following three options:
8 #
9 #     FLTK_SKIP_OPENGL, set to true to disable searching for opengl and
10 #                       the FLTK GL library
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
13 #
14 #     FLTK_SKIP_FLUID, set to true if the fluid binary need not be present
15 #                      at build time
16 #
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
23 #
24 # The following cache variables are assigned but should not be used.
25 # See the FLTK_LIBRARIES variable instead.
26 #
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
31
32 #=============================================================================
33 # Copyright 2001-2009 Kitware, Inc.
34 #
35 # Distributed under the OSI-approved BSD License (the "License");
36 # see accompanying file Copyright.txt for details.
37 #
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.)
44
45 if(NOT FLTK_SKIP_OPENGL)
46   find_package(OpenGL)
47 endif()
48
49 #  Platform dependent libraries required by FLTK
50 if(WIN32)
51   if(NOT CYGWIN)
52     if(BORLAND)
53       set( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
54     else()
55       set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
56     endif()
57   endif()
58 endif()
59
60 if(UNIX)
61   include(FindX11)
62   find_library(FLTK_MATH_LIBRARY m)
63   set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
64 endif()
65
66 if(APPLE)
67   set( FLTK_PLATFORM_DEPENDENT_LIBS  "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
68 endif()
69
70 # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
71 if(FLTK_INCLUDE_DIR)
72   set(FLTK_DIR ${FLTK_INCLUDE_DIR})
73 endif()
74
75
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.")
78
79 # Search only if the location is not already known.
80 if(NOT FLTK_DIR)
81   # Get the system search path as a list.
82   file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
83
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")
88   endforeach()
89   string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
90
91   #
92   # Look for an installation or build tree.
93   #
94   find_path(FLTK_DIR FLTKConfig.cmake
95     # Look for an environment variable FLTK_DIR.
96     HINTS
97       ENV FLTK_DIR
98
99     # Look in places relative to the system executable search path.
100     ${FLTK_DIR_SEARCH}
101
102     PATHS
103     # Look in standard UNIX install locations.
104     /usr/local/lib/fltk
105     /usr/lib/fltk
106     /usr/local/fltk
107     /usr/X11R6/include
108
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]
123
124     # Help the user find it if we cannot.
125     DOC "The ${FLTK_DIR_STRING}"
126     )
127 endif()
128
129   # Check if FLTK was built using CMake
130   if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
131     set(FLTK_BUILT_WITH_CMAKE 1)
132   endif()
133
134   if(FLTK_BUILT_WITH_CMAKE)
135     set(FLTK_FOUND 1)
136     include(${FLTK_DIR}/FLTKConfig.cmake)
137
138     # Fluid
139     if(FLUID_COMMAND)
140       set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
141     else()
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
147         NO_SYSTEM_PATH)
148     endif()
149     # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
150
151     set(FLTK_INCLUDE_DIR ${FLTK_DIR})
152     link_directories(${FLTK_LIBRARY_DIRS})
153
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)
158
159     # Add the extra libraries
160     load_cache(${FLTK_DIR}
161       READ_WITH_PREFIX
162       FL FLTK_USE_SYSTEM_JPEG
163       FL FLTK_USE_SYSTEM_PNG
164       FL FLTK_USE_SYSTEM_ZLIB
165       )
166
167     set(FLTK_IMAGES_LIBS "")
168     if(FLFLTK_USE_SYSTEM_JPEG)
169       set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
170     endif()
171     if(FLFLTK_USE_SYSTEM_PNG)
172       set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
173     endif()
174     if(FLFLTK_USE_SYSTEM_ZLIB)
175       set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
176     endif()
177     set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
178       "Extra libraries for fltk_images library.")
179
180   else()
181
182     # if FLTK was not built using CMake
183     # Find fluid executable.
184     find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
185
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)
195       set(FLTK_WRAP_UI 1)
196     endif()
197
198     #
199     # Try to find FLTK include dir using fltk-config
200     #
201     if(UNIX)
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)
207           if(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})
213             endforeach()
214           endif()
215         endif()
216       endif()
217     endif()
218
219     set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
220       /usr/local/fltk
221       /usr/X11R6/include
222       ${_FLTK_POSSIBLE_INCLUDE_DIRS}
223       )
224
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})
228
229     #
230     # Try to find FLTK library
231     if(UNIX)
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)
236         endif()
237       endif()
238     endif()
239
240     set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
241       /usr/local/fltk/lib
242       /usr/X11R6/lib
243       ${FLTK_INCLUDE_DIR}/lib
244       ${_FLTK_POSSIBLE_LIBRARY_DIR}
245       )
246
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})
255
256     # Find the extra libraries needed for the fltk_images library.
257     if(UNIX)
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.")
270         endif()
271       endif()
272     endif()
273
274   endif()
275
276   # Append all of the required libraries together (by default, everything)
277   set(FLTK_LIBRARIES)
278   if(NOT FLTK_SKIP_IMAGES)
279     list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
280   endif()
281   if(NOT FLTK_SKIP_FORMS)
282     list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
283   endif()
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)
288   endif()
289   list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
290
291 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
292 if(FLTK_SKIP_FLUID)
293   FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
294 else()
295   FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
296 endif()
297
298 if(FLTK_FOUND)
299   if(APPLE)
300     set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
301   else()
302     set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
303   endif()
304
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})
310 endif()
311