I’m new to both cmake and visual studio code although I’ve been a software engineer for a decade. I’ve just never had to use these tools. Following the documentation from microsoft I setup vcpkg as my package manager.
I’ve setup my CMakeList.txt like so. I have 2 executables. One for the main project and one for the running tests (RunTests.exe)
cmake_minimum_required(VERSION 3.10)
project(Geodesic-RayTracer)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_executable(Geodesic-RayTracer Source/Main.cpp)
# gtest stuff TODO make this a add_subdirectory with its own cmakelist
find_package(gtest CONFIG REQUIRED)
include(CTest)
include(GoogleTest)
add_executable(Runtests Source/Tests/Runtests.cpp)
target_link_libraries(Runtests PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # For Windows: Prevent overriding the parent project's compiler/linker settings
#TODO see if I can make this automatically pick up .cpp files
target_sources(Runtests PRIVATE Source/Tests/ExampleTest.cpp)
gtest_discover_tests(Runtests)
However CTest doesn’t seem to pick up any tests. In the Testing window in visual studio code 1.89.1 with the CMake plugin I see my project name but no tests under it. When I click run I get the following output. I’ve redacted some personal information with asterisks
[main] Building folder: Geodesic-RayCaster
[build] Starting build
[proc] Executing command: "C:Program FilesCMakebincmake.EXE" --build C:/Users/***/Desktop/Geodesic-RayCaster/build --parallel 18
[build] ninja: no work to do.
[driver] Build completed: 00:00:00.062
[build] Build finished with exit code 0
[proc] Executing command: "C:Program FilesCMakebinctest.exe" -T test --output-on-failure -R ^c:/users/***/desktop/geodesic-raycaster$
[cpptools] The build configurations generated do not contain the active build configuration. Using "Debug" for CMAKE_BUILD_TYPE instead of "null" to ensure that IntelliSense configurations can be found
[ctest] Site: ****
[ctest] Build name: Win32-ninja
[ctest] Test project C:/Users/****/Desktop/Geodesic-RayCaster/build
[ctest] No tests were found!!!
[ctest] CTest finished with return code 0
[ctest] [object Object]