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

Fix broken gdal JPEG driver on iOS by relying on internal lib #4340

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions vcpkg/overlay/gdal/cmake-project-include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if(GDAL_USE_WEBP)
find_package(WebP CONFIG REQUIRED)
add_library(WEBP::WebP ALIAS WebP::webp)
set(GDAL_CHECK_PACKAGE_WebP_NAMES WebP CACHE INTERNAL "vcpkg")
set(GDAL_CHECK_PACKAGE_WebP_TARGETS WebP::webp CACHE INTERNAL "vcpkg")
endif()
109 changes: 109 additions & 0 deletions vcpkg/overlay/gdal/find-link-libraries.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
diff --git a/cmake/modules/packages/FindFreeXL.cmake b/cmake/modules/packages/FindFreeXL.cmake
index 6c86fb8..0634412 100644
--- a/cmake/modules/packages/FindFreeXL.cmake
+++ b/cmake/modules/packages/FindFreeXL.cmake
@@ -37,7 +37,15 @@ include(SelectLibraryConfigurations)

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
- pkg_check_modules(PC_FREEXL QUIET freexl)
+ pkg_check_modules(PC_FREEXL QUIET IMPORTED_TARGET freexl)
+endif()
+if(PC_FREEXL_FOUND)
+ set(FREEXL_INCLUDE_DIR "${PC_FREEXL_INCLUDE_DIRS}" CACHE STRING "")
+ set(FREEXL_LIBRARY "${PC_FREEXL_LIBRARIES}" CACHE STRING "")
+ if(NOT TARGET FREEXL::freexl)
+ add_library(FREEXL::freexl INTERFACE IMPORTED)
+ set_target_properties(FREEXL::freexl PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::PC_FREEXL)
+ endif()
endif()

