How to properly setup googleTest on OS X aside from XCode

Viewed 11885

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.

3 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} )
Related