c++cmakefetchcontent

Cannot get FetchCotent_Populate to work for CLI11 getting message: No content details recorded for cli11


I am trying to use CLI11 in a project via CMake. However, I get thismessage: No content details recorded for cli11 (extensive output below). I have add CLI11 in my CMakeLists.txt file according to 'Using Fetchcontent' section in CLI11 Installation Chapter.

CMake Error at /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/FetchContent.cmake:1221 (message):
  No content details recorded for cli11
Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/FetchContent.cmake:1740 (__FetchContent_getSavedDetails)
  /opt/homebrew/Cellar/cmake/3.28.1/share/cmake/Modules/FetchContent.cmake:2033 (FetchContent_Populate)
  CMakeLists.txt:18 (FetchContent_MakeAvailable)

The bare minimum to reproduce the issue. First the CMakeLists.txt

cmake_minimum_required(VERSION 3.28)

project(app VERSION 0.0.0 DESCRIPTION "app" LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
SET(CMAKE_CXX_FLAGS "-Wall -Wextra -O3")

include(FetchContent)

FetchContent_Populate(
    cli11_proj
    QUIET
    GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
    GIT_TAG v2.3.2
    SOURCE_DIR     cli11_proj
  )
FetchContent_MakeAvailable(cli11)  




add_subdirectory(${cli11_proj_SOURCE_DIR} ${cli11_proj_SOURCE_DIR}/build)

add_executable(app ../src/app/app.cpp)
target_include_directories(app PRIVATE include CLI11::CLI11)

Then the app.cpp file located in a folder ./src/app


#include <string>
#include <CLI/CLI.hpp>

int main(int argc, char** argv) {
    CLI::App app{"App description"};
    argv = app.ensure_utf8(argv);

    std::string filename = "default";
    app.add_option("-f,--file", filename, "A help string");

    CLI11_PARSE(app, argc, argv);
    return 0;
}


Solution

  • There are some other problems with your code, in addition to Corristo's answer. Here's a sum-up:

    1. Use FetchContent_Declare and FetchContent_MakeAvailable instead of FetchContent_Populate.
    2. The first argument for both functions is <name> and must be identical.
    3. Do not use add_subdirectory, this is done automatically by FetchContent_MakeAvailable after the repository has been cloned.
    4. You may ommit SOURCE_DIR, there is no need for it. Let CMake handle the directory layout.
    5. Do not use target_include_directories. You want to link against CLI11::CLI11, so you have to use target_link_libraries. The include path is added automatically to your target.
    6. The function ensure_utf8 is only available in main (according to GitHub). You may change GIT_TAG to main or stop using it.

    This is how the final CMakeLists.txt should look like:

    cmake_minimum_required(VERSION 3.28)
    
    project(app VERSION 0.0.0 DESCRIPTION "app" LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED True)
    SET(CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
    
    include(FetchContent)
    
    FetchContent_Declare(
        cli11
        QUIET
        GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
        GIT_TAG v2.3.2
    )
    
    FetchContent_MakeAvailable(cli11)  
    
    add_executable(app ../src/app/app.cpp)
    target_include_directories(app PRIVATE include)
    target_link_libraries(app PRIVATE CLI11::CLI11)