Changeset 12396

Show
Ignore:
Timestamp:
10/13/07 06:02:17 (1 year ago)
Author:
rouault
Message:

Add a GDAL_CHECK_VERSION macro and use it in GDAL/OGR drivers that depend on external libraries and may be compiled as plugins (ticket #1899)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/dods/dodsdataset2.cpp

    r11410 r12396  
    16731673{ 
    16741674    GDALDriver *poDriver; 
     1675     
     1676    if (! GDAL_CHECK_VERSION("GDAL/DODS driver")) 
     1677        return; 
    16751678 
    16761679    if( GDALGetDriverByName( "DODS" ) == NULL ) { 
  • trunk/gdal/frmts/ecw/ecwdataset.cpp

    r10970 r12396  
    15091509    GDALDriver  *poDriver; 
    15101510 
     1511    if (! GDAL_CHECK_VERSION("JP2ECW driver")) 
     1512        return; 
    15111513 
    15121514    if( GDALGetDriverByName( "JP2ECW" ) == NULL ) 
  • trunk/gdal/frmts/grass/grass57dataset.cpp

    r11365 r12396  
    970970{ 
    971971    GDALDriver  *poDriver; 
     972     
     973    if (! GDAL_CHECK_VERSION("GDAL/GRASS57 driver")) 
     974        return; 
    972975 
    973976    if( GDALGetDriverByName( "GRASS" ) == NULL ) 
  • trunk/gdal/frmts/grass/grassdataset.cpp

    r10645 r12396  
    575575{ 
    576576    GDALDriver  *poDriver; 
     577     
     578    if (! GDAL_CHECK_VERSION("GDAL/GRASS driver")) 
     579        return; 
    577580 
    578581    if( GDALGetDriverByName( "GRASS" ) == NULL ) 
  • trunk/gdal/frmts/hdf4/hdf4dataset.cpp

    r12194 r12396  
    10931093{ 
    10941094    GDALDriver  *poDriver; 
     1095     
     1096    if (! GDAL_CHECK_VERSION("HDF4 driver")) 
     1097        return; 
    10951098 
    10961099    if( GDALGetDriverByName( "HDF4" ) == NULL ) 
  • trunk/gdal/frmts/hdf5/hdf5imagedataset.cpp

    r10645 r12396  
    453453{ 
    454454    GDALDriver  *poDriver; 
     455     
     456    if (! GDAL_CHECK_VERSION("HDF5Image driver")) 
     457        return; 
    455458 
    456459    if(  GDALGetDriverByName( "HDF5Image" ) == NULL ) 
  • trunk/gdal/frmts/jp2kak/jp2kakdataset.cpp

    r12098 r12396  
    27362736{ 
    27372737    GDALDriver  *poDriver; 
     2738     
     2739    if (! GDAL_CHECK_VERSION("JP2KAK driver")) 
     2740        return; 
    27382741 
    27392742    if( GDALGetDriverByName( "JP2KAK" ) == NULL ) 
  • trunk/gdal/frmts/jpeg2000/jpeg2000dataset.cpp

    r10953 r12396  
    10801080{ 
    10811081    GDALDriver  *poDriver; 
     1082     
     1083    if (! GDAL_CHECK_VERSION("JPEG2000 driver")) 
     1084        return; 
    10821085 
    10831086    if( GDALGetDriverByName( "JPEG2000" ) == NULL ) 
  • trunk/gdal/frmts/mrsid/mrsiddataset.cpp

    r10661 r12396  
    30863086{ 
    30873087    GDALDriver  *poDriver; 
     3088     
     3089    if (! GDAL_CHECK_VERSION("MrSID driver")) 
     3090        return; 
    30883091 
    30893092/* -------------------------------------------------------------------- */ 
  • trunk/gdal/frmts/netcdf/gmtdataset.cpp

    r11897 r12396  
    564564{ 
    565565    GDALDriver  *poDriver; 
     566     
     567    if (! GDAL_CHECK_VERSION("GMT driver")) 
     568        return; 
    566569 
    567570    if( GDALGetDriverByName( "GMT" ) == NULL ) 
  • trunk/gdal/frmts/netcdf/netcdfdataset.cpp

    r11972 r12396  
    24732473{ 
    24742474    GDALDriver  *poDriver; 
     2475 
     2476    if (! GDAL_CHECK_VERSION("netCDF driver")) 
     2477        return; 
    24752478 
    24762479    if( GDALGetDriverByName( "netCDF" ) == NULL ) 
  • trunk/gdal/frmts/ogdi/ogdidataset.cpp

    r10645 r12396  
    943943    GDALDriver  *poDriver; 
    944944 
     945    if (! GDAL_CHECK_VERSION("GDAL/OGDI driver")) 
     946        return; 
     947     
    945948    if( GDALGetDriverByName( "OGDI" ) == NULL ) 
    946949    { 
  • trunk/gdal/frmts/pcraster/pcrastermisc.cpp

    r7553 r12396  
    3030void GDALRegister_PCRaster() 
    3131{ 
    32   if(!GDALGetDriverByName("PCRaster")) { 
     32    if (! GDAL_CHECK_VERSION("PCRaster driver")) 
     33        return; 
     34 
     35if(!GDALGetDriverByName("PCRaster")) { 
    3336 
    3437    GDALDriver* driver = new GDALDriver(); 
     
    4447 
    4548    GetGDALDriverManager()->RegisterDriver(driver); 
    46   } 
    4749} 
     50} 
  • trunk/gdal/frmts/sde/sdedataset.cpp

    r12239 r12396  
    478478{ 
    479479    GDALDriver  *poDriver; 
     480     
     481    if (! GDAL_CHECK_VERSION("SDE driver")) 
     482        return; 
    480483 
    481484    if( GDALGetDriverByName( "SDE" ) == NULL ) 
  • trunk/gdal/gcore/gdal.h

    r12380 r12396  
    500500const char CPL_DLL * CPL_STDCALL GDALVersionInfo( const char * ); 
    501501 
     502#ifndef GDAL_CHECK_VERSION 
     503 
     504/** Return TRUE if GDAL library version at runtime matches nVersionMajor.nVersionMinor. 
     505 
     506    The purpose of this method is to ensure that calling code will run with the GDAL 
     507    version it is compiled for. It is primarly intented for external plugins. 
     508 
     509    @param nVersionMajor Major version to be tested against 
     510    @param nVersionMinor Minor version to be tested against 
     511    @param pszCallingComponentName If not NULL, in case of version mismatch, the method 
     512                                   will issue a failure mentionning the name of 
     513                                   the calling component. 
     514  */ 
     515int CPL_DLL CPL_STDCALL GDALCheckVersion( int nVersionMajor, int nVersionMinor, 
     516                                          const char* pszCallingComponentName); 
     517 
     518/** Helper macro for GDALCheckVersion */ 
     519#define GDAL_CHECK_VERSION(pszCallingComponentName) \ 
     520 GDALCheckVersion(GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, pszCallingComponentName) 
     521 
     522#endif 
     523 
    502524typedef struct {  
    503525    double      dfLINE_OFF; 
  • trunk/gdal/gcore/gdal_misc.cpp

    r12136 r12396  
    16151615 
    16161616/************************************************************************/ 
     1617/*                         GDALCheckVersion()                           */ 
     1618/************************************************************************/ 
     1619 
     1620/** Return TRUE if GDAL library version at runtime matches nVersionMajor.nVersionMinor. 
     1621 
     1622    The purpose of this method is to ensure that calling code will run with the GDAL 
     1623    version it is compiled for. It is primarly intented for external plugins. 
     1624 
     1625    @param nVersionMajor Major version to be tested against 
     1626    @param nVersionMinor Minor version to be tested against 
     1627    @param pszCallingComponentName If not NULL, in case of version mismatch, the method 
     1628                                   will issue a failure mentionning the name of 
     1629                                   the calling component. 
     1630  */ 
     1631int CPL_STDCALL GDALCheckVersion( int nVersionMajor, int nVersionMinor, 
     1632                                  const char* pszCallingComponentName) 
     1633{ 
     1634    if (nVersionMajor == GDAL_VERSION_MAJOR && 
     1635        nVersionMinor == GDAL_VERSION_MINOR) 
     1636        return TRUE; 
     1637 
     1638    if (pszCallingComponentName) 
     1639    { 
     1640        CPLError( CE_Failure, CPLE_AppDefined, 
     1641                  "%s was compiled against GDAL %d.%d but current library version is %d.%d\n", 
     1642                  pszCallingComponentName, nVersionMajor, nVersionMinor, 
     1643                  GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR); 
     1644    } 
     1645    return FALSE; 
     1646} 
     1647 
     1648/************************************************************************/ 
    16171649/*                            GDALDecToDMS()                            */ 
    16181650/*                                                                      */ 
  • trunk/gdal/ogr/ogr_core.h

    r11918 r12396  
    3232 
    3333#include "cpl_port.h" 
     34#include "gdal_version.h" 
    3435 
    3536/** 
     
    312313#define ODrCDeleteDataSource   "DeleteDataSource" 
    313314 
     315/* ------------------------------------------------------------------- */ 
     316/*                        Version checking                             */ 
     317/* -------------------------------------------------------------------- */ 
     318 
     319#ifndef GDAL_CHECK_VERSION 
     320 
     321/** Return TRUE if GDAL library version at runtime matches nVersionMajor.nVersionMinor. 
     322 
     323    The purpose of this method is to ensure that calling code will run with the GDAL 
     324    version it is compiled for. It is primarly intented for external plugins. 
     325 
     326    @param nVersionMajor Major version to be tested against 
     327    @param nVersionMinor Minor version to be tested against 
     328    @param pszCallingComponentName If not NULL, in case of version mismatch, the method 
     329                                   will issue a failure mentionning the name of 
     330                                   the calling component. 
     331  */ 
     332int CPL_DLL CPL_STDCALL GDALCheckVersion( int nVersionMajor, int nVersionMinor, 
     333                                          const char* pszCallingComponentName); 
     334 
     335/** Helper macro for GDALCheckVersion */ 
     336#define GDAL_CHECK_VERSION(pszCallingComponentName) \ 
     337 GDALCheckVersion(GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, pszCallingComponentName) 
     338 
     339#endif 
     340 
    314341CPL_C_END 
    315342 
  • trunk/gdal/ogr/ogrsf_frmts/dods/ogrdodsdriver.cpp

    r10645 r12396  
    9393 
    9494{ 
     95    if (! GDAL_CHECK_VERSION("OGR/DODS driver")) 
     96        return; 
    9597    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRDODSDriver ); 
    9698} 
  • trunk/gdal/ogr/ogrsf_frmts/dxfdwg/ogrdwgdriver.cpp

    r10645 r12396  
    119119 
    120120{ 
     121    if (! GDAL_CHECK_VERSION("DWG/DXF driver")) 
     122        return; 
     123 
    121124    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver(  
    122125        new OGRDWGDriver( "DWG" ) ); 
  • trunk/gdal/ogr/ogrsf_frmts/fme/ogrfmedriver.cpp

    r12123 r12396  
    102102 
    103103{ 
     104    if (! GDAL_CHECK_VERSION("FME driver")) 
     105        return; 
    104106    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRFMEDriver ); 
    105107} 
  • trunk/gdal/ogr/ogrsf_frmts/grass/ogrgrassdriver.cpp

    r10645 r12396  
    106106void RegisterOGRGRASS() 
    107107{ 
     108    if (! GDAL_CHECK_VERSION("OGR/GRASS driver")) 
     109        return; 
    108110    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRGRASSDriver ); 
    109111} 
  • trunk/gdal/ogr/ogrsf_frmts/idb/ogridbdriver.cpp

    r10645 r12396  
    123123 
    124124{ 
     125    if (! GDAL_CHECK_VERSION("IDB driver")) 
     126        return; 
    125127    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRIDBDriver ); 
    126128} 
  • trunk/gdal/ogr/ogrsf_frmts/mysql/ogrmysqldriver.cpp

    r10645 r12396  
    125125 
    126126{ 
     127    if (! GDAL_CHECK_VERSION("MySQL driver")) 
     128        return; 
    127129    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRMySQLDriver ); 
    128130} 
  • trunk/gdal/ogr/ogrsf_frmts/oci/ogrocidriver.cpp

    r10645 r12396  
    117117 
    118118{ 
     119    if (! GDAL_CHECK_VERSION("OCI driver")) 
     120        return; 
    119121    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGROCIDriver ); 
    120122} 
  • trunk/gdal/ogr/ogrsf_frmts/ogdi/ogrogdidriver.cpp

    r10645 r12396  
    100100 
    101101{ 
     102    if (! GDAL_CHECK_VERSION("OGR/OGDI driver")) 
     103        return; 
    102104    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGROGDIDriver ); 
    103105} 
  • trunk/gdal/ogr/ogrsf_frmts/pg/ogrpgdriver.cpp

    r10645 r12396  
    118118 
    119119{ 
     120    if (! GDAL_CHECK_VERSION("PG driver")) 
     121        return; 
    120122    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRPGDriver ); 
    121123} 
  • trunk/gdal/ogr/ogrsf_frmts/sdts/ogrsdtsdriver.cpp

    r10645 r12396  
    9595 
    9696{ 
     97    if (! GDAL_CHECK_VERSION("SDTS driver")) 
     98        return; 
    9799    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRSDTSDriver ); 
    98100} 
  • trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitedriver.cpp

    r10645 r12396  
    154154 
    155155{ 
     156    if (! GDAL_CHECK_VERSION("SQLite driver")) 
     157        return; 
    156158    OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver( new OGRSQLiteDriver ); 
    157159}