Skip to content

Commit

Permalink
Upgrade to C++14 when using system-intalled googletest 1.13.0
Browse files Browse the repository at this point in the history
googletest 1.13.0 requires C++14 at least, otherwise you get build errors like these.

please note, that this is a source directory with some patches applied from Arch Linux
to use the system-installed googletest library.


cd /tmp/snappy-1.1.10

cp -v ../snappy.pc.in .
'../snappy.pc.in' -> './snappy.pc.in'

patch -p1 < ../cmake_add_pkgconfig.patch 
patching file CMakeLists.txt
Hunk google#1 succeeded at 209 (offset 22 lines).
Hunk google#2 succeeded at 423 (offset 22 lines).

patch -p1 < ../system_gtest.patch 
patching file CMakeLists.txt
Hunk google#2 succeeded at 320 (offset 28 lines).
Hunk google#3 succeeded at 369 (offset 28 lines).

patch -p1 < ../reenable_rtti.patch 
patching file CMakeLists.txt

mkdir build-demo
cd build-demo

CXXFLAGS+=" -DNDEBUG" \
cmake   -DCMAKE_INSTALL_PREFIX=/usr 
        -DCMAKE_INSTALL_LIBDIR=/usr/lib
        -DBUILD_SHARED_LIBS=no
        -DSNAPPY_USE_BUNDLED_GTEST=OFF
        -DSNAPPY_USE_BUNDLED_BENCHMARK_LIB=OFF

