File: FindFreeImage.cmake

package info (click to toggle)
ignition-cmake 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,132 kB
  • sloc: xml: 35,671; python: 3,768; javascript: 2,308; sh: 172; ansic: 109; cpp: 64; makefile: 7
file content (149 lines) | stat: -rw-r--r-- 4,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#===============================================================================
# Copyright (C) 2017 Open Source Robotics Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
########################################
# Find FreeImage

# Grab the version numbers requested by the call to find_package(~)
set(major_version ${FreeImage_FIND_VERSION_MAJOR})
set(minor_version ${FreeImage_FIND_VERSION_MINOR})

# Set the full version number
set(full_version ${major_version}.${minor_version})

if (NOT WIN32)
  include(IgnPkgConfig)
  ign_pkg_config_library_entry(FreeImage freeimage)

  # If we don't have PkgConfig, or if PkgConfig failed, then do a manual search
  if(NOT FreeImage_FOUND)

    find_path(FreeImage_INCLUDE_DIRS FreeImage.h)
    if(NOT FreeImage_INCLUDE_DIRS)

      if(NOT FreeImage_FIND_QUIETLY)
        message(STATUS "Looking for FreeImage.h - not found")
        message(STATUS "Missing: Unable to find FreeImage.h")
      endif()

    else(NOT FreeImage_INCLUDE_DIRS)
      # Check the FreeImage header for the right version
      set(testFreeImageSource ${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/test_freeimage.c)
      set(FreeImage_test_output "")
      set(FreeImage_compile_output "")
      file(WRITE ${testFreeImageSource}
        "#include <FreeImage.h>\nint main () { if (FREEIMAGE_MAJOR_VERSION >= ${major_version} && FREEIMAGE_MINOR_VERSION >= ${minor_version}) return 1; else return 0;} \n")

      try_run(FREEIMAGE_RUNS
              FREEIMAGE_COMPILES
              ${CMAKE_CURRENT_BINARY_DIR}
              ${testFreeImageSource}
              CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${FreeImage_INCLUDE_DIRS}
              RUN_OUTPUT_VARIABLE FreeImage_test_output
              COMPILE_OUTPUT_VARIABLE FreeImage_compile_output)

      if(NOT FREEIMAGE_COMPILES)

        if(NOT FreeImage_FIND_QUIETLY)
          message(STATUS "FreeImage test failed to compile - This may indicate a build system bug")
        endif()

        return()

      endif(NOT FREEIMAGE_COMPILES)

      if(NOT FREEIMAGE_RUNS)
        if(NOT FreeImage_FIND_QUIETLY)
          message(STATUS "Invalid FreeImage Version. Requires ${major_version}.${minor_version}")
        endif()
      endif(NOT FREEIMAGE_RUNS)

    endif(NOT FreeImage_INCLUDE_DIRS)
    mark_as_advanced(FreeImage_INCLUDE_DIRS)

    find_library(FreeImage_LIBRARIES NAMES freeimage FreeImage)
    if(FreeImage_LIBRARIES)
      set(FreeImage_FOUND true)
    else()
      if(NOT FreeImage_FIND_QUIELTY)
        message(STATUS "Missing: Unable to find libfreeimage")
      endif()
    endif(FreeImage_LIBRARIES)
    mark_as_advanced(FreeImage_LIBRARIES)

  endif()

  if(FreeImage_FOUND)
    # Create the imported target for FreeImage if we found it
    include(IgnImportTarget)
    ign_import_target(FreeImage)
  endif()

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(
    FreeImage
    REQUIRED_VARS FreeImage_FOUND)
else()
  # true by default, change to false when a failure appears
  set(FreeImage_FOUND true)

  # 1. look for FreeImage headers
  find_path(FreeImage_INCLUDE_DIRS FreeImage.h
    hints
      ${CMAKE_FIND_ROOT_PATH}
    paths
      ${CMAKE_FIND_ROOT_PATH}
    doc "FreeImage header include dir"
    path_suffixes
      include
  )

  if (FreeImage_INCLUDE_DIRS)
    if(NOT FreeImage_FIND_QUIETLY)
      message(STATUS "Looking for FreeImage.h FreeImageconfig.h - found")
    endif()
  else()
    if(NOT FreeImage_FIND_QUIETLY)
      message(STATUS "Looking for FreeImage.h FreeImageconfig.h - not found")
    endif()

    set(FreeImage_FOUND false)
  endif()
  mark_as_advanced(FreeImage_INCLUDE_DIRS)

  # 2. look for FreeImage libraries
  find_library(FreeImage_LIBRARIES FreeImage)
  mark_as_advanced(FreeImage_LIBRARIES)

  if (FreeImage_LIBRARIES)
    if(NOT FreeImage_FIND_QUIETLY)
      message(STATUS "Looking for FreeImage library - found")
    endif()
  else()
    if(NOT FreeImage_FIND_QUIETLY)
      message(STATUS "Looking for FreeImage library - not found")
    endif()

    set (FreeImage_FOUND false)
  endif()

  if (FreeImage_FOUND)
    include(IgnPkgConfig)
    ign_pkg_config_library_entry(FreeImage "FreeImage")
    include(IgnImportTarget)
    ign_import_target(FreeImage)
  endif()

endif()