[Haskell-beginners] Can I set Cabal conditional options for all build targets

Dimitri DeFigueiredo defigueiredo at ucdavis.edu
Wed Nov 12 00:47:11 UTC 2014


Hi,

Is there a way to set a conditional in a .cabal file that applies to all 
the build targets in the file?
I have many build targets and repeating the conditional for each of them 
doesn't make sense.
But I get an error message when doing that.

For example, I can do this in my example.cabal file:
----
name:                MyExample

build-type:          Simple

-- the conditional flag I want to use
Flag production
   Description: Attempts to get production env
   Default:     True

executable client
   main-is:             client.hs

   if flag(production)
     CPP-Options: -DPRODUCTION

executable server
   main-is:             server.hs

   if flag(production)
     CPP-Options: -DPRODUCTION

------
So I have to specify the options once per target. I get an error message 
if I move the "if flag(production)" outside an "executable" block. And 
the docs "seem to indicate" that's not possible.

Thanks,

Dimitri

PS. I'm using cabal "1.20.0.3"



More information about the Beginners mailing list