Skip to content

Commit

Permalink
added autoconfig flag to enable/disable the use of gdal-config for co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
Alberto Valverde committed Feb 27, 2016
1 parent 603e7a7 commit 11088ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
17 changes: 9 additions & 8 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ import Data.Maybe
import System.Process
import System.IO
import System.Exit
import Data.List
import Distribution.Simple
import Distribution.Simple.Setup (configConfigurationsFlags)
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo

main = defaultMainWithHooks simpleUserHooks {confHook = gdalConf}

gdalConf (pkg0, pbi) flags = do
lbi <- confHook simpleUserHooks (pkg0, pbi) flags
case FlagName "autoconfig" `lookup` configConfigurationsFlags flags of
Just False -> putStrLn "NOT using gdal-config" >> return lbi
_ -> putStrLn "Using gdal-config" >> configureWithGdalConfig lbi

configureWithGdalConfig lbi = do
gdalInclude <- liftM (getFlagValues 'I') $ getOutput "gdal-config" ["--cflags"]
gdalLibDirs <- liftM (getFlagValues 'L') $ getOutput "gdal-config" ["--libs"]
gdalLibs <- liftM (getFlagValues 'l') $ getOutput "gdal-config" ["--libs"]
gdalVers <- getOutput "gdal-config" ["--version"]
let (vMajor,r) = break (=='.') gdalVers
(vMinor,_) = break (=='.') (tail r)
updBinfo bi = bi { extraLibDirs = extraLibDirs bi ++ gdalLibDirs
let updBinfo bi = bi { extraLibDirs = extraLibDirs bi ++ gdalLibDirs
, extraLibs = extraLibs bi ++ gdalLibs
, includeDirs = includeDirs bi ++ gdalInclude
, cppOptions = cppOptions bi ++
[ "-DGDAL_VERSION_MAJOR=" ++ vMajor
, "-DGDAL_VERSION_MINOR=" ++ vMinor]
}
updLib lib = lib { libBuildInfo = updBinfo (libBuildInfo lib)}
updTs ts = ts { testBuildInfo = updBinfo (testBuildInfo ts)}
Expand All @@ -32,7 +34,6 @@ gdalConf (pkg0, pbi) flags = do
, benchmarks = map updBm (benchmarks lpd)
, executables = map updExe (executables lpd)
}
lbi <- confHook simpleUserHooks (pkg0, pbi) flags
return (lbi { localPkgDescr = updLpd (localPkgDescr lbi) })

getOutput s a = readProcess s a ""
Expand Down
6 changes: 6 additions & 0 deletions bindings-gdal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ flag examples
default: False
manual: True

flag autoconfig
description:
Use gdal-config to set extra-libraries, extra-lib-dirs and include-dirs.
default: True

source-repository head
type: git
location: https://github.com/meteogrid/bindings-gdal.git
Expand Down Expand Up @@ -71,6 +76,7 @@ library
, unordered-containers
, ghc-prim
, monad-control
extra-libraries: gdal
ghc-options: -funbox-strict-fields -Wall
install-includes: bindings.h
default-extensions: CPP
Expand Down
5 changes: 3 additions & 2 deletions src/GDAL/Internal/OGR.chs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
{-# LANGUAGE DeriveDataTypeable #-}

#include "bindings.h"
#include "gdal.h"
#include "ogr_api.h"


module GDAL.Internal.OGR (
DataSource
Expand Down Expand Up @@ -147,8 +150,6 @@ import GDAL.Internal.CPLError
import GDAL.Internal.Util
import GDAL.Internal.Types

#include "ogr_api.h"

{#fun RegisterAll as ^ {} -> `()' #}
{#fun CleanupAll as ^ {} -> `()' #}

Expand Down
10 changes: 5 additions & 5 deletions src/GDAL/Internal/OGRFeature.chs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
{-# LANGUAGE ScopedTypeVariables #-}

#include "bindings.h"
#include "gdal.h"
#include "ogr_core.h"
#include "ogr_api.h"
#include "cpl_string.h"


module GDAL.Internal.OGRFeature (
OGRFeature (..)
Expand Down Expand Up @@ -110,11 +115,6 @@ import GDAL.Internal.CPLString (peekEncodedCString, useAsEncodedCString)
{#import GDAL.Internal.OGRGeometry #}
{#import GDAL.Internal.OGRError #}

#include "gdal.h"
#include "ogr_core.h"
#include "ogr_api.h"
#include "cpl_string.h"

newtype Fid = Fid { unFid :: Int64 }
deriving (Eq, Num)

Expand Down

0 comments on commit 11088ae

Please sign in to comment.