我试图通过CMake在一个项目中使用CLI11。然而,我得到了这个消息:No content details recorded for cli11
(下面的大量输出)。我已经根据CLI11 Installation Chapter中的“使用Fetchcontent”部分在我的CMakeLists.txt文件中添加了CLI11。
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)
字符串
最低限度的重现问题。首先,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)
型
然后将位于文件夹./src/app
中的app.cpp
文件
#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;
}
型
1条答案
按热度按时间ui7jx7zq1#
除了Corristo的回答之外,你的代码还存在一些其他问题。这里是一个总结:
1.使用
FetchContent_Declare
和FetchContent_MakeAvailable
代替FetchContent_Populate
。1.两个函数的第一个参数都是
<name>
,并且必须相同。1.不要使用
add_subdirectory
,这是在存储库被克隆后由FetchContent_MakeAvailable
自动完成的。1.你可以省略
SOURCE_DIR
,这是没有必要的。让CMake来处理目录布局。1.不要使用
target_include_directories
。你想链接到CLI11::CLI11
,所以你必须使用target_link_libraries
。包含路径会自动添加到你的目标。1.函数
ensure_utf8
仅在main
中可用(根据GitHub)。您可以将GIT_TAG
更改为main
或停止使用它。这就是最终的CMakeLists.txt应该是这样的:
字符串