Tuesday, July 05, 2016

HOWTO - Build Google Test from Source

today jul 5 year 2016.  the latest release for gtest was 2013 Sep. version 1.7.0

either download gtest release as a zip file, or clone the git repo:

(edited: here comes linux section, followed by osx section below on 161113)

mkdir -p gtest/src && cd gtest/src
git clone https://github.com/google/googletest.git

# if prefer 1.7.0
git checkout -b 1.7.0 release-1.7.0
cd ..
mkdir build && cd build
cmake ../src

# on linux system wide setup
cp -rp ../src/include/gtest  /usr/include/
cp -p ./libgtest*.a /usr/lib/

Don't like copying?  Symbolic links work too.
(osx brew somehow recommends not system wide..)

A super simple example:

#include "gtest/gtest.h"
TEST(BareboneTest, SillyAssert)
{
    ASSERT_EQ(2,3);
}
int main(int argc, char* argv[]) {
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

# to build:
g++ test.cpp -lgtest -lpthread && ./a.out


* * *
161113 build on OSX

cd $MY_DEV_ROOT
git clone https://github.com/google/googletest.git
cd googletest
git checkout -b 1.8.0 release-1.8.0
mkdir build && cd build
cmake ../googletest
make
sudo cp -r ../googletest/include/* /usr/local/include/
sudo cp lib*.a /usr/local/lib





Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home