Giter Club home page Giter Club logo

Comments (7)

kmilos avatar kmilos commented on July 25, 2024

I'm working on Windows. PkgConfig is not available.

Just as a side note - it is in theory via vcpkg (or chocolatey, or MSYS2).

But yeah, agree there is no reason not to try the direct CMake approach for newer libdeflate versions that supply the config files.

from openexr.

bebuch avatar bebuch commented on July 25, 2024

I'm in a Docker container with minimal dependencies. ;-)

from openexr.

bebuch avatar bebuch commented on July 25, 2024

I have made a patch to 3.1.4 that work for me to link to the shared version of libdeflate:

diff --git a/openexr_original/cmake/OpenEXRSetup.cmake b/openexr/cmake/OpenEXRSetup.cmake
index 425992d..fa80886 100644
--- a/openexr_original/cmake/OpenEXRSetup.cmake
+++ b/openexr/cmake/OpenEXRSetup.cmake
@@ -160,71 +160,79 @@ 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}")
+  find_package(libdeflate CONFIG)
+  if(libdeflate_FOUND)
+    message(STATUS "Using libdeflate from ${libdeflate_DIR}")
+  else()
+    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}")
+    endif()
   endif()
 endif()
 
-if(NOT TARGET PkgConfig::deflate AND NOT deflate_FOUND)
-  if(OPENEXR_FORCE_INTERNAL_DEFLATE)
-    message(STATUS "libdeflate forced internal, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
-  else()
-    message(STATUS "libdeflate was not found, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
-  endif()
-  include(FetchContent)
-  FetchContent_Declare(Deflate
-    GIT_REPOSITORY "${OPENEXR_DEFLATE_REPO}"
-    GIT_TAG "${OPENEXR_DEFLATE_TAG}"
-    GIT_SHALLOW ON
-    )
+if(libdeflate_FOUND)
+  set(EXR_DEFLATE_LIB libdeflate::libdeflate_shared)
+else()
+  if(NOT TARGET PkgConfig::deflate AND NOT deflate_FOUND)
+    if(OPENEXR_FORCE_INTERNAL_DEFLATE)
+      message(STATUS "libdeflate forced internal, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
+    else()
+      message(STATUS "libdeflate was not found, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
+    endif()
+    include(FetchContent)
+    FetchContent_Declare(Deflate
+      GIT_REPOSITORY "${OPENEXR_DEFLATE_REPO}"
+      GIT_TAG "${OPENEXR_DEFLATE_TAG}"
+      GIT_SHALLOW ON
+      )
 
-  FetchContent_GetProperties(Deflate)
-  if(NOT Deflate_POPULATED)
-    FetchContent_Populate(Deflate)
-  endif()
+    FetchContent_GetProperties(Deflate)
+    if(NOT Deflate_POPULATED)
+      FetchContent_Populate(Deflate)
+    endif()
 
-  # Rather than actually compile something, just embed the sources
-  # into exrcore. This could in theory cause issues when compiling as
-  # a static library into another application which also uses
-  # libdeflate but we switch the export symbol to hidden which should
-  # hide the symbols when linking...
-  set(EXR_DEFLATE_SOURCES
-    lib/arm/cpu_features.c
-    lib/x86/cpu_features.c
-    lib/utils.c
-    lib/deflate_compress.c
-    lib/deflate_decompress.c
-    lib/adler32.c
-    lib/zlib_compress.c
-    lib/zlib_decompress.c)
-  # don't need these
-  # lib/crc32.c
-  # lib/gzip_compress.c
-  # lib/gzip_decompress.c
-  file(READ ${deflate_SOURCE_DIR}/lib/lib_common.h DEFLATE_HIDE)
-  string(REPLACE "visibility(\"default\")" "visibility(\"hidden\")" DEFLATE_HIDE "${DEFLATE_HIDE}")
-  string(REPLACE "__declspec(dllexport)" "/**/" DEFLATE_HIDE "${DEFLATE_HIDE}")
-  file(WRITE ${deflate_SOURCE_DIR}/lib/lib_common.h "${DEFLATE_HIDE}")
+    # Rather than actually compile something, just embed the sources
+    # into exrcore. This could in theory cause issues when compiling as
+    # a static library into another application which also uses
+    # libdeflate but we switch the export symbol to hidden which should
+    # hide the symbols when linking...
+    set(EXR_DEFLATE_SOURCES
+      lib/arm/cpu_features.c
+      lib/x86/cpu_features.c
+      lib/utils.c
+      lib/deflate_compress.c
+      lib/deflate_decompress.c
+      lib/adler32.c
+      lib/zlib_compress.c
+      lib/zlib_decompress.c)
+    # don't need these
+    # lib/crc32.c
+    # lib/gzip_compress.c
+    # lib/gzip_decompress.c
+    file(READ ${deflate_SOURCE_DIR}/lib/lib_common.h DEFLATE_HIDE)
+    string(REPLACE "visibility(\"default\")" "visibility(\"hidden\")" DEFLATE_HIDE "${DEFLATE_HIDE}")
+    string(REPLACE "__declspec(dllexport)" "/**/" DEFLATE_HIDE "${DEFLATE_HIDE}")
+    file(WRITE ${deflate_SOURCE_DIR}/lib/lib_common.h "${DEFLATE_HIDE}")
   
-  # cmake makes fetch content name lowercase for the properties (to deflate)
-  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 "")
+    # cmake makes fetch content name lowercase for the properties (to deflate)
+    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_LDFLAGS "-l${deflate_LIBRARIES}")
+    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()
-  set(EXR_DEFLATE_SOURCES)
 endif()
-
 #######################################
 # Find or install Imath
 #######################################

If you ignore the indent changes its just:

diff --git a/openexr_original/cmake/OpenEXRSetup.cmake b/openexr/cmake/OpenEXRSetup.cmake
index 425992d..eaac6fa 100644
--- a/openexr_original/cmake/OpenEXRSetup.cmake
+++ b/openexr/cmake/OpenEXRSetup.cmake
@@ -160,14 +160,22 @@ 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}")
+  find_package(libdeflate CONFIG)
+  if(libdeflate_FOUND)
+    message(STATUS "Using libdeflate from ${libdeflate_DIR}")
+  else()
+    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}")
+    endif()
   endif()
 endif()
 
