Skip to content

Commit

Permalink
Make MapInfo driver optional or buildable as a plugin (if not builtin…
Browse files Browse the repository at this point in the history
…, Northwoord driver is not available, and Shapefile attribute indices too)
  • Loading branch information
rouault committed Sep 22, 2024
1 parent 6ebc888 commit 28a00b0
Show file tree
Hide file tree
Showing 20 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ jobs:
# Build PDF driver as plugin due to the PDFium build including libopenjp2 symbols which would conflict with external libopenjp2
run: |
mkdir -p $GITHUB_WORKSPACE/build
cmake -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DUSE_CCACHE=ON" "-DCMAKE_PREFIX_PATH=${CONDA}/envs/gdalenv" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev" -DCMAKE_BUILD_TYPE=Release -DPDFIUM_ROOT=$GITHUB_WORKSPACE/install-pdfium -DGDAL_ENABLE_DRIVER_PDF_PLUGIN:BOOL=ON -DCMAKE_UNITY_BUILD=ON
cmake -G "${generator}" -Werror=dev "-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install-gdal" "-DUSE_CCACHE=ON" "-DCMAKE_PREFIX_PATH=${CONDA}/envs/gdalenv" -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} -S "$GITHUB_WORKSPACE" -B "$GITHUB_WORKSPACE/build" -DGDAL_ENABLE_PLUGINS:BOOL=ON -DGDAL_ENABLE_PLUGINS_NO_DEPS:BOOL=ON -DGDAL_USE_PUBLICDECOMPWT:BOOL=ON -DPUBLICDECOMPWT_URL=https://github.com/rouault/PublicDecompWT -DBUILD_JAVA_BINDINGS=OFF -DBUILD_CSHARP_BINDINGS=ON -DGDAL_USE_MYSQL:BOOL=OFF -DCMAKE_C_FLAGS=" /WX" -DCMAKE_CXX_FLAGS=" /WX" -DWERROR_DEV_FLAG="-Werror=dev" -DCMAKE_BUILD_TYPE=Release -DPDFIUM_ROOT=$GITHUB_WORKSPACE/install-pdfium -DGDAL_ENABLE_DRIVER_PDF_PLUGIN:BOOL=ON -DCMAKE_UNITY_BUILD=ON -DOGR_ENABLE_DRIVER_TAB_PLUGIN=OFF
- name: Build
shell: bash -l {0}
run: cmake --build $GITHUB_WORKSPACE/build --config Release -j 2
Expand Down
3 changes: 3 additions & 0 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ def test_tiff_read_stats_from_pam(tmp_path):
# Test extracting georeferencing from a .TAB file


@pytest.mark.require_driver("MapInfo File")
def test_tiff_read_from_tab(tmp_path):

ds = gdal.GetDriverByName("GTiff").Create(tmp_path / "tiff_read_from_tab.tif", 1, 1)
Expand Down Expand Up @@ -2822,6 +2823,7 @@ def test_tiff_read_one_strip_no_bytecount():
# Test GDAL_GEOREF_SOURCES


