Is it possible to specify example executables for a library as optional in a cabal package?

StackOverflow https://stackoverflow.com/questions/22094354

  •  18-10-2022
  •  | 
  •  

Question

I.e. this isn't legal:

if someFlag {
  executable someExec {
  }
}

Is there some way to do this anyway? If not, is it good practice to supply examples as a separate cabal package instead?

Was it helpful?

Solution

reactive-banana-wx does exactly this.

First, define a flag:

flag buildExamples
    description: Build example executables
    default: False

Then, for each executable, you can set buildable : false to not build it:

Executable Arithmetic
    if flag(buildExamples)
        build-depends: reactive-banana, wx, wxcore, base
    else
        buildable: False
    hs-source-dirs: src
    main-is: Arithmetic.hs

OTHER TIPS

I think you can use:

executable someExec
  if (someFlag)
    buildable: True
  else
    buildable: False
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top