thor
thor

Reputation: 22500

Getting the cabal version of a GHC compiled program?

If I compile an executable using GHC's cabal build, is there a way to get the version number as stated in the project .cabal file, from inside the main function?

For example, we can get the main program name using:

import System.Environment
main = do
    progName <- getProgName
    ...

Can we somehow write a similar function getProgVer to get the cabal-defined version number?

Upvotes: 1

Views: 135

Answers (1)

ase
ase

Reputation: 13471

Yes you can:

import Paths_PKGNAME

main = print version

Cabal will create a module Paths_PKGNAME (where PKGNAME is the name of your package) which contains among other things the version of the package. More info in the users guide.

Upvotes: 6

Related Questions