ENH: fix bug where sharedforward would not work if there was a space in the path...
[cmake.git] / Modules / FindFLTK.cmake
blob1dc4a59b012461f4cdd6312d7c49e13278c86097
1 # - Find the native FLTK includes and library
2 # The following settings are defined
3 #  FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
4 #  FLTK_WRAP_UI, This enables the FLTK_WRAP_UI command
5 #  FLTK_INCLUDE_DIR, where to find include files
6 #  FLTK_LIBRARIES, list of fltk libraries
7 #  FLTK_FOUND, Don't use FLTK if false.
8 # The following settings should not be used in general.
9 #  FLTK_BASE_LIBRARY   = the full path to fltk.lib
10 #  FLTK_GL_LIBRARY     = the full path to fltk_gl.lib
11 #  FLTK_FORMS_LIBRARY  = the full path to fltk_forms.lib
12 #  FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
14 IF (FLTK_INCLUDE_DIR)
15   # Already in cache, be silent
16   SET(FLTK_FIND_QUIETLY TRUE)
17 ENDIF (FLTK_INCLUDE_DIR)
19 #  Platform dependent libraries required by FLTK
20 IF(WIN32)
21   IF(NOT CYGWIN)
22     IF(BORLAND)
23       SET( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
24     ELSE(BORLAND)
25       SET( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
26     ENDIF(BORLAND)
27   ENDIF(NOT CYGWIN)
28 ENDIF(WIN32)
30 IF(UNIX)
31   INCLUDE(${CMAKE_ROOT}/Modules/FindX11.cmake)
32   FIND_LIBRARY(FLTK_MATH_LIBRARY m)
33   SET( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
34 ENDIF(UNIX)
36 IF(APPLE)
37   SET( FLTK_PLATFORM_DEPENDENT_LIBS  "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
38 ENDIF(APPLE)
40 IF(CYGWIN)
41   FIND_LIBRARY(FLTK_MATH_LIBRARY m)
42   SET( FLTK_PLATFORM_DEPENDENT_LIBS ole32 uuid comctl32 wsock32 supc++ ${FLTK_MATH_LIBRARY} -lgdi32)
43 ENDIF(CYGWIN)
45 # If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
46 IF(FLTK_INCLUDE_DIR)
47   SET(FLTK_DIR ${FLTK_INCLUDE_DIR})
48 ENDIF(FLTK_INCLUDE_DIR)
51 # If FLTK has been built using CMake we try to find everything directly
52 SET(FLTK_DIR_STRING "directory containing FLTKConfig.cmake.  This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
54 # Search only if the location is not already known.
55 IF(NOT FLTK_DIR)
56   # Get the system search path as a list.
57   IF(UNIX)
58     STRING(REGEX MATCHALL "[^:]+" FLTK_DIR_SEARCH1 "$ENV{PATH}")
59   ELSE(UNIX)
60     STRING(REGEX REPLACE "\\\\" "/" FLTK_DIR_SEARCH1 "$ENV{PATH}")
61   ENDIF(UNIX)
62   STRING(REGEX REPLACE "/;" ";" FLTK_DIR_SEARCH2 ${FLTK_DIR_SEARCH1})
64   # Construct a set of paths relative to the system search path.
65   SET(FLTK_DIR_SEARCH "")
66   FOREACH(dir ${FLTK_DIR_SEARCH2})
67     SET(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
68   ENDFOREACH(dir)
70   #
71   # Look for an installation or build tree.
72   #
73   FIND_PATH(FLTK_DIR FLTKConfig.cmake
74     # Look for an environment variable FLTK_DIR.
75     $ENV{FLTK_DIR}
77     # Look in places relative to the system executable search path.
78     ${FLTK_DIR_SEARCH}
80     # Look in standard UNIX install locations.
81     /usr/local/lib/fltk
82     /usr/lib/fltk
83     /usr/local/include
84     /usr/include
85     /usr/local/fltk
86     /usr/X11R6/include
88     # Read from the CMakeSetup registry entries.  It is likely that
89     # FLTK will have been recently built.
90     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
91     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
92     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
93     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
94     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
95     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
96     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
97     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
98     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
99     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
101     # Help the user find it if we cannot.
102     DOC "The ${FLTK_DIR_STRING}"
103     )
104 ENDIF(NOT FLTK_DIR)
106   # Check if FLTK was built using CMake
107   IF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
108     SET(FLTK_BUILT_WITH_CMAKE 1)
109   ENDIF(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
111   IF(FLTK_BUILT_WITH_CMAKE)
112     SET(FLTK_FOUND 1)
113     INCLUDE(${FLTK_DIR}/FLTKConfig.cmake)
115     # Fluid
116     IF(FLUID_COMMAND) 
117       SET(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
118     ELSE(FLUID_COMMAND) 
119       FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid PATHS 
120         ${FLTK_EXECUTABLE_DIRS}
121         ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
122         ${FLTK_EXECUTABLE_DIRS}/Debug
123         ${FLTK_EXECUTABLE_DIRS}/Release
124         NO_SYSTEM_PATH)
125     ENDIF(FLUID_COMMAND)
126     # MARK_AS_ADVANCED(FLTK_FLUID_EXECUTABLE)
128     SET(FLTK_INCLUDE_DIR ${FLTK_DIR})
129     LINK_DIRECTORIES(${FLTK_LIBRARY_DIRS})
131     SET(FLTK_BASE_LIBRARY fltk)
132     SET(FLTK_GL_LIBRARY fltk_gl)
133     SET(FLTK_FORMS_LIBRARY fltk_forms)
134     SET(FLTK_IMAGES_LIBRARY fltk_images)
136     # Add the extra libraries
137     LOAD_CACHE(${FLTK_DIR}
138       READ_WITH_PREFIX
139       FL FLTK_USE_SYSTEM_JPEG
140       FL FLTK_USE_SYSTEM_PNG
141       FL FLTK_USE_SYSTEM_ZLIB
142       )
144     SET(FLTK_IMAGES_LIBS "")
145     IF(FLFLTK_USE_SYSTEM_JPEG)
146       SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
147     ENDIF(FLFLTK_USE_SYSTEM_JPEG)
148     IF(FLFLTK_USE_SYSTEM_PNG)
149       SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
150     ENDIF(FLFLTK_USE_SYSTEM_PNG)
151     IF(FLFLTK_USE_SYSTEM_ZLIB)
152       SET(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
153     ENDIF(FLFLTK_USE_SYSTEM_ZLIB)
154     SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
155       "Extra libraries for fltk_images library.")
157   ELSE(FLTK_BUILT_WITH_CMAKE)
159     # if FLTK was not built using CMake
160     # Find fluid executable.
161     FIND_PROGRAM(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
163     # Use location of fluid to help find everything else.
164     SET(FLTK_INCLUDE_SEARCH_PATH "")
165     SET(FLTK_LIBRARY_SEARCH_PATH "")
166     IF(FLTK_FLUID_EXECUTABLE)
167       GET_FILENAME_COMPONENT(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
168       SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
169         ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
170       SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
171         ${FLTK_BIN_DIR}/../lib)
172       SET(FLTK_WRAP_UI 1)
173     ENDIF(FLTK_FLUID_EXECUTABLE)
175     SET(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
176       /usr/local/fltk
177       /usr/X11R6/include
178       )
180     FIND_PATH(FLTK_INCLUDE_DIR FL/Fl.h ${FLTK_INCLUDE_SEARCH_PATH})
182     SET(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
183       /usr/local/fltk/lib
184       /usr/X11R6/lib
185       ${FLTK_INCLUDE_DIR}/lib
186       )
188     FIND_LIBRARY(FLTK_BASE_LIBRARY NAMES fltk fltkd
189       PATHS ${FLTK_LIBRARY_SEARCH_PATH})
190     FIND_LIBRARY(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
191       PATHS ${FLTK_LIBRARY_SEARCH_PATH})
192     FIND_LIBRARY(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
193       PATHS ${FLTK_LIBRARY_SEARCH_PATH})
194     FIND_LIBRARY(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
195       PATHS ${FLTK_LIBRARY_SEARCH_PATH})
197     # Find the extra libraries needed for the fltk_images library.
198     IF(UNIX)
199       FIND_PROGRAM(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
200       IF(FLTK_CONFIG_SCRIPT)
201         EXEC_PROGRAM(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
202           OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
203         SET(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
204         IF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
205           STRING(REGEX REPLACE "${FLTK_LIBS_EXTRACT_REGEX}" "\\1"
206             FLTK_IMAGES_LIBS "${FLTK_IMAGES_LDFLAGS}")
207           STRING(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}")
208           # The EXEC_PROGRAM will not be inherited into subdirectories from
209           # the file that originally included this module.  Save the answer.
210           SET(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
211             "Extra libraries for fltk_images library.")
212         ENDIF("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
213       ENDIF(FLTK_CONFIG_SCRIPT)
214     ENDIF(UNIX)
216   ENDIF(FLTK_BUILT_WITH_CMAKE)
219 SET(FLTK_FOUND 1)
220 FOREACH(var FLTK_FLUID_EXECUTABLE FLTK_INCLUDE_DIR
221     FLTK_BASE_LIBRARY FLTK_GL_LIBRARY
222     FLTK_FORMS_LIBRARY FLTK_IMAGES_LIBRARY)
223   IF(NOT ${var})
224     SET(FLTK_FOUND 0)
225   ENDIF(NOT ${var})
226 ENDFOREACH(var)
228 IF(FLTK_FOUND)
229   SET(FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY} ${FLTK_IMAGES_LIBS} ${FLTK_BASE_LIBRARY} ${FLTK_GL_LIBRARY}
230     ${FLTK_FORMS_LIBRARY} )
231   IF(APPLE)
232     SET(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
233   ELSE(APPLE)
234     SET(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
235   ENDIF(APPLE)
237   # The following deprecated settings are for compatibility with CMake 1.4
238   SET (HAS_FLTK ${FLTK_FOUND})
239   SET (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
240   SET (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
241   SET (FLTK_LIBRARY ${FLTK_LIBRARIES})
242 ENDIF(FLTK_FOUND)
244 INCLUDE(FindPackageHandleStandardArgs)
245 FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)