Allow selection of system default C++ version.

This leaves the decision of which C++ version to use up to our users.  We still have a static_assert in port_def.inc that will prevent pre-C++14 usage.

PiperOrigin-RevId: 501351066
pull/11472/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 71a1027dcd
commit c92294ac6d
  1. 21
      CMakeLists.txt
  2. 13
      cmake/README.md
  3. 3
      kokoro/common/cmake.sh
  4. 2
      kokoro/linux/32-bit/test_php.sh
  5. 7
      kokoro/linux/cmake/build.sh
  6. 11
      kokoro/linux/cmake_install/build.sh
  7. 4
      kokoro/linux/cmake_ninja/build.sh
  8. 7
      kokoro/linux/cmake_shared/build.sh

@ -40,27 +40,6 @@ if(protobuf_DEPRECATED_CMAKE_SUBDIRECTORY_USAGE)
get_filename_component(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} DIRECTORY)
endif()
# Add C++14 flags
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CYGWIN)
string(REGEX_MATCH "-std=gnu\\+\\+([0-9]+)" _protobuf_CXX_STD "${CMAKE_CXX_FLAGS}")
endif()
if(NOT _protobuf_CXX_STD)
set(_protobuf_CXX_STD "${CMAKE_CXX_STANDARD}")
endif()
if(_protobuf_CXX_STD LESS "14")
message(FATAL_ERROR "Protocol Buffers requires at least C++14, but is configured for C++${_protobuf_CXX_STD}")
endif()
if(CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++${_protobuf_CXX_STD}")
else()
set(CMAKE_CXX_STANDARD ${_protobuf_CXX_STD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
# The Intel compiler isn't able to deal with noinline member functions of
# template classes defined in headers. As such it spams the output with
# warning #2196: routine is both "inline" and "noinline"

@ -8,6 +8,19 @@ currently support CMake 3.5 and newer on both [Windows](#windows-builds) and
Most of the instructions will be given using CMake's command-line interface, but
the same actions can be performed using appropriate GUI tools.
# CMake Flags
## C++ Version
By default, CMake will use whatever C++ version is the system default. Since
protobuf requires C++14 or newer, sometimes you will need to explicitly override
this. For example, the following:
cmake . -DCMAKE_CXX_STANDARD=14
cmake --build
will build protobuf using C++14 (see [CXX_STANDARD](https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html#prop_tgt:CXX_STANDARD){.external} for all available options).
# Windows Builds
On Windows, you can build the project from *Command Prompt* and using an

@ -60,7 +60,8 @@ mkdir -p "${BUILD_DIR}"
caplog 01_configure \
cmake -S "${SOURCE_DIR}" \
${CMAKE_BUILD_TYPE_FLAG} \
${CAPLOG_CMAKE_ARGS:-}
${CAPLOG_CMAKE_ARGS:-} \
-DCMAKE_CXX_STANDARD=14
)
if [[ -n ${CAPLOG_DIR:-} ]]; then
# Save configuration logs.

@ -38,7 +38,7 @@ build_php_c() {
mkdir -p build
pushd build
cmake ..
cmake .. -DCMAKE_CXX_STANDARD=14
cmake --build . -- -j20
ctest --verbose --parallel 20
export PROTOC=$(pwd)/protoc

@ -8,7 +8,7 @@ set -eux
cd $(dirname $0)/../../..
GIT_REPO_ROOT=`pwd`
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:bd17c13255c8c7af2821c6597ad96568d714c0ea9d9e27d81b108fcc195ca858
# Update git submodules and regenerate files
git submodule update --init --recursive
@ -22,7 +22,10 @@ docker run \
--cidfile $tmpfile \
-v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \
/test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON
/test.sh \
-Dprotobuf_BUILD_CONFORMANCE=ON \
-Dprotobuf_BUILD_EXAMPLES=ON \
-DCMAKE_CXX_STANDARD=14
# Save logs for Kokoro
docker cp \

@ -8,7 +8,7 @@ set -eux
cd $(dirname $0)/../../..
GIT_REPO_ROOT=`pwd`
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:bd17c13255c8c7af2821c6597ad96568d714c0ea9d9e27d81b108fcc195ca858
# Update git submodules and regenerate files
git submodule update --init --recursive
@ -22,10 +22,11 @@ docker run \
--cidfile $tmpfile \
-v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \
"/install.sh && /test.sh \
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON \
-Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF \
-Dprotobuf_BUILD_CONFORMANCE=ON"
"/install.sh -DCMAKE_CXX_STANDARD=14 && /test.sh \
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON \
-Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF \
-Dprotobuf_BUILD_CONFORMANCE=ON \
-DCMAKE_CXX_STANDARD=14"
# Save logs for Kokoro

@ -8,7 +8,7 @@ set -eux
cd $(dirname $0)/../../..
GIT_REPO_ROOT=`pwd`
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:bd17c13255c8c7af2821c6597ad96568d714c0ea9d9e27d81b108fcc195ca858
# Update git submodules and regenerate files
git submodule update --init --recursive
@ -22,7 +22,7 @@ docker run \
--cidfile $tmpfile \
-v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \
/test.sh -G Ninja -Dprotobuf_BUILD_CONFORMANCE=ON
/test.sh -G Ninja -Dprotobuf_BUILD_CONFORMANCE=ON -DCMAKE_CXX_STANDARD=14
# Save logs for Kokoro
docker cp \

@ -8,7 +8,7 @@ set -eux
cd $(dirname $0)/../../..
GIT_REPO_ROOT=`pwd`
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671
CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:bd17c13255c8c7af2821c6597ad96568d714c0ea9d9e27d81b108fcc195ca858
# Update git submodules and regenerate files
git submodule update --init --recursive
@ -22,7 +22,10 @@ docker run \
--cidfile $tmpfile \
-v $GIT_REPO_ROOT:/workspace \
$CONTAINER_IMAGE \
/test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_SHARED_LIBS=ON
/test.sh \
-Dprotobuf_BUILD_CONFORMANCE=ON \
-Dprotobuf_BUILD_SHARED_LIBS=ON \
-DCMAKE_CXX_STANDARD=14
# Save logs for Kokoro
docker cp \

Loading…
Cancel
Save