Reputation: 22500
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
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