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.
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 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.