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;
}
There are some other problems with your code, in addition to Corristo's answer. Here's a sum-up:
FetchContent_DeclareandFetchContent_MakeAvailableinstead ofFetchContent_Populate.<name>and must be identical.add_subdirectory, this is done automatically byFetchContent_MakeAvailableafter the repository has been cloned.SOURCE_DIR, there is no need for it. Let CMake handle the directory layout.target_include_directories. You want to link againstCLI11::CLI11, so you have to usetarget_link_libraries. The include path is added automatically to your target.ensure_utf8is only available inmain(according to GitHub). You may changeGIT_TAGtomainor stop using it.This is how the final CMakeLists.txt should look like: