linux - CMake 错误“包含找不到加载文件:FetchContent”
问题描述
cmake
在 Ubuntu 上执行命令时出现以下错误。CMake 版本 - 3.10.2。
mapp@ubuntu:~/Desktop/LocatePro$ cmake .
-- Enable testing: ON
CMake Error at CMakeLists.txt:40 (include):
include could not find load file:
FetchContent
CMake Error at CMakeLists.txt:42 (FetchContent_Declare):
Unknown CMake command "FetchContent_Declare".
-- Configuring incomplete, errors occurred!
See also "/home/mapp/Desktop/LocatePro/CMakeFiles/CMakeOutput.log".
mapp@ubuntu:~/Desktop/LocatePro$
以下是第CMakeLists.txt
1 行的内容。31:
# we will use the network to fetch Google Test sources
# make it possible to disable unit tests when not on network
option(ENABLE_UNIT_TESTS "Enable unit tests" ON)
message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}")
if(ENABLE_UNIT_TESTS)
# the following code to fetch googletest
# is inspired by and adapted after:
# - https://cmake.org/cmake/help/v3.11/module/FetchContent.html
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0
)
FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
# Prevent GoogleTest from overriding our compiler/linker options
# when building with Visual Studio
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Prevent GoogleTest from using PThreads
set(gtest_disable_pthreads ON CACHE BOOL "" FORCE)
# adds the targers: gtest, gtest_main, gmock, gmock_main
add_subdirectory(
${googletest_SOURCE_DIR}
${googletest_BINARY_DIR}
)
# Silence std::tr1 warning on MSVC
if(MSVC)
foreach(_tgt gtest gtest_main gmock gmock_main)
target_compile_definitions(${_tgt}
PRIVATE
"_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING"
)
endforeach()
endif()
endif()
add_executable(LocatPro_Test "")
target_sources(LocatPro_Test
PRIVATE
LocatProTest/LocatProTest.cpp
)
target_link_libraries(LocatPro_Test
PRIVATE
gtest_main
)
enable_testing()
add_test(
NAME google_test
COMMAND $<TARGET_FILE:LocatPro_Test>
)
endif()
我是新手,今天才开始使用 CMake。如果我在 CMake 中做错了什么和/或遗漏了什么,请告诉我。
include(FetchContent)
在 Ubuntu 上支持 CMAke 版本 - 3.10.2。
解决方案
模块FetchContent仅出现在 CMake 3.11 中。
(您可以尝试在上面的链接中选择 previos CMake 版本,并发现该版本中没有该模块)。
推荐阅读
- windows-terminal - Windows终端ubuntu如何更改起始目录
- node.js - 如何使用 Express 3.x 从较低目录提供文件?
- javascript - 当图像元素阻止它时,事件侦听器不起作用
- python - matplotlib + 乳胶 + 自定义 ttf 字体
- go - 如何在 Go 中按名称设置结构字段的复合字段?
- javascript - 查看为项目(节点 js)启用了哪些 GCP 服务?
- sql - 我有以下 XML,我需要将其存储在 sql 表中
- firefox - 如何在 Firefox 调试器中调试嵌入在 HTML 响应中的 JavaScript
- android - Android:在后台暂停应用程序并在前台恢复
- reactjs - 动画未触发重新渲染