[libjxl] Cleanup (#29190)

* [libjxl] Trim patch

* Trim static targets during shared build

* Cleanup
This commit is contained in:
Kai Pastor 2023-01-27 04:45:43 +01:00 committed by GitHub
parent dcbb09d22b
commit 14b8851a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 136 deletions

View File

@ -1,105 +1,32 @@
diff --git a/lib/jxl.cmake b/lib/jxl.cmake
index a8a96e1..98d69d6 100644
--- a/lib/jxl.cmake
+++ b/lib/jxl.cmake
@@ -3,6 +3,15 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
+find_package(unofficial-brotli CONFIG REQUIRED)
+find_package(lcms2 CONFIG REQUIRED)
+
+foreach(brlib IN ITEMS brotlienc brotlidec brotlicommon)
+ add_library(${brlib} ALIAS unofficial::brotli::${brlib}-static)
+ add_library(${brlib}-static ALIAS unofficial::brotli::${brlib}-static)
+endforeach()
+add_library(lcms2 ALIAS lcms2::lcms2)
+
# Lists all source files for the JPEG XL decoder library. These are also used
# by the encoder: the encoder uses both dec and enc ourse files, while the
# decoder uses only dec source files.
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 8ee9864..57993ea 100644
index 8ee9864..b8a22a5 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -45,59 +45,7 @@ else()
endif()
@@ -47,7 +47,16 @@ endif()
# brotli
-if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/brotli/c/include/brotli/decode.h" OR
- JPEGXL_FORCE_SYSTEM_BROTLI)
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/brotli/c/include/brotli/decode.h" OR
JPEGXL_FORCE_SYSTEM_BROTLI)
- find_package(Brotli)
- if (NOT Brotli_FOUND)
- message(FATAL_ERROR
- "Brotli not found, install brotli-dev or download brotli source code to"
- " third_party/brotli from https://github.com/google/brotli. You can use"
- " ${PROJECT_SOURCE_DIR}/deps.sh to download this dependency.")
- endif ()
- if(JPEGXL_DEP_LICENSE_DIR)
- configure_file("${JPEGXL_DEP_LICENSE_DIR}/libbrotli-dev/copyright"
- ${PROJECT_BINARY_DIR}/LICENSE.brotli COPYONLY)
- endif() # JPEGXL_DEP_LICENSE_DIR
-else()
- # Compile brotli from sources.
- set(BROTLI_DISABLE_TESTS ON CACHE STRING "Disable Brotli tests")
- # Override default "no-install" policy.
- if((NOT SANITIZER STREQUAL "asan") AND (NOT SANITIZER STREQUAL "msan"))
- set(BROTLI_BUNDLED_MODE OFF CACHE INTERNAL "")
- endif()
- add_subdirectory(brotli)
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/brotli/LICENSE"
- ${PROJECT_BINARY_DIR}/LICENSE.brotli COPYONLY)
- if(BROTLI_EMSCRIPTEN)
- # Brotli only defines the -static targets when using emscripten.
- foreach(brlib IN ITEMS brotlienc brotlidec brotlicommon)
- add_library(${brlib} ALIAS ${brlib}-static)
- endforeach()
- endif() # BROTLI_EMSCRIPTEN
- if(APPLE)
- if(NOT DEFINED CMAKE_MACOSX_RPATH)
- # Use @rpath in install_name when CMAKE_MACOSX_RPATH is not set.
- set_property(TARGET brotlienc PROPERTY MACOSX_RPATH TRUE)
- set_property(TARGET brotlidec PROPERTY MACOSX_RPATH TRUE)
- set_property(TARGET brotlicommon PROPERTY MACOSX_RPATH TRUE)
- endif()
- if((NOT DEFINED CMAKE_MACOSX_RPATH) OR CMAKE_MACOSX_RPATH)
- # Set library search path when @rpath is used.
- if(NOT DEFINED CMAKE_INSTALL_RPATH)
- set_property(TARGET brotlienc PROPERTY INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
- set_property(TARGET brotlidec PROPERTY INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
- set_property(TARGET brotlicommon PROPERTY INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
- endif()
- else()
- # Set conventional install_name when @rpath is not used.
- if(NOT DEFINED CMAKE_INSTALL_NAME_DIR)
- set_property(TARGET brotlienc PROPERTY INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
- set_property(TARGET brotlidec PROPERTY INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
- set_property(TARGET brotlicommon PROPERTY INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
- endif()
- endif()
- endif() # APPLE
-endif()
+find_package(unofficial-brotli CONFIG REQUIRED)
# *cms
if (JPEGXL_ENABLE_SKCMS OR JPEGXL_ENABLE_PLUGINS)
@@ -109,18 +57,7 @@ if (JPEGXL_ENABLE_SKCMS OR JPEGXL_ENABLE_PLUGINS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/skcms/LICENSE"
${PROJECT_BINARY_DIR}/LICENSE.skcms COPYONLY)
+ find_package(Brotli NAMES unofficial-brotli REQUIRED)
+ foreach(brlib IN ITEMS brotlienc brotlidec brotlicommon)
+ if(TARGET unofficial::brotli::${brlib})
+ add_library(${brlib} ALIAS unofficial::brotli::${brlib})
+ add_library(${brlib}-static ALIAS unofficial::brotli::${brlib})
+ else()
+ add_library(${brlib} ALIAS unofficial::brotli::${brlib}-static)
+ add_library(${brlib}-static ALIAS unofficial::brotli::${brlib}-static)
+ endif()
+ endforeach()
if (NOT Brotli_FOUND)
message(FATAL_ERROR
"Brotli not found, install brotli-dev or download brotli source code to"
@@ -111,7 +120,8 @@ if (JPEGXL_ENABLE_SKCMS OR JPEGXL_ENABLE_PLUGINS)
endif ()
-if (JPEGXL_ENABLE_VIEWERS OR NOT JPEGXL_ENABLE_SKCMS)
- if( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lcms/.git" OR JPEGXL_FORCE_SYSTEM_LCMS2 )
if (JPEGXL_ENABLE_VIEWERS OR NOT JPEGXL_ENABLE_SKCMS)
if( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lcms/.git" OR JPEGXL_FORCE_SYSTEM_LCMS2 )
- find_package(LCMS2 2.13)
- if ( NOT LCMS2_FOUND )
- message(FATAL_ERROR "Please install lcms2 or run git submodule update --init")
- endif ()
- else()
- include(lcms2.cmake)
- configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lcms/COPYING"
- ${PROJECT_BINARY_DIR}/LICENSE.lcms COPYONLY)
- endif()
-endif()
+find_package(lcms2 CONFIG REQUIRED)
# libpng
if (JPEGXL_BUNDLE_LIBPNG AND JPEGXL_EMSCRIPTEN)
+ find_package(LCMS2 NAMES lcms2 REQUIRED)
+ add_library(lcms2 ALIAS lcms2::lcms2)
if ( NOT LCMS2_FOUND )
message(FATAL_ERROR "Please install lcms2 or run git submodule update --init")
endif ()

View File

@ -6,6 +6,7 @@ vcpkg_from_github(
HEAD_REF main
PATCHES
fix-dependencies.patch
trim-shared-build.patch
)
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
@ -19,45 +20,31 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
)
if(VCPKG_TARGET_IS_UWP)
string(APPEND VCPKG_C_FLAGS " -D_CRT_SECURE_NO_WARNINGS /wd4146")
string(APPEND VCPKG_CXX_FLAGS " -D_CRT_SECURE_NO_WARNINGS /wd4146")
# Temporary workaround for #9390
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
list(APPEND FEATURE_OPTIONS -DCMAKE_SYSTEM_PROCESSOR=x86)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
list(APPEND FEATURE_OPTIONS -DCMAKE_SYSTEM_PROCESSOR=AMD64)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
list(APPEND FEATURE_OPTIONS -DCMAKE_SYSTEM_PROCESSOR=ARM)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
list(APPEND FEATURE_OPTIONS -DCMAKE_SYSTEM_PROCESSOR=ARM64)
else()
message(FATAL_ERROR "Unsupported uwp VCPKG_TARGET_ARCHITECTURE \"${VCPKG_TARGET_ARCHITECTURE}\"")
endif()
# Workaround for vcpkg-cmake bug, proper fix in #21857
set(_TARGETTING_UWP 1)
string(APPEND VCPKG_C_FLAGS " /wd4146")
string(APPEND VCPKG_CXX_FLAGS " /wd4146")
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
"-DJPEGXL_VERSION=${JPEGXL_VERSION}"
-DJPEGXL_FORCE_SYSTEM_HWY=ON
-DJPEGXL_FORCE_SYSTEM_BROTLI=ON
-DJPEGXL_FORCE_SYSTEM_HWY=ON
-DJPEGXL_FORCE_SYSTEM_LCMS2=ON
${FEATURE_OPTIONS}
-DJPEGXL_ENABLE_FUZZERS=OFF
-DJPEGXL_ENABLE_MANPAGES=OFF
-DJPEGXL_ENABLE_BENCHMARK=OFF
-DJPEGXL_ENABLE_DOXYGEN=OFF
-DJPEGXL_ENABLE_EXAMPLES=OFF
-DJPEGXL_ENABLE_FUZZERS=OFF
-DJPEGXL_ENABLE_JNI=OFF
-DJPEGXL_ENABLE_SJPEG=OFF
-DJPEGXL_ENABLE_MANPAGES=OFF
-DJPEGXL_ENABLE_OPENEXR=OFF
-DJPEGXL_ENABLE_PLUGINS=OFF
-DJPEGXL_ENABLE_SJPEG=OFF
-DJPEGXL_ENABLE_SKCMS=OFF
-DJPEGXL_ENABLE_TCMALLOC=OFF
-DBUILD_TESTING=OFF
-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=1
-DCMAKE_FIND_PACKAGE_TARGETS_GLOBAL=ON
MAYBE_UNUSED_VARIABLES
CMAKE_DISABLE_FIND_PACKAGE_GIF
CMAKE_DISABLE_FIND_PACKAGE_JPEG
@ -73,21 +60,6 @@ if(JPEGXL_ENABLE_TOOLS)
vcpkg_copy_tools(TOOL_NAMES cjxl djxl cjpeg_hdr jxlinfo AUTO_CLEAN)
endif()
# libjxl always builds static libraries, so we delete them if we don't need them.
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
if(VCPKG_TARGET_IS_WINDOWS)
file(GLOB FILES_TO_REMOVE
"${CURRENT_PACKAGES_DIR}/lib/*-static.lib"
"${CURRENT_PACKAGES_DIR}/debug/lib/*-static.lib"
)
else()
file(GLOB FILES_TO_REMOVE
"${CURRENT_PACKAGES_DIR}/lib/*.a"
"${CURRENT_PACKAGES_DIR}/debug/lib/*.a"
)
endif()
file(REMOVE ${FILES_TO_REMOVE})
endif()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")

View File

@ -0,0 +1,37 @@
diff --git a/lib/jxl.cmake b/lib/jxl.cmake
index a8a96e1..a42b6f0 100644
--- a/lib/jxl.cmake
+++ b/lib/jxl.cmake
@@ -556,8 +556,13 @@ if (NOT WIN32 OR MINGW)
set_target_properties(jxl-static PROPERTIES OUTPUT_NAME "jxl")
set_target_properties(jxl_dec-static PROPERTIES OUTPUT_NAME "jxl_dec")
endif()
+if(BUILD_SHARED_LIBS)
+ set_target_properties(jxl-static PROPERTIES EXCLUDE_FROM_ALL 1)
+ set_target_properties(jxl_dec-static PROPERTIES EXCLUDE_FROM_ALL 1)
+else()
install(TARGETS jxl-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS jxl_dec-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif()
if (BUILD_SHARED_LIBS)
diff --git a/lib/jxl_threads.cmake b/lib/jxl_threads.cmake
index 006e71e..b8ce66b 100644
--- a/lib/jxl_threads.cmake
+++ b/lib/jxl_threads.cmake
@@ -43,10 +43,14 @@ set_target_properties(${_target} PROPERTIES
if (NOT WIN32 OR MINGW)
set_target_properties(${_target} PROPERTIES OUTPUT_NAME "jxl_threads")
endif()
+if(BUILD_SHARED_LIBS AND _target MATCHES "-static")
+ set_target_properties(${_target} PROPERTIES EXCLUDE_FROM_ALL 1)
+else()
install(TARGETS ${_target}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif()
endfunction()

View File

@ -1,6 +1,7 @@
{
"name": "libjxl",
"version-semver": "0.8.0",
"port-version": 1,
"description": "JPEG XL image format reference implementation",
"homepage": "https://github.com/libjxl/libjxl",
"license": "BSD-3-Clause",

View File

@ -3970,7 +3970,7 @@
},
"libjxl": {
"baseline": "0.8.0",
"port-version": 0
"port-version": 1
},
"libkeyfinder": {
"baseline": "2.2.6",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "e2a279f3663c22d8d36ff1960729f8000535b063",
"version-semver": "0.8.0",
"port-version": 1
},
{
"git-tree": "ef11c9864441ebeee257d1baedf1d29d208087f5",
"version-semver": "0.8.0",