1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find the native FLTK 2.0 includes and library
10 The following settings are defined
14 FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
15 FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
16 FLTK2_INCLUDE_DIR, where to find include files
17 FLTK2_LIBRARIES, list of fltk2 libraries
18 FLTK2_FOUND, Don't use FLTK2 if false.
20 The following settings should not be used in general.
24 FLTK2_BASE_LIBRARY = the full path to fltk2.lib
25 FLTK2_GL_LIBRARY = the full path to fltk2_gl.lib
26 FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib
27 #]=======================================================================]
29 set (FLTK2_DIR $ENV{FLTK2_DIR} )
31 # Platform dependent libraries required by FLTK2
35 set( FLTK2_PLATFORM_DEPENDENT_LIBS import32 )
37 set( FLTK2_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
43 include(${CMAKE_ROOT}/Modules/FindX11.cmake)
44 set( FLTK2_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
48 set( FLTK2_PLATFORM_DEPENDENT_LIBS "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
51 # If FLTK2_INCLUDE_DIR is already defined we assign its value to FLTK2_DIR
53 set(FLTK2_DIR ${FLTK2_INCLUDE_DIR})
55 set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
59 # If FLTK2 has been built using CMake we try to find everything directly
60 set(FLTK2_DIR_STRING "directory containing FLTK2Config.cmake. This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
62 # Search only if the location is not already known.
64 # Get the system search path as a list.
65 file(TO_CMAKE_PATH "$ENV{PATH}" FLTK2_DIR_SEARCH2)
67 # Construct a set of paths relative to the system search path.
68 set(FLTK2_DIR_SEARCH "")
69 foreach(dir ${FLTK2_DIR_SEARCH2})
70 set(FLTK2_DIR_SEARCH ${FLTK2_DIR_SEARCH} "${dir}/../lib/fltk")
72 string(REPLACE "//" "/" FLTK2_DIR_SEARCH "${FLTK2_DIR_SEARCH}")
75 # Look for an installation or build tree.
77 find_path(FLTK2_DIR FLTK2Config.cmake
78 # Look for an environment variable FLTK2_DIR.
81 # Look in places relative to the system executable search path.
90 # Help the user find it if we cannot.
91 DOC "The ${FLTK2_DIR_STRING}"
95 find_path(FLTK2_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
101 # If FLTK2 was found, load the configuration file to get the rest of the
105 # Check if FLTK2 was built using CMake
106 if(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
107 set(FLTK2_BUILT_WITH_CMAKE 1)
110 if(FLTK2_BUILT_WITH_CMAKE)
112 include(${FLTK2_DIR}/FLTK2Config.cmake)
116 set(FLTK2_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
118 find_program(FLTK2_FLUID_EXECUTABLE fluid2 PATHS
119 ${FLTK2_EXECUTABLE_DIRS}
120 ${FLTK2_EXECUTABLE_DIRS}/RelWithDebInfo
121 ${FLTK2_EXECUTABLE_DIRS}/Debug
122 ${FLTK2_EXECUTABLE_DIRS}/Release
126 mark_as_advanced(FLTK2_FLUID_EXECUTABLE)
127 set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
132 set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
133 link_directories(${FLTK2_LIBRARY_DIRS})
135 set(FLTK2_BASE_LIBRARY fltk2)
136 set(FLTK2_GL_LIBRARY fltk2_gl)
137 set(FLTK2_IMAGES_LIBRARY fltk2_images)
139 # Add the extra libraries
140 load_cache(${FLTK2_DIR}
142 FLTK2_USE_SYSTEM_JPEG
144 FLTK2_USE_SYSTEM_ZLIB
147 set(FLTK2_IMAGES_LIBS "")
148 if(FLFLTK2_USE_SYSTEM_JPEG)
149 set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_jpeg)
151 if(FLFLTK2_USE_SYSTEM_PNG)
152 set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_png)
154 if(FLFLTK2_USE_SYSTEM_ZLIB)
155 set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_zlib)
157 set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
158 "Extra libraries for fltk2_images library.")
162 # if FLTK2 was not built using CMake
163 # Find fluid executable.
164 find_program(FLTK2_FLUID_EXECUTABLE fluid2 ${FLTK2_INCLUDE_DIR}/fluid)
166 # Use location of fluid to help find everything else.
167 set(FLTK2_INCLUDE_SEARCH_PATH "")
168 set(FLTK2_LIBRARY_SEARCH_PATH "")
169 if(FLTK2_FLUID_EXECUTABLE)
170 set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
171 get_filename_component(FLTK2_BIN_DIR "${FLTK2_FLUID_EXECUTABLE}" PATH)
172 set(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
173 ${FLTK2_BIN_DIR}/../include ${FLTK2_BIN_DIR}/..)
174 set(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
175 ${FLTK2_BIN_DIR}/../lib)
179 find_path(FLTK2_INCLUDE_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/include)
181 list(APPEND FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_INCLUDE_DIR}/lib)
183 find_library(FLTK2_BASE_LIBRARY NAMES fltk2
184 PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
185 find_library(FLTK2_GL_LIBRARY NAMES fltk2_gl
186 PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
187 find_library(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
188 PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
190 # Find the extra libraries needed for the fltk_images library.
192 find_program(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR})
193 if(FLTK2_CONFIG_SCRIPT)
194 execute_process(COMMAND ${FLTK2_CONFIG_SCRIPT} --use-images --ldflags
195 OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS)
196 set(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*")
197 if("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
198 string(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${CMAKE_MATCH_1}")
199 # The execute_process() will not be inherited into subdirectories from
200 # the file that originally included this module. Save the answer.
201 set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
202 "Extra libraries for fltk_images library.")
212 foreach(var FLTK2_FLUID_EXECUTABLE FLTK2_INCLUDE_DIR
213 FLTK2_BASE_LIBRARY FLTK2_GL_LIBRARY
214 FLTK2_IMAGES_LIBRARY)
216 message( STATUS "${var} not found" )
223 set(FLTK2_LIBRARIES ${FLTK2_IMAGES_LIBRARY} ${FLTK2_IMAGES_LIBS} ${FLTK2_BASE_LIBRARY} ${FLTK2_GL_LIBRARY} )
225 set(FLTK2_LIBRARIES ${FLTK2_PLATFORM_DEPENDENT_LIBS} ${FLTK2_LIBRARIES})
227 set(FLTK2_LIBRARIES ${FLTK2_LIBRARIES} ${FLTK2_PLATFORM_DEPENDENT_LIBS})
230 # The following deprecated settings are for compatibility with CMake 1.4
231 set (HAS_FLTK2 ${FLTK2_FOUND})
232 set (FLTK2_INCLUDE_PATH ${FLTK2_INCLUDE_DIR})
233 set (FLTK2_FLUID_EXE ${FLTK2_FLUID_EXECUTABLE})
234 set (FLTK2_LIBRARY ${FLTK2_LIBRARIES})
236 # make FIND_PACKAGE friendly
237 if(NOT FLTK2_FIND_QUIETLY)
238 if(FLTK2_FIND_REQUIRED)
240 "FLTK2 required, please specify its location with FLTK2_DIR.")
242 message(STATUS "FLTK2 was not found.")