Closed lezcano closed 8 years ago
This looks actually like a bug in the gmock.cmake
script of Manu343726/cmake module. Look at the implementation of gmock_gtest_target()
function:
function(gmock_test_target)
...
if(NOT ET_TARGET_OUT)
exec_target(${ARGN} PREFIX test TARGET_OUT __exec_target)
else()
exec_target(${ARGN} PREFIX test)
set(__exec_target ${${ET_TARGET_OUT}})
endif()
...
add_test(NAME ${ET_NAME} COMMAND ${__exec_target})
endfunction()
I'm declaring the test as a call to the test executable. It was written this way since GTest embeds the test driver (GTest framework) in the executable itself, so you just have to launch it.
The issue is that I forgot to add a dependency between the test target (${ET_NAME}
variable) and the executable target, so the latter is built when the former is invoked. Your problem was you were trying to run the tests when the test executables are not built yet.
The solution should be as simple as adding that dependency explicitly through a call to add_dependencies()
.
Of course the workaround is as simple as invoking make
before running the tests. Which is what I usually do and the reason why I didn't catch this....
We no longer manage gmock in that way, instead the imported target is wrapped in a gmock
target, so just linking against that gmock
target triggers the external project build. Like:
add_executable(MyUnitTest myunittest.cpp)
target_link_libraries(MyUnitTest PRIVATE gmock)
That's all. This triggers the external project download/configure/build and then the generated gmock library is linked against your target.
After trying to compile the project as we did today in class, using the same commands, I was not able to build the "test" objective.
The commands I run were:
That last
make test
threw: