FindFLTK.cmake 9.97 KB
Newer Older
1 2 3
#.rst:
# FindFLTK
# --------
4
#
5
# Find the native FLTK includes and library
6 7 8
#
#
#
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# By default FindFLTK.cmake will search for all of the FLTK components
# and add them to the FLTK_LIBRARIES variable.
#
# ::
#
#    You can limit the components which get placed in FLTK_LIBRARIES by
#    defining one or more of the following three options:
#
#
#
# ::
#
#      FLTK_SKIP_OPENGL, set to true to disable searching for opengl and
#                        the FLTK GL library
#      FLTK_SKIP_FORMS, set to true to disable searching for fltk_forms
#      FLTK_SKIP_IMAGES, set to true to disable searching for fltk_images
#
#
#
# ::
#
#      FLTK_SKIP_FLUID, set to true if the fluid binary need not be present
#                       at build time
#
#
34 35
#
# The following variables will be defined:
36 37 38 39 40 41 42 43 44 45
#
# ::
#
#      FLTK_FOUND, True if all components not skipped were found
#      FLTK_INCLUDE_DIR, where to find include files
#      FLTK_LIBRARIES, list of fltk libraries you should link against
#      FLTK_FLUID_EXECUTABLE, where to find the Fluid tool
#      FLTK_WRAP_UI, This enables the FLTK_WRAP_UI command
#
#
46 47 48 49
#
# The following cache variables are assigned but should not be used.
# See the FLTK_LIBRARIES variable instead.
#
50 51 52 53 54 55
# ::
#
#      FLTK_BASE_LIBRARY   = the full path to fltk.lib
#      FLTK_GL_LIBRARY     = the full path to fltk_gl.lib
#      FLTK_FORMS_LIBRARY  = the full path to fltk_forms.lib
#      FLTK_IMAGES_LIBRARY = the full path to fltk_images.lib
56

57 58 59 60 61 62 63 64 65 66
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
67
# (To distribute this file outside of CMake, substitute the full
68 69
#  License text for the above reference.)

70 71 72
if(NOT FLTK_SKIP_OPENGL)
  find_package(OpenGL)
endif()
73

74
#  Platform dependent libraries required by FLTK
75 76 77 78
if(WIN32)
  if(NOT CYGWIN)
    if(BORLAND)
      set( FLTK_PLATFORM_DEPENDENT_LIBS import32 )
79
    else()
80
      set( FLTK_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
81 82 83
    endif()
  endif()
endif()
84 85

if(UNIX)
86
  include(${CMAKE_CURRENT_LIST_DIR}/FindX11.cmake)
87 88
  find_library(FLTK_MATH_LIBRARY m)
  set( FLTK_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} ${FLTK_MATH_LIBRARY})
89
endif()
90 91 92