-- The C compiler identification is GNU 13.1.0
-- The CXX compiler identification is GNU 13.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for sys/resource.h
-- Looking for sys/resource.h - found
-- Looking for sys/time.h
-- Looking for sys/time.h - found
-- Looking for sys/uio.h
-- Looking for sys/uio.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for windows.h
-- Looking for windows.h - not found
-- Looking for zlibVersion in z
-- Looking for zlibVersion in z - found
-- Looking for lzo1x_1_15_compress in lzo2
-- Looking for lzo1x_1_15_compress in lzo2 - found
-- Looking for LZ4_compress_default in lz4
-- Looking for LZ4_compress_default in lz4 - found
-- Performing Test HAVE_VISUAL_STUDIO_ARCH_AVX
-- Performing Test HAVE_VISUAL_STUDIO_ARCH_AVX - Failed
-- Performing Test HAVE_VISUAL_STUDIO_ARCH_AVX2
-- Performing Test HAVE_VISUAL_STUDIO_ARCH_AVX2 - Failed
-- Performing Test HAVE_CLANG_MAVX
-- Performing Test HAVE_CLANG_MAVX - Success
-- Performing Test HAVE_CLANG_MBMI2
-- Performing Test HAVE_CLANG_MBMI2 - Success
-- Performing Test SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS
-- Performing Test SNAPPY_HAVE_NO_MISSING_FIELD_INITIALIZERS - Success
-- Performing Test HAVE_BUILTIN_EXPECT
-- Performing Test HAVE_BUILTIN_EXPECT - Success
-- Performing Test HAVE_BUILTIN_CTZ
-- Performing Test HAVE_BUILTIN_CTZ - Success
-- Performing Test HAVE_ATTRIBUTE_ALWAYS_INLINE
-- Performing Test HAVE_ATTRIBUTE_ALWAYS_INLINE - Failed
-- Performing Test SNAPPY_HAVE_SSSE3
-- Performing Test SNAPPY_HAVE_SSSE3 - Failed
-- Performing Test SNAPPY_HAVE_X86_CRC32
-- Performing Test SNAPPY_HAVE_X86_CRC32 - Failed
-- Performing Test SNAPPY_HAVE_NEON_CRC32
-- Performing Test SNAPPY_HAVE_NEON_CRC32 - Failed
-- Performing Test SNAPPY_HAVE_BMI2
-- Performing Test SNAPPY_HAVE_BMI2 - Failed
-- Performing Test SNAPPY_HAVE_NEON
-- Performing Test SNAPPY_HAVE_NEON - Failed
-- Looking for mmap
-- Looking for mmap - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.9.5") 
-- Checking for one of the modules 'gtest_main'
-- Checking for one of the modules 'benchmark'
-- Configuring done (5.7s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/snappy-1.1.10/build-demo

make -w -j 1 VERBOSE=1

make: Entering directory '/tmp/snappy-1.1.10/build-demo'
/usr/bin/cmake -S/tmp/snappy-1.1.10 -B/tmp/snappy-1.1.10/build-demo --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /tmp/snappy-1.1.10/build-demo/CMakeFiles /tmp/snappy-1.1.10/build-demo//CMakeFiles/progress.marks
make  -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/tmp/snappy-1.1.10/build-demo'
make  -f CMakeFiles/snappy.dir/build.make CMakeFiles/snappy.dir/depend
make[2]: Entering directory '/tmp/snappy-1.1.10/build-demo'
cd /tmp/snappy-1.1.10/build-demo && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /tmp/snappy-1.1.10 /tmp/snappy-1.1.10 /tmp/snappy-1.1.10/build-demo /tmp/snappy-1.1.10/build-demo /tmp/snappy-1.1.10/build-demo/CMakeFiles/snappy.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/tmp/snappy-1.1.10/build-demo'
make  -f CMakeFiles/snappy.dir/build.make CMakeFiles/snappy.dir/build
make[2]: Entering directory '/tmp/snappy-1.1.10/build-demo'
[  7%] Building CXX object CMakeFiles/snappy.dir/snappy-c.cc.o
/usr/bin/g++ -DHAVE_CONFIG_H -I/tmp/snappy-1.1.10/build-demo -I/tmp/snappy-1.1.10 -fPIC -fstack-protector-strong -DNDEBUG -Wall -Wextra -fno-exceptions -std=c++11 -MD -MT CMakeFiles/snappy.dir/snappy-c.cc.o -MF CMakeFiles/snappy.dir/snappy-c.cc.o.d -o CMakeFiles/snappy.dir/snappy-c.cc.o -c /tmp/snappy-1.1.10/snappy-c.cc
[ 14%] Building CXX object CMakeFiles/snappy.dir/snappy-sinksource.cc.o
/usr/bin/g++ -DHAVE_CONFIG_H -I/tmp/snappy-1.1.10/build-demo -I/tmp/snappy-1.1.10 -fPIC -fstack-protector-strong -DNDEBUG -Wall -Wextra -fno-exceptions -std=c++11 -MD -MT CMakeFiles/snappy.dir/snappy-sinksource.cc.o -MF CMakeFiles/snappy.dir/snappy-sinksource.cc.o.d -o CMakeFiles/snappy.dir/snappy-sinksource.cc.o -c /tmp/snappy-1.1.10/snappy-sinksource.cc

...

make[2]: Entering directory '/tmp/snappy-1.1.10/build-demo'
[ 64%] Building CXX object CMakeFiles/snappy_unittest.dir/snappy_unittest.cc.o
/usr/bin/g++ -DHAVE_CONFIG_H -I/tmp/snappy-1.1.10 -I/tmp/snappy-1.1.10/build-demo -fPIC -fstack-protector-strong -DNDEBUG -Wall -Wextra -fno-exceptions -std=c++11 -DGTEST_HAS_PTHREAD=1 -MD -MT CMakeFiles/snappy_unittest.dir/snappy_unittest.cc.o -MF CMakeFiles/snappy_unittest.dir/snappy_unittest.cc.o.d -o CMakeFiles/snappy_unittest.dir/snappy_unittest.cc.o -c /tmp/snappy-1.1.10/snappy_unittest.cc
In file included from /usr/include/gtest/gtest-message.h:57,
                 from /usr/include/gtest/gtest-assertion-result.h:46,
                 from /usr/include/gtest/gtest.h:64,
                 from /tmp/snappy-1.1.10/snappy_unittest.cc:39:
/usr/include/gtest/internal/gtest-port.h:270:2: error: #error C++ versions less than C++14 are not supported.
  270 | #error C++ versions less than C++14 are not supported.
      |  ^~~~~
In file included from /usr/include/gtest/gtest-printers.h:115,
                 from /usr/include/gtest/gtest-matchers.h:48,
                 from /usr/include/gtest/internal/gtest-death-test-internal.h:47,
                 from /usr/include/gtest/gtest-death-test.h:43,
                 from /usr/include/gtest/gtest.h:65:
/usr/include/gtest/internal/gtest-internal.h:636:58: error: wrong number of template arguments (0, should be 1)
  636 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
      |                                                          ^
In file included from /usr/include/c++/13.1.0/string:49,
                 from /usr/include/c++/13.1.0/random:42,
                 from /tmp/snappy-1.1.10/snappy_unittest.cc:32:
/usr/include/c++/13.1.0/bits/stl_function.h:403:12: note: provided for 'template<class _Tp> struct std::less'
  403 |     struct less : public binary_function<_Tp, _Tp, bool>
      |            ^~~~
/usr/include/gtest/internal/gtest-internal.h:636:59: error: template argument 3 is invalid
  636 |   typedef ::std::map<std::string, CodeLocation, std::less<>> RegisteredTestsMap;
      |                                                           ^~
/usr/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::AddTestName(const char*, int, const char*, const char*)':
/usr/include/gtest/internal/gtest-internal.h:613:23: error: request for member 'insert' in '((testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'int'}
  613 |     registered_tests_.insert(
      |                       ^~~~~~
/usr/include/gtest/internal/gtest-internal.h: In member function 'bool testing::internal::TypedTestSuitePState::TestExists(const std::string&) const':
/usr/include/gtest/internal/gtest-internal.h:619:30: error: request for member 'count' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'const int'}
  619 |     return registered_tests_.count(test_name) > 0;
      |                              ^~~~~
/usr/include/gtest/internal/gtest-internal.h: In member function 'const testing::internal::CodeLocation& testing::internal::TypedTestSuitePState::GetCodeLocation(const std::string&) const':
/usr/include/gtest/internal/gtest-internal.h:623:40: error: qualified-id in declaration before 'it'
  623 |     RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name);
      |                                        ^~
