FindFLTK2.cmake 7.97 KB
Newer Older
1 2 3 4 5 6
#.rst:
# FindFLTK2
# ---------
#
# Find the native FLTK2 includes and library
#
Bill Hoffman's avatar
Bill Hoffman committed
7
# The following settings are defined
8 9 10 11 12 13 14 15 16
#
# ::
#
#   FLTK2_FLUID_EXECUTABLE, where to find the Fluid tool
#   FLTK2_WRAP_UI, This enables the FLTK2_WRAP_UI command
#   FLTK2_INCLUDE_DIR, where to find include files
#   FLTK2_LIBRARIES, list of fltk2 libraries
#   FLTK2_FOUND, Don't use FLTK2 if false.
#
Bill Hoffman's avatar
Bill Hoffman committed
17
# The following settings should not be used in general.
18 19 20 21 22 23
#
# ::
#
#   FLTK2_BASE_LIBRARY   = the full path to fltk2.lib
#   FLTK2_GL_LIBRARY     = the full path to fltk2_gl.lib
#   FLTK2_IMAGES_LIBRARY = the full path to fltk2_images.lib
Bill Hoffman's avatar
Bill Hoffman committed
24

25 26 27 28 29 30 31 32 33 34
#=============================================================================
# Copyright 2007-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.
#=============================================================================
35
# (To distribute this file outside of CMake, substitute the full
36 37
#  License text for the above reference.)

38
set (FLTK2_DIR $ENV{FLTK2_DIR} )
Bill Hoffman's avatar
Bill Hoffman committed
39 40

#  Platform dependent libraries required by FLTK2
41 42 43 44
if(WIN32)
  if(NOT CYGWIN)
    if(BORLAND)
      set( FLTK2_PLATFORM_DEPENDENT_LIBS import32 )
45
    else()
46
      set( FLTK2_PLATFORM_DEPENDENT_LIBS wsock32 comctl32 )
47 48 49
    endif()
  endif()
endif()
50 51 52 53

if(UNIX)
  include(${CMAKE_ROOT}/Modules/FindX11.cmake)
  set( FLTK2_PLATFORM_DEPENDENT_LIBS ${X11_LIBRARIES} -lm)
54
endif()
55 56 57

if(APPLE)
  set( FLTK2_PLATFORM_DEPENDENT_LIBS  "-framework Carbon -framework Cocoa -framework ApplicationServices -lz")
58
endif()
Bill Hoffman's avatar
Bill Hoffman committed
59

60
# If FLTK2_INCLUDE_DIR is already defined we assign its value to FLTK2_DIR
61 62
if(FLTK2_INCLUDE_DIR)
  set(FLTK2_DIR ${FLTK2_INCLUDE_DIR})
63
else()
64
  set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
65
endif()
Bill Hoffman's avatar
Bill Hoffman committed
66 67 68


# If FLTK2 has been built using CMake we try to find everything directly
69
set(FLTK2_DIR_STRING "directory containing FLTK2Config.cmake.  This is either the root of the build tree, or PREFIX/lib/fltk for an installation.")
Bill Hoffman's avatar
Bill Hoffman committed
70 71

# Search only if the location is not already known.
72
if(NOT FLTK2_DIR)
Bill Hoffman's avatar
Bill Hoffman committed
73
  # Get the system search path as a list.
74
  file(TO_CMAKE_PATH "$ENV{PATH}" FLTK2_DIR_SEARCH2)
Bill Hoffman's avatar
Bill Hoffman committed
75 76

  # Construct a set of paths relative to the system search path.
77 78 79
  set(FLTK2_DIR_SEARCH "")
  foreach(dir ${FLTK2_DIR_SEARCH2})
    set(FLTK2_DIR_SEARCH ${FLTK2_DIR_SEARCH} "${dir}/../lib/fltk")
80
  endforeach()
81
  string(REPLACE "//" "/" FLTK2_DIR_SEARCH "${FLTK2_DIR_SEARCH}")
Bill Hoffman's avatar
Bill Hoffman committed
82 83 84 85

  #
  # Look for an installation or build tree.
  #
86
  find_path(FLTK2_DIR FLTK2Config.cmake
Bill Hoffman's avatar
Bill Hoffman committed
87
    # Look for an environment variable FLTK2_DIR.
88
    ENV FLTK2_DIR
Bill Hoffman's avatar
Bill Hoffman committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102

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

    # Look in standard UNIX install locations.
    /usr/local/lib/fltk2
    /usr/lib/fltk2
    /usr/local/fltk2
    /usr/X11R6/include

    # Help the user find it if we cannot.
    DOC "The ${FLTK2_DIR_STRING}"
    )

