0

I have a small c++ project that I converted to cmake (from visual studio's native solutions), as this now appears to be industry standard.

However, there are appear to be some negative side effects: The boost tests are no longer discovered by visual studio's test explorer.

The projct is visible here: https://github.com/dickreuter/neuron_poker/tree/master/tools/montecarlo_cpp

It contains Test.cpp which contains some tests that should be discovered.

the cmake file looks as below. Could this be the issue or what could be the cause of the problem?

cmake_minimum_required(VERSION 3.15)
project(montecarlo_cpp)


set(CMAKE_CXX_STANDARD 14)

include_directories("C:/Users/dickr/Anaconda3/include" "C:/Users/dickr/git/vcpkg/installed/x64-windows/include" )
link_directories("C:/Users/dickr/Anaconda3/libs")

add_executable(montecarlo_cpp
        Montecarlo.cpp
        Montecarlo.h
        Test.cpp)

TARGET_LINK_LIBRARIES( montecarlo_cpp LINK_PUBLIC ${Boost_LIBRARIES} )
Nickpick
  • 6,163
  • 16
  • 65
  • 116
  • You are not calling the `find_package(Boost ...)` command, which would define the variable `Boost_LIBRARIES`. Thus, this variable is likely empty. I suggest checking out some of the example in the documentation [here](https://cmake.org/cmake/help/latest/module/FindBoost.html). – Kevin Dec 09 '19 at 23:15
  • Did you figure out what was the problem? Im having a similar issue. – Gert Kommer Apr 14 '20 at 13:20
  • no, still waiting for a solution. In the meantime I'm using clion.. – Nickpick Apr 14 '20 at 13:21

1 Answers1

1

Need to correctly configure tests discovering in the CMake file and tests will be shown in the Visual Studio Tests Explorer. Please follow instructions from Boost official page Boost Tests Frequently Asked Questions. I've modified your "CMakeLists.txt":

cmake_minimum_required(VERSION 3.15)
project(montecarlo_cpp)


set(CMAKE_CXX_STANDARD 14)

find_package(Boost REQUIRED COMPONENTS unit_test_framework) 

add_executable(${PROJECT_NAME}
        Montecarlo.cpp
        Montecarlo.h
        Test.cpp)

TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE Boost::unit_test_framework ${PYTHON_LIBRARY})

enable_testing()
add_test(NAME montecarlo_tests COMMAND ${PROJECT_NAME})

And tests has been successfully discovered by Visual Studio 2022 Tests Explorer: enter image description here

Please also make sure that you are installed Test Adapter for Boost.Test, it is available since Visual Studio 2017 and can be installed via the Visual Studio Installer / Individual components.

Pavel K.
  • 983
  • 9
  • 21