我有一个 CMake 项目,结构如下:
cmake_minimum_required(VERSION 3.11)
project(ReadGraph)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
SET(CMAKE_CXX_FLAGS "-std=c++20 -pthread -O3")
include_directories(include)
enable_testing()
file(GLOB TESTS "test/*.cpp" "test/*/*.cpp" "src/*.cpp" "src/*/*.cpp")
add_executable(Tests ${TESTS})
target_link_libraries(Tests gtest_main)
而这个 CMakeLists.txt.in 文件:
cmake_minimum_required(VERSION 3.11)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
我从GoogleTest说明中复制粘贴了大部分内容。
Gtests 的使用非常适合我。
我想我想在我的项目中使用FMT 库。
我尝试了一些方法(例如直接从 gtest 复制方法)将 FMT 包含到我的项目中,但失败了。
我希望 CMake 下载此库并将其嵌入到我的项目中,因此我可以按如下方式使用 FMT:
#include <fmt/core.h>
目前我收到以下错误消息:
fatal error: fmt/core.h: No such file or directory
10 | #include <fmt/core.h>
| ^~~~~~~~~~~~
compilation terminated.