Skip to content
Permalink
Browse files

Set GDAL env vars for when gdal lib is bundled in app on Mac

  • Loading branch information
dakcarto committed Mar 20, 2015
1 parent 8c8a9e0 commit 12e0f358a8758b8947aef20263e5e119814ea4d3
Showing with 72 additions and 0 deletions.
  1. +18 −0 src/app/main.cpp
  2. +2 −0 src/browser/CMakeLists.txt
  3. +28 −0 src/browser/main.cpp
  4. +6 −0 tests/bench/CMakeLists.txt
  5. +18 −0 tests/bench/main.cpp
@@ -682,6 +682,24 @@ int main( int argc, char *argv[] )
{
setenv( "GDAL_DRIVER_PATH", gdalPlugins.toUtf8(), 1 );
}

// Point GDAL_DATA at any GDAL share directory embedded in the app bundle
if ( !getenv( "GDAL_DATA" ) )
{
QStringList gdalShares;
QString appResources( QDir::cleanPath( QgsApplication::pkgDataPath() ) );
gdalShares << QCoreApplication::applicationDirPath().append( "/share/gdal" )
<< appResources.append( "/share/gdal" )
<< appResources.append( "/gdal" );
Q_FOREACH ( const QString& gdalShare, gdalShares )
{
if ( QFile::exists( gdalShare ) )
{
setenv( "GDAL_DATA", gdalShare.toUtf8().constData(), 1 );
break;
}
}
}
#endif

QSettings mySettings;
@@ -103,4 +103,6 @@ IF (APPLE)
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../../${QGIS_LIB_SUBDIR} \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/QGIS Browser.app/Contents/MacOS/lib\")")
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../${QGIS_PLUGIN_SUBDIR}/.. \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/QGIS Browser.app/Contents/Plugins\")")
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../${QGIS_DATA_SUBDIR} \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/QGIS Browser.app/Contents/Resources\")")
# may not exist, unless BundleUtilities are used
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../../share \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/QGIS Browser.app/Contents/MacOS/share\")")
ENDIF (APPLE)
@@ -51,6 +51,34 @@ int main( int argc, char ** argv )
QCoreApplication::setOrganizationDomain( "qgis.org" );
QCoreApplication::setApplicationName( "QGIS2" );

#ifdef Q_OS_MACX
// If the GDAL plugins are bundled with the application and GDAL_DRIVER_PATH
// is not already defined, use the GDAL plugins in the application bundle.
QString gdalPlugins( QCoreApplication::applicationDirPath().append( "/lib/gdalplugins" ) );
if ( QFile::exists( gdalPlugins ) && !getenv( "GDAL_DRIVER_PATH" ) )
{
setenv( "GDAL_DRIVER_PATH", gdalPlugins.toUtf8(), 1 );
}

// Point GDAL_DATA at any GDAL share directory embedded in the app bundle
if ( !getenv( "GDAL_DATA" ) )
{
QStringList gdalShares;
QString appResources( QDir::cleanPath( QgsApplication::pkgDataPath() ) );
gdalShares << QCoreApplication::applicationDirPath().append( "/share/gdal" )
<< appResources.append( "/share/gdal" )
<< appResources.append( "/gdal" );
Q_FOREACH ( const QString& gdalShare, gdalShares )
{
if ( QFile::exists( gdalShare ) )
{
setenv( "GDAL_DATA", gdalShare.toUtf8().constData(), 1 );
break;
}
}
}
#endif

QgsBrowser w;

a.connect( &a, SIGNAL( aboutToQuit() ), &w, SLOT( saveWindowState() ) );
@@ -53,5 +53,11 @@ INSTALL (TARGETS qgis_bench
)
IF (APPLE)
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../${QGIS_FW_SUBDIR} \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/qgis_bench.app/Contents/Frameworks\")")
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../../${QGIS_LIB_SUBDIR} \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/qgis_bench.app/Contents/MacOS/lib\")")
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../${QGIS_PLUGIN_SUBDIR}/.. \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/qgis_bench.app/Contents/Plugins\")")
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../${QGIS_DATA_SUBDIR} \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/qgis_bench.app/Contents/Resources\")")
# may not exist, unless BundleUtilities are used
INSTALL (CODE "EXECUTE_PROCESS(COMMAND ln -sfh ../../../../share \"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${QGIS_BIN_DIR}/qgis_bench.app/Contents/MacOS/share\")")

ENDIF (APPLE)

@@ -407,6 +407,24 @@ int main( int argc, char *argv[] )
{
setenv( "GDAL_DRIVER_PATH", gdalPlugins.toUtf8(), 1 );
}

// Point GDAL_DATA at any GDAL share directory embedded in the app bundle
if ( !getenv( "GDAL_DATA" ) )
{
QStringList gdalShares;
QString appResources( QDir::cleanPath( QgsApplication::pkgDataPath() ) );
gdalShares << QCoreApplication::applicationDirPath().append( "/share/gdal" )
<< appResources.append( "/share/gdal" )
<< appResources.append( "/gdal" );
Q_FOREACH ( const QString& gdalShare, gdalShares )
{
if ( QFile::exists( gdalShare ) )
{
setenv( "GDAL_DATA", gdalShare.toUtf8().constData(), 1 );
break;
}
}
}
#endif

QSettings mySettings;

0 comments on commit 12e0f35

Please sign in to comment.
You can’t perform that action at this time.