Skip to content

Commit 624eaf7

Browse files
lgritzCopilot
andcommitted
build: Use libheif exported config if available (#5012)
Needed to change the Libheif::Libheif target we set up ages ago to the "heif" name that the package's exported config uses. Also, need to give the warning about static libraries occur any time we are using static libheif, even if we didn't set LIBSTATIC to try to force all static libraries. --------- Signed-off-by: Larry Gritz <lg@larrygritz.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 269457a commit 624eaf7

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

src/cmake/externalpackages.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ checked_find_package (GIF VERSION_MIN 5.0)
163163

164164
# For HEIF/HEIC/AVIF formats
165165
checked_find_package (Libheif VERSION_MIN 1.11
166+
PREFER_CONFIG
166167
RECOMMEND_MIN 1.16
167168
RECOMMEND_MIN_REASON "for orientation support")
168169

src/cmake/modules/FindLibheif.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ find_library (LIBHEIF_LIBRARY heif
2727
HINTS
2828
${LIBHEIF_LIBRARY_PATH}
2929
ENV LIBHEIF_LIBRARY_PATH
30-
DOC "The directory where libheif libraries reside")
30+
DOC "The found libheif library")
3131

3232
if (LIBHEIF_INCLUDE_DIR)
3333
file(STRINGS "${LIBHEIF_INCLUDE_DIR}/libheif/heif_version.h" TMP REGEX "^#define LIBHEIF_VERSION[ \t].*$")
@@ -44,11 +44,11 @@ if (Libheif_FOUND)
4444
set(LIBHEIF_INCLUDES "${LIBHEIF_INCLUDE_DIR}")
4545
set(LIBHEIF_LIBRARIES "${LIBHEIF_LIBRARY}")
4646

47-
if (NOT TARGET Libheif::Libheif)
48-
add_library(Libheif::Libheif UNKNOWN IMPORTED)
49-
set_target_properties(Libheif::Libheif PROPERTIES
47+
if (NOT TARGET heif)
48+
add_library(heif UNKNOWN IMPORTED)
49+
set_target_properties(heif PROPERTIES
5050
INTERFACE_INCLUDE_DIRECTORIES "${LIBHEIF_INCLUDES}")
51-
set_property(TARGET Libheif::Libheif APPEND PROPERTY
51+
set_property(TARGET heif APPEND PROPERTY
5252
IMPORTED_LOCATION "${LIBHEIF_LIBRARIES}")
5353
endif ()
5454
endif()

src/heif.imageio/CMakeLists.txt

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,27 @@
33
# https://github.com/AcademySoftwareFoundation/OpenImageIO
44

55
if (Libheif_FOUND)
6-
if (LINKSTATIC)
7-
set (_static_suffixes .lib .a)
8-
set (_static_libraries_found 0)
9-
10-
foreach (_libeheif_library IN LISTS LIBHEIF_LIBRARIES)
11-
get_filename_component (_ext ${_libeheif_library} LAST_EXT)
12-
list (FIND _static_suffixes ${_ext} _index)
13-
if (${_index} GREATER -1)
14-
MATH (EXPR _static_libraries_found "${static_libraries_found}+1")
15-
endif()
16-
endforeach()
17-
18-
if (${_static_libraries_found} GREATER 0)
19-
message (STATUS "${ColorYellow}")
20-
message (STATUS "You are linking OpenImageIO against a static version of libheif, which is LGPL")
21-
message (STATUS "licensed. If you intend to redistribute this build of OpenImageIO, we recommend")
22-
message (STATUS "that you review the libheif license terms, or you may wish to switch to using a")
23-
message (STATUS "dynamically-linked libheif.")
24-
message ("${ColorReset}")
6+
# Some extra care is needed if the libheif we found was static
7+
set (_static_suffixes .lib .a)
8+
set (_static_libraries_found 0)
9+
foreach (_libeheif_library IN LISTS LIBHEIF_LIBRARIES)
10+
get_filename_component (_ext ${_libeheif_library} LAST_EXT)
11+
list (FIND _static_suffixes ${_ext} _index)
12+
if (${_index} GREATER -1)
13+
MATH (EXPR _static_libraries_found "${_static_libraries_found}+1")
2514
endif()
15+
endforeach()
16+
if (${_static_libraries_found} GREATER 0)
17+
message (STATUS "${ColorYellow}")
18+
message (STATUS "You are linking OpenImageIO against a static version of libheif, which is LGPL")
19+
message (STATUS "licensed. If you intend to redistribute this build of OpenImageIO, we recommend")
20+
message (STATUS "that you review the libheif license terms, or you may wish to switch to using a")
21+
message (STATUS "dynamically-linked libheif.")
22+
message ("${ColorReset}")
2623
endif()
2724

2825
add_oiio_plugin (heifinput.cpp heifoutput.cpp
29-
INCLUDE_DIRS ${LIBHEIF_INCLUDES}
30-
LINK_LIBRARIES ${LIBHEIF_LIBRARIES}
26+
LINK_LIBRARIES heif
3127
DEFINITIONS "USE_HEIF=1")
3228
else ()
3329
message (WARNING "heif plugin will not be built")

0 commit comments

Comments
 (0)