/usr/include/gtest/internal/gtest-internal.h:624:5: error: 'it' was not declared in this scope; did you mean 'int'?
  624 |     GTEST_CHECK_(it != registered_tests_.end());
      |     ^~~~~~~~~~~~
/usr/include/gtest/internal/gtest-internal.h:624:5: error: request for member 'end' in '((const testing::internal::TypedTestSuitePState*)this)->testing::internal::TypedTestSuitePState::registered_tests_', which is of non-class type 'const testing::internal::TypedTestSuitePState::RegisteredTestsMap' {aka 'const int'}
  624 |     GTEST_CHECK_(it != registered_tests_.end());
      |     ^~~~~~~~~~~~
/usr/include/gtest/internal/gtest-internal.h:625:12: error: 'it' was not declared in this scope; did you mean 'int'?
  625 |     return it->second;
      |            ^~
      |            int
make[2]: *** [CMakeFiles/snappy_unittest.dir/build.make:76: CMakeFiles/snappy_unittest.dir/snappy_unittest.cc.o] Error 1
make[2]: Leaving directory '/tmp/snappy-1.1.10/build-demo'
make[1]: *** [CMakeFiles/Makefile2:144: CMakeFiles/snappy_unittest.dir/all] Error 2
make[1]: Leaving directory '/tmp/snappy-1.1.10/build-demo'
make: *** [Makefile:146: all] Error 2
make: Leaving directory '/tmp/snappy-1.1.10/build-demo'
  • Loading branch information
Min4sT1r1th authored Jul 13, 2023
1 parent 27f34a5 commit c780fa8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ project(Snappy VERSION 1.1.10 LANGUAGES C CXX)

# C++ standard can be overridden when this is used as a sub-project.
if(NOT CMAKE_CXX_STANDARD)
# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
# This project requires C++11 (but googletest 1.13.x requires C++14)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_STANDARD)
Expand Down

0 comments on commit c780fa8

Please sign in to comment.