I have a CMake project, with following structure:
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)
And this CMakeLists.txt.in file:
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 ""
)
Most of this I copy-pasted from GoogleTest instructions.
Usage of Gtests works perfectly for me.
I figured that I want to use FMT Library in my project.
I tried some approaches (such as direct copy of approach from gtest) to include FMT into my project, but failed.
I want CMake to download this library and embed it into my project, so I can use FMT as follow:
#include <fmt/core.h>
Currently I am receiving following error massage:
fatal error: fmt/core.h: No such file or directory
10 | #include <fmt/core.h>
| ^~~~~~~~~~~~
compilation terminated.