I'm trying to integrate Google Test into my Qt project. I have basic (EXPECT_EQ(1, 1))
tests running with Google Test, but am confused how I can integrate my Qt project (which uses qmake
) into the test's CMake build.
Google Test is currently added using the recommended CMakeLists.txt
from their README. I would like to add my local src and build to the test build. My src is located (relative to the test folder) ../src/
and I've built the src into (relative to the test folder) build/project-build/
but I believe it won't integrate because the project has .pro
's. The error when I try to integrate it as a subdirectory:
CMake Error at CMakeLists.txt:31 (add_subdirectory):
The source directory
/home/project/src
does not contain a CMakeLists.txt file.
This is how I am adding it as a subdirectory and project to my CMakeLists.txt
:
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/../../src
${CMAKE_CURRENT_BINARY_DIR}/project-build
EXCLUDE_FROM_ALL)
In a separate CMakeLists.txt.in
(similar to how google test does it):
include(ExternalProject)
ExternalProject_Add(project
GIT_REPOSITORY "${CMAKE_CURRENT_BINARY_DIR}/../.."
GIT_TAG master
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/../../src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/project-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Also, please let me know if this is a difficult way to test a project. I was hoping to use google test, but if this doesn't work will probably use Qt Test. I am fairly new to C++ and new to C++ unit testing (am familiar with Java and JUnit). Would appreciate any help, thank you!