103 104
  if(NOT FLTK2_DIR)
    find_path(FLTK2_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
105
  endif()
Bill Hoffman's avatar
Bill Hoffman committed
106

107
endif()
Bill Hoffman's avatar
Bill Hoffman committed
108 109 110 111


# If FLTK2 was found, load the configuration file to get the rest of the
# settings.
112
if(FLTK2_DIR)
Bill Hoffman's avatar
Bill Hoffman committed
113 114

  # Check if FLTK2 was built using CMake
115 116
  if(EXISTS ${FLTK2_DIR}/FLTK2Config.cmake)
    set(FLTK2_BUILT_WITH_CMAKE 1)
117
  endif()
Bill Hoffman's avatar
Bill Hoffman committed
118

119 120 121
  if(FLTK2_BUILT_WITH_CMAKE)
    set(FLTK2_FOUND 1)
    include(${FLTK2_DIR}/FLTK2Config.cmake)
Bill Hoffman's avatar
Bill Hoffman committed
122 123

    # Fluid
124 125
    if(FLUID_COMMAND)
      set(FLTK2_FLUID_EXECUTABLE ${FLUID_COMMAND} CACHE FILEPATH "Fluid executable")
126
    else()
127
      find_program(FLTK2_FLUID_EXECUTABLE fluid2 PATHS
Bill Hoffman's avatar
Bill Hoffman committed
128 129 130 131 132
        ${FLTK2_EXECUTABLE_DIRS}
        ${FLTK2_EXECUTABLE_DIRS}/RelWithDebInfo
        ${FLTK2_EXECUTABLE_DIRS}/Debug
        ${FLTK2_EXECUTABLE_DIRS}/Release
        NO_SYSTEM_PATH)
133
    endif()
Bill Hoffman's avatar
Bill Hoffman committed
134

135 136
    mark_as_advanced(FLTK2_FLUID_EXECUTABLE)
    set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
Bill Hoffman's avatar
Bill Hoffman committed
137

138

Bill Hoffman's avatar
Bill Hoffman committed
139 140


141 142
    set(FLTK2_INCLUDE_DIR ${FLTK2_DIR})
    link_directories(${FLTK2_LIBRARY_DIRS})
Bill Hoffman's avatar
Bill Hoffman committed
143

144 145 146
    set(FLTK2_BASE_LIBRARY fltk2)
    set(FLTK2_GL_LIBRARY fltk2_gl)
    set(FLTK2_IMAGES_LIBRARY fltk2_images)
Bill Hoffman's avatar
Bill Hoffman committed
147 148

    # Add the extra libraries
149
    load_cache(${FLTK2_DIR}
Bill Hoffman's avatar
Bill Hoffman committed
150 151 152 153 154 155
      READ_WITH_PREFIX
      FL FLTK2_USE_SYSTEM_JPEG
      FL FLTK2_USE_SYSTEM_PNG
      FL FLTK2_USE_SYSTEM_ZLIB
      )

156 157 158
    set(FLTK2_IMAGES_LIBS "")
    if(FLFLTK2_USE_SYSTEM_JPEG)
      set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_jpeg)
159
    endif()
160 161
    if(FLFLTK2_USE_SYSTEM_PNG)
      set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_png)
162
    endif()
163 164
    if(FLFLTK2_USE_SYSTEM_ZLIB)
      set(FLTK2_IMAGES_LIBS ${FLTK2_IMAGES_LIBS} fltk2_zlib)
165
    endif()
166
    set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
Bill Hoffman's avatar
Bill Hoffman committed
167 168
      "Extra libraries for fltk2_images library.")

169
  else()
Bill Hoffman's avatar
Bill Hoffman committed
170 171 172

    # if FLTK2 was not built using CMake
    # Find fluid executable.
173
    find_program(FLTK2_FLUID_EXECUTABLE fluid2 ${FLTK2_INCLUDE_DIR}/fluid)
Bill Hoffman's avatar
Bill Hoffman committed
174 175

    # Use location of fluid to help find everything else.
176 177 178 179 180 181
    set(FLTK2_INCLUDE_SEARCH_PATH "")
    set(FLTK2_LIBRARY_SEARCH_PATH "")
    if(FLTK2_FLUID_EXECUTABLE)
      set( FLTK_FLUID_EXECUTABLE ${FLTK2_FLUID_EXECUTABLE} )
      get_filename_component(FLTK2_BIN_DIR "${FLTK2_FLUID_EXECUTABLE}" PATH)
      set(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
Bill Hoffman's avatar
Bill Hoffman committed
182
        ${FLTK2_BIN_DIR}/../include ${FLTK2_BIN_DIR}/..)
183
      set(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
Bill Hoffman's avatar
Bill Hoffman committed
184
        ${FLTK2_BIN_DIR}/../lib)
185
      set(FLTK2_WRAP_UI 1)
186
    endif()
Bill Hoffman's avatar
Bill Hoffman committed
187

188
    set(FLTK2_INCLUDE_SEARCH_PATH ${FLTK2_INCLUDE_SEARCH_PATH}
Bill Hoffman's avatar
Bill Hoffman committed
189 190 191 192
      /usr/local/fltk2
      /usr/X11R6/include
      )

