Skip to content

Commit

Permalink
Merge pull request #10420 from rouault/standalone_ecw
Browse files Browse the repository at this point in the history
CMake: make it possible to build ECW and GeoRaster drivers in standalone mode
  • Loading branch information
rouault authored Jul 18, 2024
2 parents 18ed4a0 + 003242a commit 126a885
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 55 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/ubuntu_20.04/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ unset CFLAGS
make "-j$(nproc)"
make "-j$(nproc)" install

# Download Oracle SDK
wget https://download.oracle.com/otn_software/linux/instantclient/1923000/instantclient-basic-linux.x64-19.23.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/1923000/instantclient-sdk-linux.x64-19.23.0.0.0dbru.zip
unzip -o instantclient-basic-linux.x64-19.23.0.0.0dbru.zip
unzip -o instantclient-sdk-linux.x64-19.23.0.0.0dbru.zip

# Test building MrSID driver in standalone mode
mkdir build_mrsid
cd build_mrsid
Expand All @@ -34,15 +40,19 @@ cd ..
# Test building OCI driver in standalone mode
mkdir build_oci
cd build_oci
wget https://download.oracle.com/otn_software/linux/instantclient/1923000/instantclient-basic-linux.x64-19.23.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/1923000/instantclient-sdk-linux.x64-19.23.0.0.0dbru.zip
unzip -o instantclient-basic-linux.x64-19.23.0.0.0dbru.zip
unzip -o instantclient-sdk-linux.x64-19.23.0.0.0dbru.zip
cmake -S "${GDAL_SOURCE_DIR:=..}/ogr/ogrsf_frmts/oci" "-DOracle_ROOT=$PWD/instantclient_19_23" -DCMAKE_PREFIX_PATH=/tmp/install-gdal
cmake -S "${GDAL_SOURCE_DIR:=..}/ogr/ogrsf_frmts/oci" "-DOracle_ROOT=$PWD/../instantclient_19_23" -DCMAKE_PREFIX_PATH=/tmp/install-gdal
cmake --build . "-j$(nproc)"
test -f ogr_OCI.so
cd ..

# Test building GeoRaster driver in standalone mode
mkdir build_georaster
cd build_georaster
cmake -S "${GDAL_SOURCE_DIR:=..}/frmts/georaster" -DCMAKE_PREFIX_PATH=/tmp/install-gdal "-DOracle_ROOT=$PWD/../instantclient_19_23"
cmake --build . "-j$(nproc)"
test -f gdal_GEOR.so
cd ..

# Test building Parquet driver in standalone mode
mkdir build_parquet
cd build_parquet
Expand Down Expand Up @@ -74,3 +84,11 @@ cmake -S "${GDAL_SOURCE_DIR:=..}/frmts/tiledb" -DCMAKE_PREFIX_PATH=/tmp/install-
cmake --build . "-j$(nproc)"
test -f gdal_TileDB.so
cd ..

# Test building ECW driver in standalone mode
mkdir build_ecw
cd build_ecw
cmake -S "${GDAL_SOURCE_DIR:=..}/frmts/ecw" -DCMAKE_PREFIX_PATH=/tmp/install-gdal -DECW_ROOT=/opt/libecwj2-3.3
cmake --build . "-j$(nproc)"
test -f gdal_ECW_JP2ECW.so
cd ..
50 changes: 5 additions & 45 deletions cmake/helpers/CheckDependentLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ endif()

gdal_check_package(XercesC "Read and write XML formats (needed for GMLAS and ILI drivers)" CAN_DISABLE)

gdal_check_package(ZLIB "zlib (external)" CAN_DISABLE)
gdal_internal_library(ZLIB REQUIRED)
include(CheckDependentLibrariesZLIB)

gdal_check_package(Deflate "Enable libdeflate compression library (complement to ZLib)" CAN_DISABLE)

Expand Down Expand Up @@ -168,46 +167,7 @@ include(CheckDependentLibrariesGeoTIFF)
gdal_check_package(PNG "PNG compression library (external)" CAN_DISABLE RECOMMENDED VERSION "1.6")
gdal_internal_library(PNG)

