From 2479e889b8b0c1a88b99e06802378602609a3a2a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 6 Apr 2023 11:11:52 +0200 Subject: [PATCH] Fix for Clang 16 --- cmake/Modules/BuildProtobuf.cmake | 43 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/cmake/Modules/BuildProtobuf.cmake b/cmake/Modules/BuildProtobuf.cmake index 779f60a2c..ca8ea19c7 100644 --- a/cmake/Modules/BuildProtobuf.cmake +++ b/cmake/Modules/BuildProtobuf.cmake @@ -4,10 +4,24 @@ # SPDX-FileCopyrightText: 2023 C. Fernandez-Prades cfernandez(at)cttc.es # SPDX-License-Identifier: BSD-3-Clause +# Downloads and builds the protoc compiler and static libraries of Protocol +# Buffers >= v22.0 (see https://protobuf.dev/) It requires CMake >= 3.10 and the +# abseil-cpp >= 20230117 libraries (see https://github.com/abseil/abseil-cpp) +# already installed. Zlib is used if found. +# +# Note: requires the patch command if using GCC >= 13 or Clang >= 16 +# +# Creates protobuf::libprotobuf and protobuf::protoc imported targets. + + if(NOT GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION) set(GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION "22.2") endif() +if(NOT GNSSSDR_BINARY_DIR) + set(GNSSSDR_BINARY_DIR "${PROJECT_BINARY_DIR}") +endif() + if(NOT ZLIB_FOUND) find_package(ZLIB) set_package_properties(ZLIB PROPERTIES @@ -43,22 +57,19 @@ list(APPEND UTF8_LIBRARIES ${GNSSSDR_BINARY_DIR}/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}utf8_range${CMAKE_STATIC_LIBRARY_SUFFIX} ) -# Fix for GCC 13 -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "12.99") - find_program(Patch_EXECUTABLE NAME patch PATHS ENV PATH) - if(NOT Patch_EXECUTABLE) - message(FATAL_ERROR "The patch command is not found. It is required to build Protocol Buffers. Please check your OS documentation and install the patch command.") - endif() - set(PROTOBUF_PATCH_COMMAND - cd ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/ && - ${Patch_EXECUTABLE} ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/port.h < ${GNSSSDR_SOURCE_DIR}/src/tests/data/protobuf22.patch - ) - # Patch only once - if(EXISTS ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/port.h) - set(PROTOBUF_PATCH_COMMAND "") - endif() - else() +# Fix for GCC 13 and Clang 16 +if(((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "13")) OR + ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16"))) + find_program(Patch_EXECUTABLE NAME patch PATHS ENV PATH) + if(NOT Patch_EXECUTABLE) + message(FATAL_ERROR "The patch command is not found. It is required to build Protocol Buffers. Please check your OS documentation and install the patch command.") + endif() + set(PROTOBUF_PATCH_COMMAND + cd ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/ && + ${Patch_EXECUTABLE} ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/port.h < ${GNSSSDR_SOURCE_DIR}/src/tests/data/protobuf22.patch + ) + # Patch only once + if(EXISTS ${GNSSSDR_BINARY_DIR}/thirdparty/protobuf/protobuf-${GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION}/src/google/protobuf/port.h) set(PROTOBUF_PATCH_COMMAND "") endif() else()