find_path(FREEXL_INCLUDE_DIR
diff --git a/cmake/modules/packages/FindOpenJPEG.cmake b/cmake/modules/packages/FindOpenJPEG.cmake
index c697484..6e83222 100644
--- a/cmake/modules/packages/FindOpenJPEG.cmake
+++ b/cmake/modules/packages/FindOpenJPEG.cmake
@@ -32,9 +32,18 @@ endfunction()

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
- pkg_check_modules(PC_OPENJPEG QUIET libopenjp2)
+ pkg_check_modules(PC_OPENJPEG QUIET IMPORTED_TARGET libopenjp2)
set(OPENJPEG_VERSION_STRING ${PC_OPENJPEG_VERSION})
endif()
+if(PC_OPENJPEG_FOUND)
+ set(OPENJPEG_INCLUDE_DIR "${PC_OPENJPEG_INCLUDE_DIRS}" CACHE STRING "")
+ set(OPENJPEG_LIBRARY "${PC_OPENJPEG_LIBRARIES}" CACHE STRING "")
+ if(NOT TARGET OPENJPEG::OpenJPEG)
+ add_library(OPENJPEG::OpenJPEG INTERFACE IMPORTED)
+ set_target_properties(OPENJPEG::OpenJPEG PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${PC_OPENJPEG_INCLUDE_DIRS}")
+ set_target_properties(OPENJPEG::OpenJPEG PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::PC_OPENJPEG)
+ endif()
+endif()


find_path(OPENJPEG_INCLUDE_DIR opj_config.h
diff --git a/cmake/modules/packages/FindPoppler.cmake b/cmake/modules/packages/FindPoppler.cmake
index 3807ec0..8059eb4 100644
--- a/cmake/modules/packages/FindPoppler.cmake
+++ b/cmake/modules/packages/FindPoppler.cmake
@@ -42,11 +42,19 @@ This module defines the following variables:

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
- pkg_check_modules(PC_Poppler QUIET poppler)
+ pkg_check_modules(PC_Poppler QUIET IMPORTED_TARGET poppler)
if(PC_Poppler_VERSION)
set(Poppler_VERSION_STRING ${PC_Poppler_VERSION})
endif()
endif()
+if(PC_Poppler_FOUND)
+ find_path(Poppler_INCLUDE_DIR NAMES Object.h PATHS ${PC_Poppler_INCLUDE_DIRS} NO_DEFAULT_PATH)
+ set(Poppler_LIBRARY "${PC_Poppler_LIBRARIES}" CACHE STRING "")
+ if(NOT TARGET Poppler::Poppler)
+ add_library(Poppler::Poppler INTERFACE IMPORTED)
+ set_target_properties(Poppler::Poppler PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::PC_Poppler)
+ endif()
+endif()
find_path(Poppler_INCLUDE_DIR NAMES "poppler-config.h" "cpp/poppler-version.h" "qt5/poppler-qt5.h" "qt4/poppler-qt4.h"
"glib/poppler.h"
HINTS ${PC_Poppler_INCLUDE_DIRS}
@@ -77,6 +85,15 @@ endforeach()
foreach(_comp IN LISTS Poppler_known_components)
list(FIND Poppler_FIND_COMPONENTS "${_comp}" _nextcomp)
if(_nextcomp GREATER -1)
+ pkg_check_modules(PC_Poppler_${_comp} QUIET IMPORTED_TARGET ${Poppler_${_comp}_pkg_config})
+ if(PC_Poppler_${_comp}_FOUND)
+ set(Poppler_${_comp}_INCLUDE_DIR "${PC_Poppler_${_comp}_INCLUDE_DIRS}" CACHE STRING "")
+ set(Poppler_${_comp}_LIBRARY "${PC_Poppler_${_comp}_LIBRARIES}" CACHE STRING "")
+ if(NOT TARGET Poppler::Poppler_${_comp})
+ add_library(Poppler::${_comp} INTERFACE IMPORTED)
+ set_target_properties(Poppler::${_comp} PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::PC_Poppler_${_comp})
+ endif()
+ endif()
find_path(Poppler_${_comp}_INCLUDE_DIR
NAMES ${Poppler_${_comp}_header}
PATH_SUFFIXES poppler
diff --git a/cmake/modules/packages/FindSPATIALITE.cmake b/cmake/modules/packages/FindSPATIALITE.cmake
index 00612b0..6388719 100644
--- a/cmake/modules/packages/FindSPATIALITE.cmake
+++ b/cmake/modules/packages/FindSPATIALITE.cmake
@@ -38,9 +38,17 @@ endif()

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
- pkg_check_modules(PC_SPATIALITE QUIET spatialite)
+ pkg_check_modules(PC_SPATIALITE QUIET IMPORTED_TARGET spatialite)
set(SPATIALITE_VERSION_STRING ${PC_SPATIALITE_VERSION})
endif()
+if(PC_SPATIALITE_FOUND)
+ set(SPATIALITE_INCLUDE_DIR "${PC_SPATIALITE_INCLUDE_DIRS}" CACHE STRING "")
+ set(SPATIALITE_LIBRARY "${PC_SPATIALITE_LIBRARIES}" CACHE STRING "")
+ if(NOT TARGET SPATIALITE::SPATIALITE)
+ add_library(SPATIALITE::SPATIALITE INTERFACE IMPORTED)
+ set_target_properties(SPATIALITE::SPATIALITE PROPERTIES INTERFACE_LINK_LIBRARIES PkgConfig::PC_SPATIALITE)
+ endif()
+endif()

find_path(SPATIALITE_INCLUDE_DIR
NAMES spatialite.h
15 changes: 15 additions & 0 deletions vcpkg/overlay/gdal/fix-gdal-target-interfaces.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/cmake/helpers/GdalDriverHelper.cmake b/cmake/helpers/GdalDriverHelper.cmake
index 838f0fd..380e20d 100644
--- a/cmake/helpers/GdalDriverHelper.cmake
+++ b/cmake/helpers/GdalDriverHelper.cmake
@@ -248,6 +248,10 @@ function(gdal_target_interfaces _TARGET)
if (_res)
target_compile_options(${_TARGET} PRIVATE ${_res})
endif ()
+ get_property(_res TARGET ${_LIB} PROPERTY INTERFACE_LINK_LIBRARIES)
+ if (_res)
+ gdal_target_interfaces(${_TARGET} ${_res})
+ endif ()
endif ()
endforeach ()
endfunction()
46 changes: 46 additions & 0 deletions vcpkg/overlay/gdal/libkml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/cmake/modules/packages/FindLibKML.cmake b/cmake/modules/packages/FindLibKML.cmake
index 9418247..589b83d 100644
--- a/cmake/modules/packages/FindLibKML.cmake
+++ b/cmake/modules/packages/FindLibKML.cmake
@@ -56,6 +56,8 @@ find_library(LIBKML_BASE_LIBRARY
HINTS ${PC_LIBKML_LIBRARY_DIRS} )
mark_as_advanced(LIBKML_BASE_LIBRARY)

+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW)
set(libkml_known_components DOM CONVENIENCE ENGINE REGIONATOR)
foreach(_comp IN LISTS libkml_known_components)
if(${_comp} IN_LIST LibKML_FIND_COMPONENTS)
@@ -99,21 +101,20 @@ find_package_handle_standard_args(LibKML
if(LIBKML_FOUND)
set(LIBKML_INCLUDE_DIRS "${LIBKML_INCLUDE_DIR}")
set(LIBKML_LIBRARIES "${LIBKML_BASE_LIBRARY}")
+ find_package(LibKML CONFIG REQUIRED)
if(NOT TARGET LIBKML::LibKML)
- add_library(LIBKML::LibKML UNKNOWN IMPORTED)
+ add_library(LIBKML::LibKML INTERFACE IMPORTED)
set_target_properties(LIBKML::LibKML PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${LIBKML_INCLUDE_DIR}"
- IMPORTED_LINK_INTERFACE_LANGUAGES "C++"
- IMPORTED_LOCATION "${LIBKML_BASE_LIBRARY}")
+ INTERFACE_LINK_LIBRARIES kmlbase)
endif()
foreach(_comp IN LISTS libkml_known_components)
if(${_comp} IN_LIST LibKML_FIND_COMPONENTS)
+ string(TOLOWER ${_comp} _name)
list(APPEND LIBKML_LIBRARIES "${LIBKML_${_comp}_LIBRARY}")
if(NOT TARGET LIBKML::${_comp})
- add_library(LIBKML::${_comp} UNKNOWN IMPORTED)
+ add_library(LIBKML::${_comp} INTERFACE IMPORTED)
set_target_properties(LIBKML::${_comp} PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES "C++"
- IMPORTED_LOCATION "${LIBKML_${_comp}_LIBRARY}")
+ INTERFACE_LINK_LIBRARIES kml${_name})
endif()
endif()
endforeach()
@@ -129,3 +130,4 @@ if(LIBKML_FOUND)
endif()
endforeach()
endif()
+cmake_policy(POP)
168 changes: 168 additions & 0 deletions vcpkg/overlay/gdal/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO OSGeo/gdal
REF "v${VERSION}"
SHA512 dfc7ccf5c1a3184fa93be762a880b7631faa4cd178cd72df8f5fd8a6296edafc56de2594617bebcb75ddf19ed4471dafcb574b22d7e9217dedfd7ea72c9247f2
HEAD_REF master
PATCHES
find-link-libraries.patch
fix-gdal-target-interfaces.patch
libkml.patch
)
# `vcpkg clean` stumbles over one subdir
file(REMOVE_RECURSE "${SOURCE_PATH}/autotest")

# Cf. cmake/helpers/CheckDependentLibraries.cmake
# The default for all `GDAL_USE_<PKG>` dependencies is `OFF`.
# Here, we explicitly control dependencies provided via vpcpkg.
# "core" is used for a dependency which must be enabled to avoid vendored lib.
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
cfitsio GDAL_USE_CFITSIO
curl GDAL_USE_CURL
expat GDAL_USE_EXPAT
freexl GDAL_USE_FREEXL
geos GDAL_USE_GEOS
core GDAL_USE_GEOTIFF
gif GDAL_USE_GIF
hdf5 GDAL_USE_HDF5
iconv GDAL_USE_ICONV
jpeg GDAL_USE_JPEG
core GDAL_USE_JSONC
lerc GDAL_USE_LERC
libkml GDAL_USE_LIBKML
lzma GDAL_USE_LIBLZMA
libxml2 GDAL_USE_LIBXML2
mysql-libmariadb GDAL_USE_MYSQL
netcdf GDAL_USE_NETCDF
odbc GDAL_USE_ODBC
openjpeg GDAL_USE_OPENJPEG
openssl GDAL_USE_OPENSSL
pcre2 GDAL_USE_PCRE2
png GDAL_USE_PNG
poppler GDAL_USE_POPPLER
postgresql GDAL_USE_POSTGRESQL
qhull GDAL_USE_QHULL
#core GDAL_USE_SHAPELIB # https://github.com/OSGeo/gdal/issues/5711, https://github.com/microsoft/vcpkg/issues/16041
core GDAL_USE_SHAPELIB_INTERNAL
libspatialite GDAL_USE_SPATIALITE
sqlite3 GDAL_USE_SQLITE3
core GDAL_USE_TIFF
webp GDAL_USE_WEBP
core GDAL_USE_ZLIB
zstd GDAL_USE_ZSTD
tools BUILD_APPS
)
if(GDAL_USE_ICONV AND VCPKG_TARGET_IS_WINDOWS)
list(APPEND FEATURE_OPTIONS -D_ICONV_SECOND_ARGUMENT_IS_NOT_CONST=ON)
endif()

if(VCPKG_TARGET_IS_IOS AND GDAL_USE_JPEG)
list(APPEND FEATURE_OPTIONS -DGDAL_USE_JPEG_INTERNAL=ON)
endif()

# Compatibility with older Android versions https://github.com/OSGeo/gdal/pull/5941
if(VCPKG_TARGET_IS_ANDROID AND ANRDOID_PLATFORM VERSION_LESS 24 AND (VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" OR VCPKG_TARGET_ARCHITECTURE STREQUAL "arm"))
list(APPEND FEATURE_OPTIONS -DBUILD_WITHOUT_64BIT_OFFSET=ON)
endif()

string(REPLACE "dynamic" "" qhull_target "Qhull::qhull${VCPKG_LIBRARY_LINKAGE}_r")

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DVCPKG_HOST_TRIPLET=${HOST_TRIPLET} # for host pkgconf in PATH
${FEATURE_OPTIONS}
-DBUILD_DOCS=OFF
-DBUILD_PYTHON_BINDINGS=OFF
-DBUILD_TESTING=OFF
-DCMAKE_DISABLE_FIND_PACKAGE_CSharp=ON
-DCMAKE_DISABLE_FIND_PACKAGE_Java=ON
-DCMAKE_DISABLE_FIND_PACKAGE_JNI=ON
-DCMAKE_DISABLE_FIND_PACKAGE_SWIG=ON
-DGDAL_USE_INTERNAL_LIBS=OFF
-DGDAL_USE_EXTERNAL_LIBS=OFF
-DGDAL_BUILD_OPTIONAL_DRIVERS=ON
-DOGR_BUILD_OPTIONAL_DRIVERS=ON
-DGDAL_CHECK_PACKAGE_MySQL_NAMES=unofficial-libmariadb
-DGDAL_CHECK_PACKAGE_MySQL_TARGETS=unofficial::libmariadb
-DMYSQL_LIBRARIES=unofficial::libmariadb
-DGDAL_CHECK_PACKAGE_NetCDF_NAMES=netCDF
-DGDAL_CHECK_PACKAGE_NetCDF_TARGETS=netCDF::netcdf
-DGDAL_CHECK_PACKAGE_QHULL_NAMES=Qhull
"-DGDAL_CHECK_PACKAGE_QHULL_TARGETS=${qhull_target}"
"-DQHULL_LIBRARY=${qhull_target}"
-DCMAKE_PROJECT_INCLUDE="${CMAKE_CURRENT_LIST_DIR}/cmake-project-include.cmake"
OPTIONS_DEBUG
-DBUILD_APPS=OFF
MAYBE_UNUSED_VARIABLES
QHULL_LIBRARY
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()
vcpkg_fixup_pkgconfig()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/gdal)
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/gdal/GDALConfig.cmake"
"include(CMakeFindDependencyMacro)"
"include(CMakeFindDependencyMacro)
# gdal needs a pkg-config tool. A host dependency provides pkgconf.
get_filename_component(vcpkg_host_prefix \"\${CMAKE_CURRENT_LIST_DIR}/../../../${HOST_TRIPLET}\" ABSOLUTE)
list(APPEND CMAKE_PROGRAM_PATH \"\${vcpkg_host_prefix}/tools/pkgconf\")"
)

if (BUILD_APPS)
vcpkg_copy_tools(
TOOL_NAMES
gdalinfo
gdalbuildvrt
gdaladdo
gdal_grid
gdal_translate
gdal_rasterize
gdalsrsinfo
gdalenhance
gdalmanage
gdaltransform
gdaltindex
gdaldem
gdal_create
gdal_viewshed
nearblack
ogrlineref
ogrtindex
gdalwarp
gdal_contour
gdallocationinfo
ogrinfo
ogr2ogr
ogrlineref
nearblack
gdalmdiminfo
gdalmdimtranslate
gnmanalyse
gnmmanage
sozip
AUTO_CLEAN
)
endif()

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
)

file(REMOVE "${CURRENT_PACKAGES_DIR}/bin/gdal-config" "${CURRENT_PACKAGES_DIR}/debug/bin/gdal-config")

file(GLOB bin_files "${CURRENT_PACKAGES_DIR}/bin/*")
if(NOT bin_files)
file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/bin"
"${CURRENT_PACKAGES_DIR}/debug/bin"
)
endif()

vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/cpl_config.h" "#define GDAL_PREFIX \"${CURRENT_PACKAGES_DIR}\"" "")

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/LICENSE.TXT" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
4 changes: 4 additions & 0 deletions vcpkg/overlay/gdal/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The package GDAL provides CMake targets:

find_package(GDAL CONFIG REQUIRED)
target_link_libraries(main PRIVATE GDAL::GDAL)
23 changes: 23 additions & 0 deletions vcpkg/overlay/gdal/vcpkg-cmake-wrapper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_policy(PUSH)
cmake_policy(SET CMP0012 NEW)
cmake_policy(SET CMP0054 NEW)

list(REMOVE_ITEM ARGS "NO_MODULE" "CONFIG" "MODULE")
list(APPEND ARGS "CONFIG")
# The current port version should satisfy GDAL 3.0 ... 3.5
list(GET ARGS 1 vcpkg_gdal_maybe_version)
if(vcpkg_gdal_maybe_version MATCHES "(^3\$|^3[.][0-5])")
list(REMOVE_AT ARGS "1")
endif()
unset(vcpkg_gdal_maybe_version)
_find_package(${ARGS} CONFIG)
if(GDAL_FOUND)
get_filename_component(vcpkg_gdal_prefix "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
set(GDAL_INCLUDE_DIR "${vcpkg_gdal_prefix}/include" CACHE INTERNAL "")
set(GDAL_INCLUDE_DIRS "${GDAL_INCLUDE_DIR}")
set(GDAL_LIBRARY GDAL::GDAL CACHE INTERNAL "")
set(GDAL_LIBRARIES "${GDAL_LIBRARY}")
unset(vcpkg_gdal_prefix)
endif()

cmake_policy(POP)
Loading