Я пытаюсь добавить gtest в существующий проект UWP, который строит CMake.
Процесс сборки выглядит нормально, и я могу создать и собрать проект, используя:
cmake ../ -G "Visual Studio 15 2017 Win64" -T v141 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0.14393.0 -Dgtest_disable_pthreads=ON -DCMAKE_USE_WIN32_THREADS_INIT=ON
Однако, когда я запускаю тест, я получаю:
E:\Test-Gtest\build>ctest -C Debug
Test project E:/Test-Gtest/build
Start 1: example_test
1/1 Test #1: example_test .....................Exit code 0xc0000135
***Exception: 0.03 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.05 sec
The following tests FAILED:
1 - example_test (Exit code 0xc0000135
)
Errors while running CTest
Попытка запустить исполняемый файл example.exe приводит к:
VCRUNTIME140D_APP.dll was not found
с последующим
MSVCP140D_APP.dll was not found
Это ссылка на MCVE на github для удобства, которая имеет следующую структуру (в основном на основе рекомендаций в документах ):
│ CMakeLists.txt
│
└───src-test
│ CMakeLists.txt
│ CMakeLists.txt.in
│
└───src-integration
basic_logon.cpp
main CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(TestGtest CXX C)
set (CMAKE_CXX_STANDARD 14)
enable_testing()
add_subdirectory(src-test)
src-test CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
# 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()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# 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)
# Now simply link against gtest or gtest_main as needed. Eg
message(STATUS "CMAKE_CURRENT_LIST_DIR: ${CMAKE_CURRENT_LIST_DIR}")
file(GLOB SRC_TEST_INTEGRATION_FILES ${CMAKE_CURRENT_LIST_DIR}/src-integration/*.cpp)
add_executable(example ${SRC_TEST_INTEGRATION_FILES})
target_link_libraries(example gtest_main)
add_test(NAME example_test COMMAND example)
CMakeLists.txt.in
cmake_minimum_required(VERSION 3.12)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
basic_logon.cpp
#include "gtest/gtest.h"
#include <cmath>
TEST(Pow, Two)
{
EXPECT_EQ(4, std::pow(2,2));
}