c++cmakerange-v3

How to install the C++20 range library from github


I would like to use the range-v3 library in my project, but i don't understand how. The installation description says the following:

This library is header-only. You can get the source code from the range-v3 repository on github. To compile with Range-v3, just #include the individual headers you want.

Does that mean I can copy and paste the needed header files and add the filepath to my CMake file? I am a bit confused, because I never included third party library.


Solution

  • Note: please see hythis' answer for a better solution.


    Does that mean I can copy and paste the needed header files and add the filepath to my CMake file?

    Basically, yes. First git clone to <path_to_range_v3>. Then include these lines into CMakeLists.txt:

    add_library(range_v3 INTERFACE IMPORTED)
    set_target_properties(range_v3 PROPERTIES 
        INTERFACE_INCLUDE_DIRECTORIES <path_to_range_v3>/include)
    
    target_link_libraries(your_target PUBLIC range_v3)