Maik Klein
Maik Klein

Reputation: 16148

CMake workflow of adding a library which uses CMake

#include "somelib/some.h"

int main(){}

I have a 3rd party library that has a pretty messy structure but it uses CMake. How would I add that library to my project so that I could just use it as I have written above?

Do I have to manually build and move every file by myself or is there a shortcut?

something like

mkdir lib
mv path/somelib lib

and in my CMakeLists.txt I could just add something like

ADD_CMAKE_LIB(${CMAKE_BINARY_DIR}/lib/somelib)

And everything would magically work?

Upvotes: 2

Views: 105

Answers (1)

Sergei Nikulov
Sergei Nikulov

Reputation: 5135

You can use one of the following options:

  1. Build 3rd party lib out of your project, install it anywhere and write your own, for example, FindMessyLib.cmake within your project to search for specific header and libs
  2. Add <project root>/ext/yourmessylib under your source control and use add_subdirectory(ext/yourmessylib) in your top-level CMakeLists.txt project file
  3. Use ExternalProject_Add. Example can be found here.

Personally, I prefer second approach combined with git submodule. If git is not used - I'll vote for third.

Upvotes: 2

Related Questions