Fwd: [googletest] Using GoogleTest as an external project in cmake

1,003 views
Skip to first unread message

Benjamin Kircher

unread,
Feb 19, 2014, 4:04:35 PM2/19/14
to googletes...@googlegroups.com


Begin forwarded message:

From: Benjamin Kircher <benjamin...@gmail.com>
Subject: Re: [googletest] Using GoogleTest as an external project in cmake
Date: 19 Feb 2014 21:55:09 GMT+1
To: doug65536 <doug...@gmail.com>

Hello there, 


On 14 Feb 2014, at 14:28, doug65536 <doug...@gmail.com> wrote:

I am attempting to integrate GoogleTest into my project's cmake build as a dependency.

Here is the relevant part of my cmake:

# ============================================================
# GoogleTest dependency
# ============================================================

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)
ExternalProject_Add(
	gtest
	SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/gtest-1.7.0
	PREFIX ${gtest_PREFIX}
	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


Forgot to include the list. Sorry.

signature.asc

Billy Donahue

unread,
Feb 19, 2014, 9:09:38 PM2/19/14
to Benjamin Kircher, Google C++ Testing Framework
I don't understand this distinction. "somewhere" is "on the system". Can you clarify?
Reply all
Reply to author
Forward
0 new messages