Including external header library from github using cmake

Viewed 3829

There is an GitHub repository that contains only hpp files with no CMakeList.txt file.

I need to include those header files in my project. I do not want to manually clone them then linking against them. I want that each time I call cmake command, cmake will clone them and put them in some inner folder.

Is it possible? if yes, how can I achive this?

3 Answers

another option I've spotted at json cpp repo:

FetchContent_Declare(json
    GIT_REPOSITORY https://github.com/nlohmann/json.git
    GIT_TAG v3.7.3)

FetchContent_GetProperties(json)
if(NOT json_POPULATED)
    FetchContent_Populate(json)
    add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

IMHO looks even better

Related