gdal_check_package(JPEG "JPEG compression library (external)" CAN_DISABLE RECOMMENDED)
if (GDAL_USE_JPEG AND (JPEG_LIBRARY MATCHES ".*turbojpeg\.(so|lib)"))
message(
FATAL_ERROR
"JPEG_LIBRARY should point to a library with libjpeg ABI, not TurboJPEG. See https://libjpeg-turbo.org/About/TurboJPEG for the difference"
)
endif ()
if (GDAL_USE_JPEG AND TARGET JPEG::JPEG)
set(EXPECTED_JPEG_LIB_VERSION "" CACHE STRING "Expected libjpeg version number")
mark_as_advanced(GDAL_CHECK_PACKAGE_${name}_NAMES)
if (EXPECTED_JPEG_LIB_VERSION)
get_property(_jpeg_old_icd TARGET JPEG::JPEG PROPERTY INTERFACE_COMPILE_DEFINITIONS)
set_property(TARGET JPEG::JPEG PROPERTY
INTERFACE_COMPILE_DEFINITIONS "${_jpeg_old_icd};EXPECTED_JPEG_LIB_VERSION=${EXPECTED_JPEG_LIB_VERSION}")
endif()

# Check for jpeg12_read_scanlines() which has been added in libjpeg-turbo 2.2
# for dual 8/12 bit mode.
include(CheckCSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARIES}")
check_c_source_compiles(
"
#include <stddef.h>
#include <stdio.h>
#include \"jpeglib.h\"
int main()
{
jpeg_read_scanlines(0,0,0);
jpeg12_read_scanlines(0,0,0);
return 0;
}
"
HAVE_JPEGTURBO_DUAL_MODE_8_12)
cmake_pop_check_state()

endif()
gdal_internal_library(JPEG)
include(CheckDependentLibrariesJpeg)

gdal_check_package(GIF "GIF compression library (external)" CAN_DISABLE)
gdal_internal_library(GIF)
Expand Down Expand Up @@ -443,7 +403,8 @@ gdal_check_package(GEOS "Geometry Engine - Open Source (GDAL core dependency)" R
)
gdal_check_package(HDF4 "Enable HDF4 driver" CAN_DISABLE)

gdal_check_package(ECW "Enable ECW driver" CAN_DISABLE)
include(CheckDependentLibrariesECW)

