2

I'm working on a C++ project (I am using CMake) and need to depend on a C library like this one (but uses make): https://github.com/RoaringBitmap/CRoaring

What's the cleanest way for me to integrate that library into my project?

One option is importing that code into my source tree, creating a CMakeLists.txt for that external dependency and using it as a CMake submodule. But I don't want to do that, since that project might evolve, and I just want that code as a git submodule dependency, and not actually committed into my repository.

jeffreyveon
  • 13,400
  • 18
  • 79
  • 129
  • 3
    Possible duplicate of [Compile other external libraries (without CMakeLists.txt) with CMake](http://stackoverflow.com/questions/3489056/compile-other-external-libraries-without-cmakelists-txt-with-cmake) – Tsyvarev Jan 23 '16 at 14:37
  • Also duplicates [Building a library using autotools from cmake](https://stackoverflow.com/questions/5971921/building-a-library-using-autotools-from-cmake) – Alexander Voitenko Apr 19 '21 at 20:47

1 Answers1

1

What you could do is use the build system of make within CMake if you cd into the sources of CRoaring and call external commands within CMakeLists.txt using the execute_process command:

execute_process

With INSTALL_PREFIX you can indicate where to compile that library and cmake would use it then.

This also would mean, that the make compilation starts whenever you trigger configure though I imagine that you could control that a bit. If you want to avoid that add_custom_command could help you on this:

add_custom_command

For Commander Genius we have been using those when building the Windows version and using icotool so the executable gets an application icon embedded into the exe.

Another alternative would be using ExternalProject like indicated in the similar post by Tsyvarev:

ExternalProject

Yet I'm not sure if that call is flexible enough for your needs. It has a lot of options though.

So the cleanest way to use CMake really depends on what you need to do for your project.

sat63k
  • 333
  • 1
  • 2
  • 13
Gerhard Stein
  • 1,543
  • 13
  • 25