I have a main project with a subproject tests. In project/CMakeLists.txt I added
add_subdirectory(tests)
In project/tests/CMakeLists.txt I plug in "pre-compiled" gtest library (from Ubuntu repository). I cd to /usr/src/gtest and compile two *.a files into system lib directory. And it works fine, until issue scribed in google test FAQ appeared.
How to build gtest static library files from project/tests/CMakeLists.txt and how to use this new *.a files instead of system ones?
Finaly I find out how to rebuild static libgtest.a without adding googletest as a subproject.
Using info from this link and from the bottom of this link.
Interesting part of my project/tests/CMakeLists.txt:
.....
# Locate GTest
#find_package(GTest REQUIRED)
#include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
set(GTEST_SRC /usr/src/gtest/src/gtest-all.cc)
include_directories(SYSTEM /usr/src/gtest # <-- path to non-header files from gtest-all.cc
/usr/include) # <-- path to gtest headers
add_library(gtest STATIC ${GTEST_SRC}) # <-- make static library target before main project executable
target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT})
# Link runTests with what we want to test and the GTest and pthread library
add_executable(tests ${SRC})
target_link_libraries(tests ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} gtest) # <-- finaly link this library as others
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With