gdal_check_package(NetCDF "Enable netCDF driver" CAN_DISABLE
NAMES netCDF
TARGETS netCDF::netcdf NETCDF::netCDF
Expand Down Expand Up @@ -501,8 +462,7 @@ gdal_check_package(PDFIUM "Enable PDF driver with Pdfium (read side)" CAN_DISABL
gdal_check_package(Podofo "Enable PDF driver with Podofo (read side)" CAN_DISABLE)


set(Oracle_CAN_USE_CLNTSH_AS_MAIN_LIBRARY ON)
gdal_check_package(Oracle "Enable Oracle OCI driver" CAN_DISABLE)
include(CheckDependentLibrariesOracle)
gdal_check_package(TEIGHA "Enable DWG and DGNv8 drivers" CAN_DISABLE)
gdal_check_package(FileGDB "Enable FileGDB (based on closed-source SDK) driver" CAN_DISABLE)

Expand Down
1 change: 1 addition & 0 deletions cmake/helpers/CheckDependentLibrariesECW.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gdal_check_package(ECW "Enable ECW driver" CAN_DISABLE)
40 changes: 40 additions & 0 deletions cmake/helpers/CheckDependentLibrariesJpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
gdal_check_package(JPEG "JPEG compression library (external)" CAN_DISABLE RECOMMENDED)
if (GDAL_USE_JPEG AND (JPEG_LIBRARY MATCHES ".*turbojpeg\.(so|lib)"))
message(
FATAL_ERROR
"JPEG_LIBRARY should point to a library with libjpeg ABI, not TurboJPEG. See https://libjpeg-turbo.org/About/TurboJPEG for the difference"
)
endif ()
if (GDAL_USE_JPEG AND TARGET JPEG::JPEG)
set(EXPECTED_JPEG_LIB_VERSION "" CACHE STRING "Expected libjpeg version number")
mark_as_advanced(GDAL_CHECK_PACKAGE_${name}_NAMES)
if (EXPECTED_JPEG_LIB_VERSION)
get_property(_jpeg_old_icd TARGET JPEG::JPEG PROPERTY INTERFACE_COMPILE_DEFINITIONS)
set_property(TARGET JPEG::JPEG PROPERTY
INTERFACE_COMPILE_DEFINITIONS "${_jpeg_old_icd};EXPECTED_JPEG_LIB_VERSION=${EXPECTED_JPEG_LIB_VERSION}")
endif()

# Check for jpeg12_read_scanlines() which has been added in libjpeg-turbo 2.2
# for dual 8/12 bit mode.
include(CheckCSourceCompiles)
include(CMakePushCheckState)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES "${JPEG_INCLUDE_DIRS}")
set(CMAKE_REQUIRED_LIBRARIES "${JPEG_LIBRARIES}")
check_c_source_compiles(
"
#include <stddef.h>
#include <stdio.h>
#include \"jpeglib.h\"
int main()
{
jpeg_read_scanlines(0,0,0);
jpeg12_read_scanlines(0,0,0);
return 0;
}
"
HAVE_JPEGTURBO_DUAL_MODE_8_12)
cmake_pop_check_state()

endif()
gdal_internal_library(JPEG)
2 changes: 0 additions & 2 deletions cmake/helpers/CheckDependentLibrariesOCI.cmake

This file was deleted.

2 changes: 2 additions & 0 deletions cmake/helpers/CheckDependentLibrariesOracle.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(Oracle_CAN_USE_CLNTSH_AS_MAIN_LIBRARY ON)
gdal_check_package(Oracle "Enable Oracle OCI and GeoRaster drivers" CAN_DISABLE)
2 changes: 2 additions & 0 deletions cmake/helpers/CheckDependentLibrariesZLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gdal_check_package(ZLIB "zlib (external)" CAN_DISABLE)
gdal_internal_library(ZLIB REQUIRED)
25 changes: 25 additions & 0 deletions doc/source/drivers/raster/ecw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,31 @@ File Metadata Keys:
uncompressed file size by 5), etc...
- VERSION

Standalone plugin compilation
-----------------------------

.. versionadded:: 3.10

While this driver may be built as part of a whole GDAL build, either in libgdal
itself, or as a plugin, it is also possible to only build this driver as a plugin,
against an already built libgdal.

The version of the GDAL sources used to build the driver must match the version
of the libgdal it is built against.

For example, from a "build_georaster" directory under the root of the GDAL source tree:

::

cmake -S ../frmts/ecw -DCMAKE_PREFIX_PATH=/path/to/GDAL_installation_prefix -DECW_ROOT=/path/to/ecw_sdk_root
cmake --build .


Note that such a plugin, when used against a libgdal not aware of it, will be
systematically loaded at GDAL driver initialization time, and will not benefit from
`deferred plugin loading capabilities <rfc-96>`. For that, libgdal itself must be built with the
CMake variable GDAL_REGISTER_DRIVER_ECW_FOR_LATER_PLUGIN=ON set.

See Also
--------

Expand Down
25 changes: 25 additions & 0 deletions doc/source/drivers/raster/georaster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,28 @@ system so one alternative is to create VRT to represent the GeoRaster descriptio
% gdal_translate -of VRT geor:scott/tiger@dbdemo,landsat,scene,id=54 view_54.vrt
% openenv view_54.vrt
Standalone plugin compilation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 3.10

While this driver may be built as part of a whole GDAL build, either in libgdal
itself, or as a plugin, it is also possible to only build this driver as a plugin,
against an already built libgdal.

The version of the GDAL sources used to build the driver must match the version
of the libgdal it is built against.

For example, from a "build_georaster" directory under the root of the GDAL source tree:

::

cmake -S ../frmts/georaster -DCMAKE_PREFIX_PATH=/path/to/GDAL_installation_prefix -DOracle_ROOT=/path/to/instantclient_sdk_root
cmake --build .