if(APPLE)
  set( FLTK_PLATFORM_DEPENDENT_LIBS  "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
93
endif()
94

95
# If FLTK_INCLUDE_DIR is already defined we assigne its value to FLTK_DIR
96 97
if(FLTK_INCLUDE_DIR)
  set(FLTK_DIR ${FLTK_INCLUDE_DIR})
98
endif()
99 100


101
# If FLTK has been built using CMake we try to find everything directly
102
set(FLTK_DIR_STRING "directory containing FLTKConfig.cmake.  This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
103 104

# Search only if the location is not already known.
105
if(NOT FLTK_DIR)
106
  # Get the system search path as a list.
107
  file(TO_CMAKE_PATH "$ENV{PATH}" FLTK_DIR_SEARCH2)
108 109

  # Construct a set of paths relative to the system search path.
110 111 112
  set(FLTK_DIR_SEARCH "")
  foreach(dir ${FLTK_DIR_SEARCH2})
    set(FLTK_DIR_SEARCH ${FLTK_DIR_SEARCH} "${dir}/../lib/fltk")
113
  endforeach()
114
  string(REPLACE "//" "/" FLTK_DIR_SEARCH "${FLTK_DIR_SEARCH}")
115 116 117 118

  #
  # Look for an installation or build tree.
  #
119
  find_path(FLTK_DIR FLTKConfig.cmake
120
    # Look for an environment variable FLTK_DIR.
121 122
    HINTS
      ENV FLTK_DIR
123 124 125 126

    # Look in places relative to the system executable search path.
    ${FLTK_DIR_SEARCH}

127
    PATHS
128 129 130 131 132 133 134 135 136
    # Look in standard UNIX install locations.
    /usr/local/lib/fltk
    /usr/lib/fltk
    /usr/local/fltk
    /usr/X11R6/include

    # Help the user find it if we cannot.
    DOC "The ${FLTK_DIR_STRING}"
    )
137
endif()
138 139

  # Check if FLTK was built using CMake
140 141
  if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
    set(FLTK_BUILT_WITH_CMAKE 1)
142
  endif()
143

144 145 146
  if(FLTK_BUILT_WITH_CMAKE)
    set(FLTK_FOUND 1)
    include(${FLTK_DIR}/FLTKConfig.cmake)
147 148

    # Fluid
149 150
    if(FLUID_COMMAND)
      set(FLTK_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
151
    else()
152
      find_program(FLTK_FLUID_EXECUTABLE fluid PATHS
153 154 155 156 157
        ${FLTK_EXECUTABLE_DIRS}
        ${FLTK_EXECUTABLE_DIRS}/RelWithDebInfo
        ${FLTK_EXECUTABLE_DIRS}/Debug
        ${FLTK_EXECUTABLE_DIRS}/Release
        NO_SYSTEM_PATH)
158
    endif()
159
    # mark_as_advanced(FLTK_FLUID_EXECUTABLE)
160

161 162
    set(FLTK_INCLUDE_DIR ${FLTK_DIR})
    link_directories(${FLTK_LIBRARY_DIRS})
163

164 165 166 167
    set(FLTK_BASE_LIBRARY fltk)
    set(FLTK_GL_LIBRARY fltk_gl)
    set(FLTK_FORMS_LIBRARY fltk_forms)
    set(FLTK_IMAGES_LIBRARY fltk_images)
168 169

    # Add the extra libraries
170
    load_cache(${FLTK_DIR}
171 172 173 174 175
      READ_WITH_PREFIX
      FL FLTK_USE_SYSTEM_JPEG
      FL FLTK_USE_SYSTEM_PNG
      FL FLTK_USE_SYSTEM_ZLIB
      )
176

177 178 179
    set(FLTK_IMAGES_LIBS "")
    if(FLFLTK_USE_SYSTEM_JPEG)
      set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_jpeg)
180
    endif()
181 182
    if(FLFLTK_USE_SYSTEM_PNG)
      set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_png)
183
    endif()
184 185
    if(FLFLTK_USE_SYSTEM_ZLIB)
      set(FLTK_IMAGES_LIBS ${FLTK_IMAGES_LIBS} fltk_zlib)
186
    endif()
187
    set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
188 189
      "Extra libraries for fltk_images library.")

190
  else()
191 192 193

    # if FLTK was not built using CMake
    # Find fluid executable.
194
    find_program(FLTK_FLUID_EXECUTABLE fluid ${FLTK_INCLUDE_DIR}/fluid)
195 196

    # Use location of fluid to help find everything else.
197 198 199 200 201
    set(FLTK_INCLUDE_SEARCH_PATH "")
    set(FLTK_LIBRARY_SEARCH_PATH "")
    if(FLTK_FLUID_EXECUTABLE)
      get_filename_component(FLTK_BIN_DIR "${FLTK_FLUID_EXECUTABLE}" PATH)
      set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
202
        ${FLTK_BIN_DIR}/../include ${FLTK_BIN_DIR}/..)
203
      set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
204
        ${FLTK_BIN_DIR}/../lib)
205
      set(FLTK_WRAP_UI 1)
206
    endif()
207

208
    #
209 210
    # Try to find FLTK include dir using fltk-config
    #
211
    if(UNIX)
212
      # Use fltk-config to generate a list of possible include directories
213 214 215 216 217 218 219 220 221 222 223
      find_program(FLTK_CONFIG_SCRIPT fltk-config PATHS ${FLTK_BIN_DIR})
      if(FLTK_CONFIG_SCRIPT)
        if(NOT FLTK_INCLUDE_DIR)
          exec_program(${FLTK_CONFIG_SCRIPT} ARGS --cxxflags OUTPUT_VARIABLE FLTK_CXXFLAGS)
          if(FLTK_CXXFLAGS)
            string(REGEX MATCHALL "-I[^ ]*" _fltk_temp_dirs ${FLTK_CXXFLAGS})
            string(REPLACE "-I" "" _fltk_temp_dirs "${_fltk_temp_dirs}")
            foreach(_dir ${_fltk_temp_dirs})
              string(STRIP ${_dir} _output)
              list(APPEND _FLTK_POSSIBLE_INCLUDE_DIRS ${_output})
            endforeach()
224
          endif()
225 226 227 228 229
        endif()
      endif()
    endif()

    set(FLTK_INCLUDE_SEARCH_PATH ${FLTK_INCLUDE_SEARCH_PATH}
230 231
      /usr/local/fltk
      /usr/X11R6/include
232
      ${_FLTK_POSSIBLE_INCLUDE_DIRS}
233
      )
234

