Hello there,
I am attempting to integrate GoogleTest into my project's cmake build as a dependency.
Here is the relevant part of my cmake:
# ============================================================
# ============================================================
set(gtest_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/gtest")set(gtest_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/gtest")set(gtest_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${gtest_INSTALL_DIR} -DCMAKE_BUILD_TYPE=${dep_BUILD_TYPE})set(gtest_INCLUDES "${gtest_INSTALL_DIR}/include")set(gtest_LIBRARIES ${gtest_INSTALL_DIR}/lib/libgtest.a) SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/gtest-1.7.0 INSTALL_DIR ${gtest_INSTALL_DIR} CMAKE_ARGS ${gtest_CMAKE_ARGS}
This tries to "install" google test, but not in the system - it installs it in the build directory. The library name above (libgtest.a) is just my first guess at what it would be named.
However I am blocked because there "is no rule to make target install". I searched the internet and I found several replies to people with similar issues dismissing it as "not supported". Apparently, the google developers have the idea that "make install" means "install on the system", when it does *not* mean that at all, it means, "write the libs and headers somewhere for me so I can use them in something".
Why can't I use google test as a subproject of my project? Do you have a workaround?
I’m not sure if this answers your question but our relevant section in CMakeLists.txt is as follows:
add_subdirectory(3rdparty/gtest)
set(GTEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/gtest)
set(GTEST_INCLUDE_DIR ${GTEST_ROOT}/include)
set(GTEST_LIBRARIES gtest gtest_main)
# …
add_executable(test tests/test_fubar.cpp)
target_link_libraries(test ${GTEST_LIBRARIES})
Whereas our relevant directory structure looks like
.
├── 3rdparty
│ ├── gtest
│ │ ├── cmake
│ │ ├── …
│ │ ├── include
│ │ │ └── gtest
│ │ │ └── internal
│ │ └── …
│ └── …
├── sources
└── tests
GTest is build along with our sources. This way it is compiled with the very same compiler flags, optimization flags and so on as our own sources.
We have a subversion checkout directly in our git repository that is updated from time to time. So we have all GTest sources in our main repository. However, maybe you could even use something like git submodules for that.
Regards,
Ben