Is it possible to use cmake for Haskell projects?

后端 未结 4 2203
失恋的感觉
失恋的感觉 2021-02-13 17:11

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 b

相关标签:
4条回答
  • 2021-02-13 17:36

    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.

    0 讨论(0)
  • 2021-02-13 17:36

    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!

    0 讨论(0)
  • 2021-02-13 17:39

    I've rewritten @arrowdodger's initial work, in the process fixing a couple bugs that were present:

    • Could not be used from an in-project cmake/ directory because of hardcoded paths
    • There were some occurrences of Fortran/CXX variables (which caused buggy behaviour)
    • Lots of code that was irrelevant to Haskell could be removed, other code added based on newer versions of the C/CXX language files that ship with CMake

    The repository can be found at:

    https://github.com/kvanberendonck/cmake-haskell

    Working beautifully for me, and the build speed I can get out of ninja is extremely impressive.

    0 讨论(0)
  • 2021-02-13 17:56

    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.

    0 讨论(0)
提交回复
热议问题