235
    find_path(FLTK_INCLUDE_DIR
236 237
        NAMES FL/Fl.h FL/Fl.H    # fltk 1.1.9 has Fl.H (#8376)
        PATHS ${FLTK_INCLUDE_SEARCH_PATH})
238

239 240
    #
    # Try to find FLTK library
241 242 243 244 245 246 247 248 249 250
    if(UNIX)
      if(FLTK_CONFIG_SCRIPT)
        exec_program(${FLTK_CONFIG_SCRIPT} ARGS --libs OUTPUT_VARIABLE _FLTK_POSSIBLE_LIBS)
        if(_FLTK_POSSIBLE_LIBS)
          get_filename_component(_FLTK_POSSIBLE_LIBRARY_DIR ${_FLTK_POSSIBLE_LIBS} PATH)
        endif()
      endif()
    endif()

    set(FLTK_LIBRARY_SEARCH_PATH ${FLTK_LIBRARY_SEARCH_PATH}
251 252 253
      /usr/local/fltk/lib
      /usr/X11R6/lib
      ${FLTK_INCLUDE_DIR}/lib
254
      ${_FLTK_POSSIBLE_LIBRARY_DIR}
255
      )
256

257
    find_library(FLTK_BASE_LIBRARY NAMES fltk fltkd
258
      PATHS ${FLTK_LIBRARY_SEARCH_PATH})
259
    find_library(FLTK_GL_LIBRARY NAMES fltkgl fltkgld fltk_gl
260
      PATHS ${FLTK_LIBRARY_SEARCH_PATH})
261
    find_library(FLTK_FORMS_LIBRARY NAMES fltkforms fltkformsd fltk_forms
262
      PATHS ${FLTK_LIBRARY_SEARCH_PATH})
263
    find_library(FLTK_IMAGES_LIBRARY NAMES fltkimages fltkimagesd fltk_images
264 265 266
      PATHS ${FLTK_LIBRARY_SEARCH_PATH})

    # Find the extra libraries needed for the fltk_images library.
267 268 269
    if(UNIX)
      if(FLTK_CONFIG_SCRIPT)
        exec_program(${FLTK_CONFIG_SCRIPT} ARGS --use-images --ldflags
270
          OUTPUT_VARIABLE FLTK_IMAGES_LDFLAGS)
271 272
        set(FLTK_LIBS_EXTRACT_REGEX ".*-lfltk_images (.*) -lfltk.*")
        if("${FLTK_IMAGES_LDFLAGS}" MATCHES "${FLTK_LIBS_EXTRACT_REGEX}")
273
          string(REGEX REPLACE " +" ";" FLTK_IMAGES_LIBS "${CMAKE_MATCH_1}")
274 275
          # The EXEC_PROGRAM will not be inherited into subdirectories from
          # the file that originally included this module.  Save the answer.
276
          set(FLTK_IMAGES_LIBS "${FLTK_IMAGES_LIBS}" CACHE INTERNAL
277
            "Extra libraries for fltk_images library.")
278 279 280
        endif()
      endif()
    endif()
281

282
  endif()
283

284
  # Append all of the required libraries together (by default, everything)
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
  set(FLTK_LIBRARIES)
  if(NOT FLTK_SKIP_IMAGES)
    list(APPEND FLTK_LIBRARIES ${FLTK_IMAGES_LIBRARY})
  endif()
  if(NOT FLTK_SKIP_FORMS)
    list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
  endif()
  if(NOT FLTK_SKIP_OPENGL)
    list(APPEND FLTK_LIBRARIES ${FLTK_GL_LIBRARY} ${OPENGL_gl_LIBRARY})
    list(APPEND FLTK_INCLUDE_DIR ${OPENGL_INCLUDE_DIR})
    list(REMOVE_DUPLICATES FLTK_INCLUDE_DIR)
  endif()
  list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})

include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
if(FLTK_SKIP_FLUID)
301
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR)
302
else()
303
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(FLTK DEFAULT_MSG FLTK_LIBRARIES FLTK_INCLUDE_DIR FLTK_FLUID_EXECUTABLE)
304
endif()
305

306 307 308
if(FLTK_FOUND)
  if(APPLE)
    set(FLTK_LIBRARIES ${FLTK_PLATFORM_DEPENDENT_LIBS} ${FLTK_LIBRARIES})
309
  else()
310
    set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${FLTK_PLATFORM_DEPENDENT_LIBS})
311
  endif()
312 313

  # The following deprecated settings are for compatibility with CMake 1.4
314 315 316 317
  set (HAS_FLTK ${FLTK_FOUND})
  set (FLTK_INCLUDE_PATH ${FLTK_INCLUDE_DIR})
  set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
  set (FLTK_LIBRARY ${FLTK_LIBRARIES})
318
endif()
319