cmake error at message(FATAL_ERROR "CMake step for ${contentName} failed: ${result}")

Natourand
Mon, 22 Jan 2024 13:24:18 +0000
Usage

hello,
I was trying to run cmake on Visual Studio code to use the gtest .
I have already downloaded the MinGW compiler on my Windows computer.
I also downloaded the relevant extensions in vs code such as cmake and cmake tools and the cmake, cmake GUI on my local computer.
i have this code and test files:
#include

int sum(int a, int b)
{
return a + b;
}

#include <gt est/gtest.h>

#include “../src/calc.cpp” // here we include the code to be tested

TEST(SumTest, BasicTest) {

EXPECT_EQ(sum(1,2), 1);

}

#include <gtest/gtest.h>
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

and this CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(“FooBarEX”) # Replace “MyCalc” with your repo name

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

set(gtest_force_shared_crt ON CACHE BOOL “” FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

set(SOURCE_FILES
src/calc.cpp # this is where the code we want to test
)

set(TEST_FILES
tests/test_main.cpp # this is the main for tests
tests/calc_test.cpp # this file contain the tests
)
add_executable(CalcTests ${TEST_FILES})

Link Google Test to the test executable

target_link_libraries(CalcTests PRIVATE gtest gtest_main)

Include the source directory for tests

target_include_directories(CalcTests PRIVATE src)
include(GoogleTest)
add_test(NAME CalcTests COMMAND CalcTests)

but everytime I am trying to run the test I get this errors:
[proc] Executing command: cmake --version
[proc] Executing command: cmake -E capabilities
[variant] Loaded new set of variants
[kit] Successfully loaded 7 kits from C:\Users\raand\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] Executing command: “C:\Program Files\CMake\bin\cmake.EXE” --version
[proc] Executing command: “C:\Program Files\CMake\bin\cmake.EXE” -E capabilities
[proc] Executing command: chcp
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[main] Configuring project: FooBarEX-2
[proc] Executing command: “C:\Program Files\CMake\bin\cmake.EXE” --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/raand/FooBarEX-2 -Bc:/Users/raand/FooBarEX-2/build -G “Visual Studio 17 2022” -T host=x86 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1331 (message):
[cmake] The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
[cmake] not set. The policy’s OLD behavior will be used. When using a URL
[cmake] download, the timestamps of extracted files should preferably be that of
[cmake] the time of extraction, otherwise code that depends on the extracted
[cmake] contents might not be rebuilt if the URL changes. The OLD behavior
[cmake] preserves the timestamps from the archive instead, but this is usually not
[cmake] what you want. Update your project to the NEW behavior or specify the
[cmake] DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
[cmake] robustness issue.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:8 (FetchContent_Declare)
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Error: The current CMakeCache.txt directory C:/Users/raand/FooBarEX-2/build/_deps/googletest-subbuild/CMakeCache.txt is different than the directory c:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/_deps/googletest-subbuild where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
[cmake]
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1667 (message):
[cmake] CMake step for googletest failed: 1
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1819:EVAL:2 (__FetchContent_directPopulate)
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1819 (cmake_language)
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:2033 (FetchContent_Populate)
[cmake] CMakeLists.txt:14 (FetchContent_MakeAvailable)
[cmake]
[cmake]
[cmake] – Configuring incomplete, errors occurred!
[proc] The command: “C:\Program Files\CMake\bin\cmake.EXE” --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/raand/FooBarEX-2 -Bc:/Users/raand/FooBarEX-2/build -G “Visual Studio 17 2022” -T host=x86 -A x64 exited with code: 1
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[main] Building folder: FooBarEX-2
[main] Configuring project: FooBarEX-2
[proc] Executing command: “C:\Program Files\CMake\bin\cmake.EXE” --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/raand/FooBarEX-2 -Bc:/Users/raand/FooBarEX-2/build -G “Visual Studio 17 2022” -T host=x86 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Warning (dev) at C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1331 (message):
[cmake] The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy CMP0135 is
[cmake] not set. The policy’s OLD behavior will be used. When using a URL
[cmake] download, the timestamps of extracted files should preferably be that of
[cmake] the time of extraction, otherwise code that depends on the extracted
[cmake] contents might not be rebuilt if the URL changes. The OLD behavior
[cmake] preserves the timestamps from the archive instead, but this is usually not
[cmake] what you want. Update your project to the NEW behavior or specify the
[cmake] DOWNLOAD_EXTRACT_TIMESTAMP option with a value of true to avoid this
[cmake] robustness issue.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:8 (FetchContent_Declare)
[cmake] This warning is for project developers. Use -Wno-dev to suppress it.
[cmake]
[cmake] CMake Error: The current CMakeCache.txt directory C:/Users/raand/FooBarEX-2/build/_deps/googletest-subbuild/CMakeCache.txt is different than the directory c:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/_deps/googletest-subbuild where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
[cmake]
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1667 (message):
[cmake] CMake step for googletest failed: 1
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1819:EVAL:2 (__FetchContent_directPopulate)
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1819 (cmake_language)
[cmake] C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:2033 (FetchContent_Populate)
[cmake] CMakeLists.txt:14 (FetchContent_MakeAvailable)
[cmake]
[cmake]
[cmake] – Configuring incomplete, errors occurred!
[proc] The command: “C:\Program Files\CMake\bin\cmake.EXE” --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/raand/FooBarEX-2 -Bc:/Users/raand/FooBarEX-2/build -G “Visual Studio 17 2022” -T host=x86 -A x64 exited with code: 1
[visual-studio] Patch Windows SDK path from C:\Program Files (x86)\Windows Kits\10\bin\x64 to C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64 for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat
[proc] Executing command: “C:\Program Files\CMake\bin\ctest.exe” -j10 -C Debug -T test --output-on-failure -R ^CalcTests$
[ctest] Cannot find file: C:/Users/raand/FooBarEX-2/build/DartConfiguration.tcl
[ctest] Site:
[ctest] Build name: (empty)
[ctest] Test project C:/Users/raand/FooBarEX-2/build
[ctest] Cannot find file: C:/Users/raand/FooBarEX-2/build/DartConfiguration.tcl
[ctest] Start 1: CalcTests
[ctest] Could not find executable C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe
[ctest] Looked in the following places:
[ctest] C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe
[ctest] C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe.exe
[ctest] C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/Debug/CalcTests.exe
[ctest] C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/Debug/CalcTests.exe.exe
[ctest] Debug/C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe
[ctest] Debug/C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe.exe
[ctest] 1/1 Test #1: CalcTests …***Not Run 0.00 sec
[ctest] Unable to find executable: C:/Users/97254/OneDrive/Desktop/Files/FooBarEX/build/Debug/CalcTests.exe
[ctest]
[ctest] 0% tests passed, 1 tests failed out of 1
[ctest]
[ctest] Total Test time (real) = 0.06 sec
[ctest]
[ctest] The following tests FAILED:
[ctest] 1 - CalcTests (Not Run)
[ctest] Errors while running CTest
[proc] The command: “C:\Program Files\CMake\bin\ctest.exe” -j10 -C Debug -T test --output-on-failure -R ^CalcTests$ exited with code: 8
[ctest] CTest finished with return code 8