+if(libdeflate_FOUND)
+  set(EXR_DEFLATE_LIB libdeflate::libdeflate_shared)
+else()
 if(NOT TARGET PkgConfig::deflate AND NOT deflate_FOUND)
   if(OPENEXR_FORCE_INTERNAL_DEFLATE)
     message(STATUS "libdeflate forced internal, installing from ${OPENEXR_DEFLATE_REPO} (${OPENEXR_DEFLATE_TAG})")
@@ -224,7 +232,7 @@ else()
   endif()
   set(EXR_DEFLATE_SOURCES)
 endif()
-
+endif()
 #######################################
 # Find or install Imath
 #######################################

from openexr.

brechtvl avatar brechtvl commented on July 25, 2024

@bebuch are you planning to submit this as a pull request? We need the same thing for Blender. I can make a pull request too if that helps.

The one further change we need is to fall back to the static library if there is no shared one.

if(libdeflate::libdeflate_shared)
  set(EXR_DEFLATE_LIB libdeflate::libdeflate_shared)
else()
  set(EXR_DEFLATE_LIB libdeflate::libdeflate_static)
endif()

from openexr.

bebuch avatar bebuch commented on July 25, 2024

@brechtvl The patch is not a general solution, therefore I didn't make a PR. Please feel free to use it as part of your PR. ;-)

from openexr.

cary-ilm avatar cary-ilm commented on July 25, 2024

Following up on this, @brechtvl, will you submit a PR?

from openexr.

brechtvl avatar brechtvl commented on July 25, 2024

I submitted one now.

from openexr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.