jberryman
jberryman

Reputation: 16635

Cabal compilation conditional on compiling with llvm or not

In a library I'm writing I need to use CPP to choose between two blocks of code depending on whether my user is compiling with LLVM or the native code gen. Is there a way to detect this in the .cabal file and do something like

library
  -- not real:
  if backend(llvm)
      CPP-Options:     -DUSING_LLVM

Or maybe it's even possible to detect arbitrary flags passed to GHC (instead of just -fllvm)?

Upvotes: 1

Views: 146

Answers (1)

jberryman
jberryman

Reputation: 16635

Ah, I forgot to check the GHC docs. GHC defines a macro __GLASGOW_HASKELL_LLVM__ which is defined when -fllvm was specified (and can be used to check llvm version as well):

https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/phases.html#options-affecting-the-c-pre-processor

Upvotes: 1

Related Questions