FetchContent

If you happen to want a way to auto-install the library for your users then there is CMake utility module to help you: FetchContent.

cmake_minimum_required(VERSION 3.11)

include(FetchContent)

Used layout

This example assumes that the code for getting the dependencies is located in a dependencies-ProjectName.cmake file which is included in the CMakeLists.txt file which creates the target.

CMakeLists.txt

In the main CMakeLists, we included our dependencies-ProjectName.cmake, either as a module, or directly as a file.

Other than that the only thing we need is to link against the library, like with the manual install method:

target_link_libraries(your-target
                         PRIVATE mikrotik::mikrotikapi)

Dependencies

Now this is where the magic happens: first we include the FetchContent module:

include(FetchContent)

Then we go and get the git URL for this library. Let me help: https://github.com/bodand/MikroTikApi.git. Now we just go and tell CMake to get this project for us:

FetchContent_Declare(
    MikroTikApi
    GIT_REPOSITORY https://github.com/bodand/MikroTikApi.git
    GIT_TAG v1.1.0 # or any version you desire
)

This tells CMake to where this library is found and which revision are we trying to use. After this we just need to get the library itself:

FetchContent_MakeAvailable(MikroTikApi)

And now you can safely use the library, as seen in above in the CMakeLists.txt.