Note that such a plugin, when used against a libgdal not aware of it, will be
systematically loaded at GDAL driver initialization time, and will not benefit from
`deferred plugin loading capabilities <rfc-96>`. For that, libgdal itself must be built with the
CMake variable GDAL_REGISTER_DRIVER_GEOR_FOR_LATER_PLUGIN=ON set.
4 changes: 2 additions & 2 deletions frmts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ gdal_dependent_format(jp2lura "JPEG-2000 (based on Luratech)" "GDAL_USE_LURATECH
gdal_dependent_format(sde "ESRI ArcSDE Raster" "HAVE_SDE")
# LizardTech's decoding software development kit (DSDK)
include(mrsid/driver_declaration.cmake)
gdal_dependent_format(georaster "Oracle Spatial GeoRaster" "GDAL_USE_ORACLE" DRIVER_NAME_OPTION GEOR)
gdal_dependent_format(ecw "ERDAS JPEG2000 (.jp2)" "GDAL_USE_ECW")
include(georaster/driver_declaration.cmake)
include(ecw/driver_declaration.cmake)

# Register all frmt drivers according to FRMT_<driver> flags
gdal_standard_includes(gdal_frmts)
Expand Down
11 changes: 11 additions & 0 deletions frmts/ecw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/helpers/GdalCMakeMinimumRequired.cmake")
cmake_minimum_required(VERSION ${GDAL_CMAKE_VERSION_MIN}...${GDAL_CMAKE_VERSION_MAX})

if(NOT DEFINED PROJECT_SOURCE_DIR)
# Standalone plugin building
project(gdal_ECW_JP2ECW)
include("${PROJECT_SOURCE_DIR}/../../cmake/helpers/SetupStandalonePlugin.cmake" )
include(CheckDependentLibrariesECW)
standalone_driver_finalize(GDAL_ENABLE_DRIVER_ECW)
endif()

set(SOURCE ecwdataset.cpp ecwcreatecopy.cpp ecwasyncreader.cpp jp2userbox.cpp)
add_gdal_driver(
TARGET gdal_ECW_JP2ECW
Expand Down
1 change: 1 addition & 0 deletions frmts/ecw/driver_declaration.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gdal_dependent_format(ecw "ERDAS JPEG2000 (.jp2)" "GDAL_USE_ECW")
19 changes: 19 additions & 0 deletions frmts/georaster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/helpers/GdalCMakeMinimumRequired.cmake")
cmake_minimum_required(VERSION ${GDAL_CMAKE_VERSION_MIN}...${GDAL_CMAKE_VERSION_MAX})

if(NOT DEFINED PROJECT_SOURCE_DIR)
# Standalone plugin building
project(gdal_GEOR)
include("${PROJECT_SOURCE_DIR}/../../cmake/helpers/SetupStandalonePlugin.cmake")
include(CheckDependentLibrariesZLIB)
include(CheckDependentLibrariesJpeg)
include(CheckDependentLibrariesOracle)
if (GDAL_USE_ZLIB_INTERNAL)
message(FATAL_ERROR "Internal zlib not supported for GeoRaster standalone plugin build")
endif()
if (GDAL_USE_JPEG_INTERNAL)
message(FATAL_ERROR "Internal libjpeg not supported for GeoRaster standalone plugin build")
endif()
standalone_driver_finalize(GDAL_ENABLE_DRIVER_GEOR)
endif()

add_gdal_driver(
TARGET gdal_GEOR
SOURCES georaster_dataset.cpp georaster_priv.h georaster_rasterband.cpp georaster_wrapper.cpp oci_wrapper.cpp
Expand Down
1 change: 1 addition & 0 deletions frmts/georaster/driver_declaration.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gdal_dependent_format(georaster "Oracle Spatial GeoRaster" "GDAL_USE_ORACLE" DRIVER_NAME_OPTION GEOR)
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/oci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(NOT DEFINED PROJECT_SOURCE_DIR)
# Standalone plugin building
project(ogr_OCI)
include("${PROJECT_SOURCE_DIR}/../../../cmake/helpers/SetupStandalonePlugin.cmake" )
include(CheckDependentLibrariesOCI)
include(CheckDependentLibrariesOracle)
standalone_driver_finalize(OGR_ENABLE_DRIVER_OCI)
endif()

Expand Down

0 comments on commit 126a885

Please sign in to comment.