Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cmake config for libdeflate #1613

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,47 @@ set(OPENEXR_DEFLATE_TAG "v1.18" CACHE STRING "Tag to use for libdeflate source r
if(NOT OPENEXR_FORCE_INTERNAL_DEFLATE)
#TODO: ^^ Release should not clone from main, this is a place holder
set(CMAKE_IGNORE_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/deflate-src/config;${CMAKE_CURRENT_BINARY_DIR}/_deps/deflate-build/config")
include(FindPkgConfig)
pkg_check_modules(deflate IMPORTED_TARGET GLOBAL libdeflate)
set(CMAKE_IGNORE_PATH)
if (deflate_FOUND)
message(STATUS "Using libdeflate from ${deflate_LINK_LIBRARIES}")
# First try cmake config
find_package(libdeflate CONFIG)
if(libdeflate_FOUND)
if(TARGET libdeflate::libdeflate_shared)
set(EXR_DEFLATE_LIB libdeflate::libdeflate_shared)
else()
set(EXR_DEFLATE_LIB libdeflate::libdeflate_static)
endif()
set(EXR_DEFLATE_SOURCES)
set(EXR_DEFLATE_INCLUDE_DIR)
set(EXR_DEFLATE_LDFLAGS)
# Set EXR_DEFATE_LDFLAGS for OpenEXR.pc.in for static build
if(NOT BUILD_SHARED_LIBS)
get_target_property(deflate_LIBRARIES ${EXR_DEFLATE_LIB} LOCATION)
set(EXR_DEFLATE_LDFLAGS "-l${deflate_LIBRARIES}")
brechtvl marked this conversation as resolved.
Show resolved Hide resolved
endif()
message(STATUS "Using libdeflate from ${libdeflate_DIR}")
else()
# If not found, try pkgconfig
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
include(FindPkgConfig)
pkg_check_modules(deflate IMPORTED_TARGET GLOBAL libdeflate)
if(deflate_FOUND)
set(EXR_DEFLATE_LIB PkgConfig::deflate)
set(EXR_DEFLATE_SOURCES)
set(EXR_DEFLATE_INCLUDE_DIR)
set(EXR_DEFLATE_LDFLAGS)
# Set EXR_DEFATE_LDFLAGS for OpenEXR.pc.in for static build
if(NOT BUILD_SHARED_LIBS)
set(EXR_DEFLATE_LDFLAGS "-l${deflate_LIBRARIES}")
brechtvl marked this conversation as resolved.
Show resolved Hide resolved
endif()
message(STATUS "Using libdeflate from ${deflate_LINK_LIBRARIES}")
endif()
endif()
endif()
set(CMAKE_IGNORE_PATH)
endif()

if(NOT TARGET PkgConfig::deflate AND NOT deflate_FOUND)
if(NOT EXR_DEFLATE_LIB)
# Using internal deflate.
if(OPENEXR_FORCE_INTERNAL_DEFLATE)
message(STATUS "libdeflate forced internal, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
else()
Expand Down Expand Up @@ -213,16 +245,6 @@ if(NOT TARGET PkgConfig::deflate AND NOT deflate_FOUND)
list(TRANSFORM EXR_DEFLATE_SOURCES PREPEND ${deflate_SOURCE_DIR}/)
set(EXR_DEFLATE_INCLUDE_DIR ${deflate_SOURCE_DIR})
set(EXR_DEFLATE_LIB)
else()
set(EXR_DEFLATE_INCLUDE_DIR)
set(EXR_DEFLATE_LIB ${deflate_LIBRARIES})
# set EXR_DEFATE_LDFLAGS for OpenEXR.pc.in for static build
if (BUILD_SHARED_LIBS)
set(EXR_DEFLATE_LDFLAGS "")
else()
set(EXR_DEFLATE_LDFLAGS "-l${deflate_LIBRARIES}")
endif()
set(EXR_DEFLATE_SOURCES)
endif()

#######################################
Expand Down