Updated formatting of documentation plus a little reorganization.
[cmake.git] / Modules / FindFLTK2.cmake
bloba434758136b12f183b3b7d27975c6ba79adfb8eb
1 # - Find the native FLTK2 includes and library
2 # The following settings are defined
3 #  FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
4 #  FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
5 #  FLTK2_INCLUDE_DIR, where to find include files
6 #  FLTK2_LIBRARIES, list of fltk2 libraries
7 #  FLTK2_FOUND, Don't use FLTK2 if false.
8 # The following settings should not be used in general.
9 #  FLTK2_BASE_LIBRARY   = the full path to fltk2.lib
10 #  FLTK2_GL_LIBRARY     = the full path to fltk2_gl.lib
11 #  FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib
13 SET (FLTK2_DIR $ENV{FLTK2_DIR} )
15 #  Platform dependent libraries required by FLTK2
16 IF(WIN32)
17   IF(NOT CYGWIN)
18     IF(BORLAND)
19       SET( FLTK2_PLATFORM_DEPENDENT_LIBS import32 )
20     ELSE(BORLAND)
21       SET( FLTK2_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
22     ENDIF(BORLAND)
23   ENDIF(NOT CYGWIN)
24 ENDIF(WIN32)
26 IF(UNIX)
27   INCLUDE(${CMAKE_ROOT}/Modules/FindX11.cmake)
28   SET( FLTK2_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
29 ENDIF(UNIX)
31 IF(APPLE)
32   SET( FLTK2_PLATFORM_DEPENDENT_LIBS  "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
33 ENDIF(APPLE)
35 IF(CYGWIN)
36   SET( FLTK2_PLATFORM_DEPENDENT_LIBS ole32 uuid comctl32 wsock32 supc++ -lm -lgdi32)
37 ENDIF(CYGWIN)
39 # If FLTK2_INCLUDE_DIR is already defined we assigne its value to FLTK2_DIR
40 IF(FLTK2_INCLUDE_DIR)
41   SET(FLTK2_DIR ${FLTK2_INCLUDE_DIR})
42 ELSE(FLTK2_INCLUDE_DIR)
43   SET(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
44 ENDIF(FLTK2_INCLUDE_DIR)
47 # If FLTK2 has been built using CMake we try to find everything directly
48 SET(FLTK2_DIR_STRING "directory containing FLTK2Config.cmake.  This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
50 # Search only if the location is not already known.
51 IF(NOT FLTK2_DIR)
52   # Get the system search path as a list.
53   IF(UNIX)
54     STRING(REGEX MATCHALL "[^:]+" FLTK2_DIR_SEARCH1 "$ENV{PATH}")
55   ELSE(UNIX)
56     STRING(REGEX REPLACE "\\\\" "/" FLTK2_DIR_SEARCH1 "$ENV{PATH}")
57   ENDIF(UNIX)
58   STRING(REGEX REPLACE "/;" ";" FLTK2_DIR_SEARCH2 ${FLTK2_DIR_SEARCH1})
60   # Construct a set of paths relative to the system search path.
61   SET(FLTK2_DIR_SEARCH "")
62   FOREACH(dir ${FLTK2_DIR_SEARCH2})
63     SET(FLTK2_DIR_SEARCH ${FLTK2_DIR_SEARCH} "${dir}/../lib/fltk")
64   ENDFOREACH(dir)
66   #
67   # Look for an installation or build tree.
68   #
69   FIND_PATH(FLTK2_DIR FLTK2Config.cmake
70     # Look for an environment variable FLTK2_DIR.
71     $ENV{FLTK2_DIR}
73     # Look in places relative to the system executable search path.
74     ${FLTK2_DIR_SEARCH}
76     # Look in standard UNIX install locations.
77     /usr/local/lib/fltk2
78     /usr/lib/fltk2
79     /usr/local/include
80     /usr/include
81     /usr/local/fltk2
82     /usr/X11R6/include
84     # Read from the CMakeSetup registry entries.  It is likely that
85     # FLTK2 will have been recently built.
86     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild1]
87     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild2]
88     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild3]
89     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild4]
90     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild5]
91     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild6]
92     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild7]
93     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild8]
94     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild9]
95     [HKEY_CURRENT_USER\\Software\\Kitware\\CMakeSetup\\Settings\\StartPath;WhereBuild10]
97     # Help the user find it if we cannot.
98     DOC "The ${FLTK2_DIR_STRING}"
99     )
101   IF(NOT FLTK2_DIR)
102     FIND_PATH(FLTK2_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
103   ENDIF(NOT FLTK2_DIR)
105 ENDIF(NOT FLTK2_DIR)
108 # If FLTK2 was found, load the configuration file to get the rest of the
109 # settings.
110 IF(FLTK2_DIR)
112   # Check if FLTK2 was built using CMake
113   IF(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
114     SET(FLTK2_BUILT_WITH_CMAKE 1)
115   ENDIF(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
117   IF(FLTK2_BUILT_WITH_CMAKE)
118     SET(FLTK2_FOUND 1)
119     INCLUDE(${FLTK2_DIR}/FLTK2Config.cmake)
121     # Fluid
122     IF(FLUID_COMMAND) 
123       SET(FLTK2_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
124     ELSE(FLUID_COMMAND) 
125       FIND_PROGRAM(FLTK2_FLUID_EXECUTABLE fluid2 PATHS 
126         ${FLTK2_EXECUTABLE_DIRS}
127         ${FLTK2_EXECUTABLE_DIRS}/RelWithDebInfo
128         ${FLTK2_EXECUTABLE_DIRS}/Debug
129         ${FLTK2_EXECUTABLE_DIRS}/Release
130         NO_SYSTEM_PATH)
131     ENDIF(FLUID_COMMAND)
133     MARK_AS_ADVANCED(FLTK2_FLUID_EXECUTABLE)
134     SET( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
136     
139     SET(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
140     LINK_DIRECTORIES(${FLTK2_LIBRARY_DIRS})
142     SET(FLTK2_BASE_LIBRARY fltk2)
143     SET(FLTK2_GL_LIBRARY fltk2_gl)
144     SET(FLTK2_IMAGES_LIBRARY fltk2_images)
146     # Add the extra libraries
147     LOAD_CACHE(${FLTK2_DIR}
148       READ_WITH_PREFIX
149       FL FLTK2_USE_SYSTEM_JPEG
150       FL FLTK2_USE_SYSTEM_PNG
151       FL FLTK2_USE_SYSTEM_ZLIB
152       )
154     SET(FLTK2_IMAGES_LIBS "")
155     IF(FLFLTK2_USE_SYSTEM_JPEG)
156       SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_jpeg)
157     ENDIF(FLFLTK2_USE_SYSTEM_JPEG)
158     IF(FLFLTK2_USE_SYSTEM_PNG)
159       SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_png)
160     ENDIF(FLFLTK2_USE_SYSTEM_PNG)
161     IF(FLFLTK2_USE_SYSTEM_ZLIB)
162       SET(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_zlib)
163     ENDIF(FLFLTK2_USE_SYSTEM_ZLIB)
164     SET(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
165       "Extra libraries for fltk2_images library.")
167   ELSE(FLTK2_BUILT_WITH_CMAKE)
169     # if FLTK2 was not built using CMake
170     # Find fluid executable.
171     FIND_PROGRAM(FLTK2_FLUID_EXECUTABLE fluid2 ${FLTK2_INCLUDE_DIR}/fluid)
173     # Use location of fluid to help find everything else.
174     SET(FLTK2_INCLUDE_SEARCH_PATH "")
175     SET(FLTK2_LIBRARY_SEARCH_PATH "")
176     IF(FLTK2_FLUID_EXECUTABLE)
177       SET( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
178       GET_FILENAME_COMPONENT(FLTK2_BIN_DIR "${FLTK2_FLUID_EXECUTABLE}" PATH)
179       SET(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
180         ${FLTK2_BIN_DIR}/../include ${FLTK2_BIN_DIR}/..)
181       SET(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
182         ${FLTK2_BIN_DIR}/../lib)
183       SET(FLTK2_WRAP_UI 1)
184     ENDIF(FLTK2_FLUID_EXECUTABLE)
186     SET(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
187       /usr/local/include
188       /usr/include
189       /usr/local/fltk2
190       /usr/X11R6/include
191       )
193     FIND_PATH(FLTK2_INCLUDE_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
195     SET(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
196       /usr/lib
197       /usr/local/lib
198       /usr/local/fltk2/lib
199       /usr/X11R6/lib
200       ${FLTK2_INCLUDE_DIR}/lib
201       )
203     FIND_LIBRARY(FLTK2_BASE_LIBRARY NAMES fltk2
204       PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
205     FIND_LIBRARY(FLTK2_GL_LIBRARY NAMES fltk2_gl 
206       PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
207     FIND_LIBRARY(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
208       PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
210     # Find the extra libraries needed for the fltk_images library.
211     IF(UNIX)
212       FIND_PROGRAM(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR})
213       IF(FLTK2_CONFIG_SCRIPT)
214         EXEC_PROGRAM(${FLTK2_CONFIG_SCRIPT} ARGS --use-images --ldflags
215           OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS)
216         SET(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*")
217         IF("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
218           STRING(REGEX REPLACE "${FLTK2_LIBS_EXTRACT_REGEX}" "\\1"
219             FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LDFLAGS}")
220           STRING(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}")
221           # The EXEC_PROGRAM will not be inherited into subdirectories from
222           # the file that originally included this module.  Save the answer.
223           SET(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
224             "Extra libraries for fltk_images library.")
225         ENDIF("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
226       ENDIF(FLTK2_CONFIG_SCRIPT)
227     ENDIF(UNIX)
229   ENDIF(FLTK2_BUILT_WITH_CMAKE)
230 ENDIF(FLTK2_DIR)
233 SET(FLTK2_FOUND 1)
234 FOREACH(var FLTK2_FLUID_EXECUTABLE FLTK2_INCLUDE_DIR
235     FLTK2_BASE_LIBRARY FLTK2_GL_LIBRARY
236     FLTK2_IMAGES_LIBRARY)
237   IF(NOT ${var})
238     MESSAGE( STATUS "${var} not found" )
239     SET(FLTK2_FOUND 0)
240   ENDIF(NOT ${var})
241 ENDFOREACH(var)
244 IF(FLTK2_FOUND)
245   SET(FLTK2_LIBRARIES ${FLTK2_IMAGES_LIBRARY} ${FLTK2_IMAGES_LIBS} ${FLTK2_BASE_LIBRARY} ${FLTK2_GL_LIBRARY} )
246   IF(APPLE)
247     SET(FLTK2_LIBRARIES ${FLTK2_PLATFORM_DEPENDENT_LIBS} ${FLTK2_LIBRARIES})
248   ELSE(APPLE)
249     SET(FLTK2_LIBRARIES ${FLTK2_LIBRARIES} ${FLTK2_PLATFORM_DEPENDENT_LIBS})
250   ENDIF(APPLE)
252   # The following deprecated settings are for compatibility with CMake 1.4
253   SET (HAS_FLTK2 ${FLTK2_FOUND})
254   SET (FLTK2_INCLUDE_PATH ${FLTK2_INCLUDE_DIR})
255   SET (FLTK2_FLUID_EXE ${FLTK2_FLUID_EXECUTABLE})
256   SET (FLTK2_LIBRARY ${FLTK2_LIBRARIES})
257 ELSE(FLTK2_FOUND)
258   # make FIND_PACKAGE friendly
259   IF(NOT FLTK2_FIND_QUIETLY)
260     IF(FLTK2_FIND_REQUIRED)
261       MESSAGE(FATAL_ERROR
262               "FLTK2 required, please specify its location with FLTK2_DIR.")
263     ELSE(FLTK2_FIND_REQUIRED)
264       MESSAGE(STATUS "FLTK2 was not found.")
265     ENDIF(FLTK2_FIND_REQUIRED)
266   ENDIF(NOT FLTK2_FIND_QUIETLY)
267 ENDIF(FLTK2_FOUND)