Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble building tests with Google Test, Clang, and libc++

I tried building Google Test with the following CMake configuration:

$ CMAKE_CXX_COMPILER="clang++" CMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -U__STRICT_ANSI__" cmake ../source

Building shows CMake picked the right compiler, but my compiler flags aren't passing through:

$ VERBOSE=1 make
...
/Users/jfreeman/local/bin/clang++    -I/Users/jfreeman/work/googletest/source/include -I/Users/jfreeman/work/googletest/source      -DGTEST_HAS_PTHREAD=1   -o CMakeFiles/gtest.dir/src/gtest-all.cc.o -c /Users/jfreeman/work/googletest/source/src/gtest-all.cc
...
/Users/jfreeman/local/bin/clang++    -I/Users/jfreeman/work/googletest/source/include -I/Users/jfreeman/work/googletest/source      -DGTEST_HAS_PTHREAD=1   -o CMakeFiles/gtest_main.dir/src/gtest_main.cc.o -c /Users/jfreeman/work/googletest/source/src/gtest_main.cc

The end goal is that I want my project, which builds with Clang and libc++, to have tests built with Google Test. That means I need Google Test built with libc++ as well.

like image 738
John Freeman Avatar asked Nov 02 '12 15:11

John Freeman


1 Answers

Using variables on the command line with CMake sometimes requires the -D (for Define) flag.

    $ cmake -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -U__STRICT_ANSI__"  ../source
like image 84
katyhuff Avatar answered Oct 24 '22 22:10

katyhuff