and this one:
[{
“resource”: “/C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake”,
“owner”: “cmake-configure-diags”,
“severity”: 8,
“message”: “CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1667 (message):CMake step for googletest failed: 1”,
“source”: “CMake (message)”,
“startLineNumber”: 1667,
“startColumn”: 1,
“endLineNumber”: 1667,
“endColumn”: 10000,
“relatedInformation”: [
{
“startLineNumber”: 2,
“startColumn”: 1,
“endLineNumber”: 2,
“endColumn”: 1000,
“message”: “In call to ‘__FetchContent_directPopulate’ here”,
“resource”: “/C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake:1819:EVAL”
},
{
“startLineNumber”: 1819,
“startColumn”: 1,
“endLineNumber”: 1819,
“endColumn”: 1000,
“message”: “In call to ‘cmake_language’ here”,
“resource”: “/C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake”
},
{
“startLineNumber”: 2033,
“startColumn”: 1,
“endLineNumber”: 2033,
“endColumn”: 1000,
“message”: “In call to ‘FetchContent_Populate’ here”,
“resource”: “/C:/Program Files/CMake/share/cmake-3.28/Modules/FetchContent.cmake”
},
{
“startLineNumber”: 14,
“startColumn”: 1,
“endLineNumber”: 14,
“endColumn”: 1000,
“message”: “In call to ‘FetchContent_MakeAvailable’ here”,
“resource”: “/C:/Users/raand/FooBarEX-2/CMakeLists.txt”
}
]
}]

In call to ‘__FetchContent_directPopulate’ here
In call to ‘cmake_language’ here
In call to ‘FetchContent_Populate’ here
In call to ‘FetchContent_Populate’ here
In call to ‘FetchContent_MakeAvailable’ here

I don’t understand what seems to be the problem and how to fix it .

3 posts - 2 participants