193
    find_path(FLTK2_INCLUDE_DIR fltk/run.h ${FLTK2_INCLUDE_SEARCH_PATH})
Bill Hoffman's avatar
Bill Hoffman committed
194

195
    set(FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_LIBRARY_SEARCH_PATH}
Bill Hoffman's avatar
Bill Hoffman committed
196 197 198 199 200
      /usr/local/fltk2/lib
      /usr/X11R6/lib
      ${FLTK2_INCLUDE_DIR}/lib
      )

201
    find_library(FLTK2_BASE_LIBRARY NAMES fltk2
Bill Hoffman's avatar
Bill Hoffman committed
202
      PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
203
    find_library(FLTK2_GL_LIBRARY NAMES fltk2_gl
Bill Hoffman's avatar
Bill Hoffman committed
204
      PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
205
    find_library(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
Bill Hoffman's avatar
Bill Hoffman committed
206 207 208
      PATHS ${FLTK2_LIBRARY_SEARCH_PATH})

    # Find the extra libraries needed for the fltk_images library.
209 210 211 212
    if(UNIX)
      find_program(FLTK2_CONFIG_SCRIPT fltk2-config PATHS ${FLTK2_BIN_DIR})
      if(FLTK2_CONFIG_SCRIPT)
        exec_program(${FLTK2_CONFIG_SCRIPT} ARGS --use-images --ldflags
Bill Hoffman's avatar
Bill Hoffman committed
213
          OUTPUT_VARIABLE FLTK2_IMAGES_LDFLAGS)
214 215
        set(FLTK2_LIBS_EXTRACT_REGEX ".*-lfltk2_images (.*) -lfltk2.*")
        if("${FLTK2_IMAGES_LDFLAGS}" MATCHES "${FLTK2_LIBS_EXTRACT_REGEX}")
216
          string(REGEX REPLACE " +" ";" FLTK2_IMAGES_LIBS "${CMAKE_MATCH_1}")
Bill Hoffman's avatar
Bill Hoffman committed
217 218
          # The EXEC_PROGRAM will not be inherited into subdirectories from
          # the file that originally included this module.  Save the answer.
219
          set(FLTK2_IMAGES_LIBS "${FLTK2_IMAGES_LIBS}" CACHE INTERNAL
Bill Hoffman's avatar
Bill Hoffman committed
220
            "Extra libraries for fltk_images library.")
221 222 223
        endif()
      endif()
    endif()
Bill Hoffman's avatar
Bill Hoffman committed
224

225 226
  endif()
endif()
Bill Hoffman's avatar
Bill Hoffman committed
227 228


229 230
set(FLTK2_FOUND 1)
foreach(var FLTK2_FLUID_EXECUTABLE FLTK2_INCLUDE_DIR
Bill Hoffman's avatar
Bill Hoffman committed
231 232
    FLTK2_BASE_LIBRARY FLTK2_GL_LIBRARY
    FLTK2_IMAGES_LIBRARY)
233 234 235
  if(NOT ${var})
    message( STATUS "${var} not found" )
    set(FLTK2_FOUND 0)
236 237
  endif()
endforeach()
Bill Hoffman's avatar
Bill Hoffman committed
238 239


240 241 242 243
if(FLTK2_FOUND)
  set(FLTK2_LIBRARIES ${FLTK2_IMAGES_LIBRARY} ${FLTK2_IMAGES_LIBS} ${FLTK2_BASE_LIBRARY} ${FLTK2_GL_LIBRARY} )
  if(APPLE)
    set(FLTK2_LIBRARIES ${FLTK2_PLATFORM_DEPENDENT_LIBS} ${FLTK2_LIBRARIES})
244
  else()
245
    set(FLTK2_LIBRARIES ${FLTK2_LIBRARIES} ${FLTK2_PLATFORM_DEPENDENT_LIBS})
246
  endif()
Bill Hoffman's avatar
Bill Hoffman committed
247 248

  # The following deprecated settings are for compatibility with CMake 1.4
249 250 251 252
  set (HAS_FLTK2 ${FLTK2_FOUND})
  set (FLTK2_INCLUDE_PATH ${FLTK2_INCLUDE_DIR})
  set (FLTK2_FLUID_EXE ${FLTK2_FLUID_EXECUTABLE})
  set (FLTK2_LIBRARY ${FLTK2_LIBRARIES})
253
else()
Bill Hoffman's avatar
Bill Hoffman committed
254
  # make FIND_PACKAGE friendly
255 256 257
  if(NOT FLTK2_FIND_QUIETLY)
    if(FLTK2_FIND_REQUIRED)
      message(FATAL_ERROR
Bill Hoffman's avatar
Bill Hoffman committed
258
              "FLTK2 required, please specify its location with FLTK2_DIR.")
259
    else()
260
      message(STATUS "FLTK2 was not found.")
261 262 263
    endif()
  endif()
endif()
Bill Hoffman's avatar
Bill Hoffman committed
264