Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly setup googleTest on OS X aside from XCode

How do I setup gTest, so that I can link aganist the library? I will code in vim, so I just want to install the libraries, unlike the XCode setup. Goal is to be able to link a project against the library by setting -lgtest as linker flag and optionally, if I did not write my own test mainroutine, the explicit -lgtest_main flag.

like image 364
ManuelSchneid3r Avatar asked Dec 23 '13 15:12

ManuelSchneid3r


People also ask

How does Google test work?

Independent and Repeatable: Googletest isolates the tests by running each of them on a different object. Portable and Reusable: Googletest works on different Oses (Linux, Windows, or a Mac), with different compilers. When tests fail, it should provide as much information about the problem as possible.


1 Answers

I think cmake is an easy way to setup and use gtest on OSX. It works without manually copying files. Unzip gooletest-release-1.8.0, then

cd googletest-release-1.8.0

# create a build directory
mkdir build      
cd build

# build configuration
cmake .. -DBUILD_GTEST=ON -DBUILD_SHARED_LIBS=ON

# build it 
make   

# installation
sudo make install

Afterwards, you can easily incorporate gtest in your project with the cmake commands

# sets GTEST_INCLUDE_DIRS and GTEST_LIBRARIES
find_package( GTest REQUIRED )      

# adds the gtest include directory
include_directories( ${GTEST_INCLUDE_DIRS} )

# links gtest
target_link_libraries( yourTestApp ${GTEST_LIBRARIES} )
like image 63
Adrian Schneider Avatar answered Sep 19 '22 10:09

Adrian Schneider