@pytest.mark.require_driver("MapInfo File")
@pytest.mark.parametrize(
"config_option_value,copy_pam,copy_worldfile,copy_tabfile,expected_srs,expected_gt",
[
Expand Down Expand Up @@ -3027,6 +3029,7 @@ def test_tiff_read_nogeoref(
# Test GDAL_GEOREF_SOURCES


@pytest.mark.require_driver("MapInfo File")
@pytest.mark.parametrize(
"config_option_value,copy_pam,copy_worldfile,copy_tabfile,expected_srs,expected_gt",
[
Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,8 @@ def test_driver_open_throw_2():

with gdaltest.enable_exceptions():
drv = ogr.GetDriverByName("MapInfo File")
if not drv:
pytest.skip("MapInfo driver not available")

assert isinstance(drv, ogr.Driver)

Expand Down
1 change: 1 addition & 0 deletions autotest/ogr/ogr_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ def test_ogr_feature_GetFieldAsISO8601DateTime():
assert feature.GetFieldAsISO8601DateTime("field_datetime") == ""


@pytest.mark.require_driver("MapInfo File")
def test_ogr_feature_dump_readable():

ds = ogr.Open("data/mitab/single_point_mapinfo.tab")
Expand Down
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

from osgeo import ogr

pytestmark = pytest.mark.require_driver("MapInfo File")

###############################################################################


Expand Down
3 changes: 3 additions & 0 deletions autotest/ogr/ogr_sql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def test_ogr_sql_13(data_ds):
# Verify selection of, and on ogr_style and ogr_geom_wkt.


@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_14():

expect = [
Expand Down Expand Up @@ -452,6 +453,7 @@ def test_ogr_sql_15(data_ds):
###############################################################################


@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_16():

expect = [2]
Expand All @@ -465,6 +467,7 @@ def test_ogr_sql_16():
###############################################################################
# Test the RFC 21 CAST operator.
#
@pytest.mark.require_driver("MapInfo File")
def test_ogr_sql_17():

expect = ["1", "2"]
Expand Down
2 changes: 2 additions & 0 deletions autotest/osr/osr_micoordsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

from osgeo import osr

pytestmark = pytest.mark.require_driver("MapInfo File")

###############################################################################
# Test the osr.SpatialReference.ImportFromMICoordSys() function.
#
Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gdal_rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def gdal_rasterize_path():
# Simple polygon rasterization (adapted from alg/rasterize.py).


@pytest.mark.require_driver("MapInfo File")
def test_gdal_rasterize_1(gdal_rasterize_path, tmp_path):

output_tif = str(tmp_path / "rast1.tif")
Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gdalsrsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_gdalsrsinfo_6(gdalsrsinfo_path):
# Test -o mapinfo option


@pytest.mark.require_driver("MapInfo File")
def test_gdalsrsinfo_7(gdalsrsinfo_path):

ret = gdaltest.runexternal(gdalsrsinfo_path + " -o mapinfo ../gcore/data/byte.tif")
Expand Down
1 change: 1 addition & 0 deletions autotest/utilities/test_gdaltindex_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def test_gdaltindex_lib_outputSRS_writeAbsoluePath(tmp_path, four_tile_index):
# Test -f, -lyr_name


@pytest.mark.require_driver("MapInfo File")
def test_gdaltindex_lib_format_layerName(tmp_path, four_tiles):

index_mif = str(tmp_path / "test_gdaltindex6.mif")
Expand Down
6 changes: 0 additions & 6 deletions cmake/helpers/GdalDriverHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,3 @@ macro(ogr_default_driver name desc)
add_feature_info(ogr_${key} OGR_ENABLE_DRIVER_${key} "${desc}")
add_subdirectory(${name})
endmacro()
macro(ogr_default_driver2 name key desc)
set(OGR_ENABLE_DRIVER_${key} ON CACHE BOOL "${desc}" FORCE)
add_feature_info(ogr_${key} OGR_ENABLE_DRIVER_${key} "${desc}")
add_subdirectory(${name})
endmacro()

4 changes: 3 additions & 1 deletion frmts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ gdal_optional_format(blx "Magellan BLX Topo File Format")
gdal_optional_format(msgn "Meteosat Second Generation (MSG) Native Archive Format (.nat)")
gdal_optional_format(til "EarthWatch .TIL Driver")
gdal_optional_format(r "R Object Data Store")
gdal_optional_format(northwood "NWT_GRD/NWT_GRC -- Northwood/Vertical Mapper File Format")
if (NOT OGR_ENABLE_DRIVER_TAB_PLUGIN)
gdal_dependent_format(northwood "NWT_GRD/NWT_GRC -- Northwood/Vertical Mapper File Format" "OGR_ENABLE_DRIVER_TAB")
endif()
gdal_optional_format(saga "SAGA GIS Binary Driver")
gdal_optional_format(xyz "ASCII Gridded XYZ")
include(avif/driver_declaration.cmake)
Expand Down
10 changes: 10 additions & 0 deletions gdal.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ if (GDAL_USE_SHAPELIB_INTERNAL)
mark_as_advanced(RENAME_INTERNAL_SHAPELIB_SYMBOLS)
endif ()

# Must be set before including ogr
option(OGR_ENABLE_DRIVER_TAB
"Set ON to build MapInfo TAB and MIF/MID driver (required by Northwoord driver, and Shapefile attribute indexing)"
${OGR_BUILD_OPTIONAL_DRIVERS})
if(OGR_ENABLE_DRIVER_TAB AND
NOT DEFINED OGR_ENABLE_DRIVER_TAB_PLUGIN AND
GDAL_ENABLE_PLUGINS_NO_DEPS)
option(OGR_ENABLE_DRIVER_TAB_PLUGIN "Set ON to build OGR MapInfo TAB and MIF/MID driver as plugin" ON)
endif()

# Core components
add_subdirectory(alg)
add_subdirectory(ogr)
Expand Down
6 changes: 4 additions & 2 deletions ogr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ target_include_directories(ogr PRIVATE $<TARGET_PROPERTY:ogr_MEM,SOURCE_DIR>)
set_property(TARGET ogr PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:ogr>)

if (OGR_ENABLE_DRIVER_TAB AND NOT OGR_ENABLE_DRIVER_TAB_PLUGIN)
target_compile_definitions(ogr PRIVATE -DHAVE_MITAB)
endif()

if (GDAL_USE_ZLIB_INTERNAL)
gdal_add_vendored_lib(ogr libz)
endif ()
Expand All @@ -103,8 +107,6 @@ if (GDAL_USE_JSONC_INTERNAL)
gdal_add_vendored_lib(ogr libjson)
endif ()

target_compile_definitions(ogr PRIVATE HAVE_MITAB)

gdal_target_link_libraries(ogr PRIVATE PROJ::proj)

# External libs then
Expand Down
7 changes: 6 additions & 1 deletion ogr/ogrsf_frmts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ add_dependencies(ogrsf_frmts generate_gdal_version_h)
# Obligatory for building GDAL; always compile in.
ogr_default_driver(mem "Read/write driver for MEMORY virtual files")
ogr_optional_driver(geojson "GeoJSON/ESRIJSON/TopoJSON driver")
ogr_default_driver2(mitab TAB "MapInfo TAB and MIF/MID")

add_feature_info(ogr_TAB OGR_ENABLE_DRIVER_TAB "MapInfo TAB and MIF/MID")
if (OGR_ENABLE_DRIVER_TAB)
add_subdirectory(mitab)
endif ()

ogr_optional_driver(shape "ESRI shape-file")

# ######################################################################################################################
Expand Down
4 changes: 4 additions & 0 deletions ogr/ogrsf_frmts/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ add_dependencies(ogrsf_generic generate_gdal_version_h)
target_compile_options(ogrsf_generic PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
target_sources(${GDAL_LIB_TARGET_NAME} PRIVATE $<TARGET_OBJECTS:ogrsf_generic>)
set_property(TARGET ogrsf_generic PROPERTY POSITION_INDEPENDENT_CODE ${GDAL_OBJECT_LIBRARIES_POSITION_INDEPENDENT_CODE})

if (OGR_ENABLE_DRIVER_TAB AND NOT OGR_ENABLE_DRIVER_TAB_PLUGIN)
target_compile_definitions(ogrsf_generic PRIVATE -DHAVE_MITAB)
endif()
17 changes: 17 additions & 0 deletions ogr/ogrsf_frmts/generic/ogr_miattrind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
****************************************************************************/

#include "ogr_attrind.h"

#ifdef HAVE_MITAB

#include "mitab/mitab_priv.h"
#include "cpl_minixml.h"

Expand Down Expand Up @@ -829,3 +832,17 @@ OGRErr OGRMIAttrIndex::Clear()
{
return OGRERR_UNSUPPORTED_OPERATION;
}

#else

/************************************************************************/
/* OGRCreateDefaultLayerIndex() */
/************************************************************************/

OGRLayerAttrIndex *OGRCreateDefaultLayerIndex()

{
return nullptr;
}

#endif
7 changes: 6 additions & 1 deletion ogr/ogrsf_frmts/generic/ogrlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1943,9 +1943,11 @@ void OGR_L_ResetReading(OGRLayerH hLayer)
/************************************************************************/

//! @cond Doxygen_Suppress
OGRErr OGRLayer::InitializeIndexSupport(const char *pszFilename)
OGRErr
OGRLayer::InitializeIndexSupport([[maybe_unused]] const char *pszFilename)

{
#ifdef HAVE_MITAB
OGRErr eErr;

if (m_poAttrIndex != nullptr)
Expand All @@ -1961,6 +1963,9 @@ OGRErr OGRLayer::InitializeIndexSupport(const char *pszFilename)
}

return eErr;
#else
return OGRERR_FAILURE;
#endif
}

//! @endcond
Expand Down
3 changes: 2 additions & 1 deletion ogr/ogrsf_frmts/mitab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
add_gdal_driver(
TARGET ogr_TAB
DEF MITAB_ENABLED
BUILTIN
PLUGIN_CAPABLE
NO_DEPS
SOURCES mitab_rawbinblock.cpp
mitab_mapheaderblock.cpp
mitab_mapindexblock.cpp
Expand Down
6 changes: 4 additions & 2 deletions ogr/ogrspatialreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11251,7 +11251,8 @@ OGRErr OSRExportToMICoordSys(OGRSpatialReferenceH hSRS, char **ppszReturn)
* OGRERR_UNSUPPORTED_OPERATION if MITAB library was not linked in.
*/

OGRErr OGRSpatialReference::exportToMICoordSys(char **ppszResult) const
OGRErr OGRSpatialReference::exportToMICoordSys(
[[maybe_unused]] char **ppszResult) const

{
#ifdef HAVE_MITAB
Expand Down Expand Up @@ -11305,7 +11306,8 @@ OGRErr OSRImportFromMICoordSys(OGRSpatialReferenceH hSRS,
* OGRERR_UNSUPPORTED_OPERATION if MITAB library was not linked in.
*/

OGRErr OGRSpatialReference::importFromMICoordSys(const char *pszCoordSys)
OGRErr OGRSpatialReference::importFromMICoordSys(
[[maybe_unused]] const char *pszCoordSys)

{
#ifdef HAVE_MITAB
Expand Down

0 comments on commit 28a00b0

Please sign in to comment.