Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use cmake for Haskell projects?

I am planning a project written in Haskell, maybe there are some parts in C as well. For the buildsystem I decided against the common choice for Haskell programs cabal, mainly because I want to learn how building programs in other languages works.

I heard about CMake and I think it is a pretty cool product. Although I have no knowledge in how to use it, I want to use CMake for that project, just to find out how it works. Googleing did not reveal any facts about how to use cmake with haskell, and all tutorials I read were rather confusing. Is it possible, and if yes, how is it possible, to compile a project written in Haskell using CMake?

like image 445
fuz Avatar asked May 11 '11 19:05

fuz


3 Answers

You can certainly use CMake to build Haskell applications and libraries. To do so, you will need to duplicate much of what Cabal does, which will be instructive, but also time consuming.

I'd recommend using cabal build -v to see the commands emitted by Cabal, and then transcribing them into CMake form.

Or, use CMake to call cabal on the Haskell code -- that's likely to be less annoying.

like image 62
Don Stewart Avatar answered Oct 15 '22 10:10

Don Stewart


I've written simple cmake wrapper for cabal packages and put it here:

http://bitbucket.org/arrowd/cmake-findcabal (use "get source" button to download it).

For now it's working for me on Windows and FreeBSD, but i still plan to improve it later. I've put this into answer here so people can find it in google, as did i.

like image 35
arrowd Avatar answered Oct 15 '22 10:10

arrowd


While you certainly can build Haskell code directly by using a general purpose build tool, the result is much more difficult to maintain, much more difficult to share with the community and harder to build on top of than when you build on top of Cabal.

For the buildsystem I decided against the common choice for Haskell programs cabal, mainly because I want to learn how building programs in other languages works.

I understand the intention behind this statement in that you want to see all of the individual steps of the build process, but read another way, by avoiding cabal, you aren't seeing how programs in Haskell are built, you are seeing how painful it is to rebuild the tools provided by the community.

I would recommend doing what Don proposed. Look at the output of cabal -v for building under your particular compiler (probably ghc) and replicating those steps in CMake.

But then, once you understand the steps, I'd seriously consider taking that knowledge and moving back to Cabal. If only to let it deal with the issues of supporting multiple compilers, platforms, package management, etc. Thereby reducing the fragility of your build system, and making it easier to package up and share your work.

To wit, I can't think of a single non-Cabal-built package or binary in active use by the community other than ghc itself.

I do, however, wish you luck on your journey into the bowels of the build process!

like image 42
Edward Kmett Avatar answered Oct 15 '22 10:10

Edward Kmett