From be2c33276bb64425e821179d32246acfc1e9d619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sun, 21 Apr 2024 14:47:19 +0200 Subject: [PATCH 1/5] cmake: fix recent protobuf build with cmake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CMake module is used by default but isn't compatible with recent protobuf version. Try to first look for a protobuf config then fallback to legacy cmake module. Signed-off-by: Clément Péron --- build-cmake/CMakeLists.txt | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index c7db9f2..7ced9cd 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -15,7 +15,11 @@ if (MSVC AND NOT BUILD_SHARED_LIBS) SET(Protobuf_USE_STATIC_LIBS ON) endif (MSVC AND NOT BUILD_SHARED_LIBS) -FIND_PACKAGE(Protobuf REQUIRED) +FIND_PACKAGE(Protobuf CONFIG) +if(NOT Protobuf_FOUND) + MESSAGE(STATUS "Protobuf CMake config not found fallback to Cmake Module") + FIND_PACKAGE(Protobuf REQUIRED) +endif() file(REAL_PATH "${PROTOBUF_INCLUDE_DIR}" PROTOBUF_INCLUDE_DIR) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) @@ -112,7 +116,7 @@ if (MSVC AND NOT BUILD_SHARED_LIBS) foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_FLAGS_RELWITHDEBINFO) if(${flag_var} MATCHES "/MD") string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") @@ -316,12 +320,12 @@ ADD_TEST(test-version test-version) if(WIN32) set_tests_properties( - test-generated-code - test-generated-code2 - test-generated-code3 - test-issue220 - test-issue251 - test-version + test-generated-code + test-generated-code2 + test-generated-code3 + test-issue220 + test-issue251 + test-version PROPERTIES ENVIRONMENT "PATH=${WINDOWS_PATH_VARIABLE}\\;$" ) endif(WIN32) From 05f9112acdf318b33280128422e7f1d5f99e4e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sun, 21 Apr 2024 14:54:28 +0200 Subject: [PATCH 2/5] ci: build: always update cache to avoid out of date packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit APT cache could be out of date leading to a: E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing? Fix this by always calling apt-get update before an apt-get install. Signed-off-by: Clément Péron --- .github/workflows/build.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c8c34e..1e83065 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,9 @@ jobs: - uses: actions/checkout@v2 - name: Install Linux dependencies if: startsWith(matrix.os, 'ubuntu') - run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev + run: | + sudo apt-get update -y + sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev - name: Install Mac dependencies if: startsWith(matrix.os, 'macos') run: brew install protobuf automake @@ -60,7 +62,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install dependencies - run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev valgrind + run: | + sudo apt-get update -y + sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev valgrind - name: Run distcheck with valgrind run: | ./autogen.sh @@ -72,7 +76,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Install dependencies - run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev lcov + run: | + sudo apt-get update -y + sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev lcov - name: Run coverage build run: | ./autogen.sh @@ -96,7 +102,9 @@ jobs: - uses: actions/checkout@v2 - name: Install Linux dependencies if: startsWith(matrix.os, 'ubuntu') - run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev + run: | + sudo apt-get update -y + sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev - name: Install Mac dependencies if: startsWith(matrix.os, 'macos') run: brew install protobuf abseil From 1c954558f137a40cd6508df789347db74e3bc1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sun, 21 Apr 2024 15:01:32 +0200 Subject: [PATCH 3/5] cmake: fix warning about policy CMP0145 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep the DART compatibility enabled until test are moved to CTest. Signed-off-by: Clément Péron --- build-cmake/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 7ced9cd..fdd28d1 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -8,6 +8,10 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) cmake_policy(SET CMP0074 NEW) cmake_policy(SET CMP0091 NEW) cmake_policy(SET CMP0112 NEW) +# TODO: Convert DART to CTEST +if(POLICY CMP0145) + cmake_policy(SET CMP0145 OLD) +endif() PROJECT(protobuf-c C CXX) From 49966f6c849d2a5ed99e80b95a851b3ba4a7a0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Sun, 21 Apr 2024 15:06:58 +0200 Subject: [PATCH 4/5] cmake: keep compatibility with CMake FindProtobuf module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROTOBUF_PROTOC_EXECUTABLE is not set in the Protobuf CMake config file. Set it properly in case we use CMake protobuf config file. Signed-off-by: Clément Péron --- build-cmake/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index fdd28d1..1ac2e81 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -20,7 +20,10 @@ if (MSVC AND NOT BUILD_SHARED_LIBS) endif (MSVC AND NOT BUILD_SHARED_LIBS) FIND_PACKAGE(Protobuf CONFIG) -if(NOT Protobuf_FOUND) +if(Protobuf_FOUND) + # Keep compatibility with FindProtobuf CMake module + set(PROTOBUF_PROTOC_EXECUTABLE $) +else() MESSAGE(STATUS "Protobuf CMake config not found fallback to Cmake Module") FIND_PACKAGE(Protobuf REQUIRED) endif() From af0ea6fac8947b3466ed4599bbdb6f83f4051599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= Date: Mon, 22 Apr 2024 08:29:06 +0200 Subject: [PATCH 5/5] cmake: link with target to also get include directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cxx-generate-packed-data needs to link with protobuf library for the C++ source file. Use the protobuf::libprotobuf to get both library and include directory. Signed-off-by: Clément Péron --- build-cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 1ac2e81..9d22321 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -220,7 +220,7 @@ GENERATE_TEST_SOURCES(${TEST_DIR}/test-full.proto t/test-full.pb-c.c t/test-full ADD_EXECUTABLE(cxx-generate-packed-data ${TEST_DIR}/generated-code2/cxx-generate-packed-data.cc t/test-full.pb.h t/test-full.pb.cc protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h) TARGET_LINK_LIBRARIES(cxx-generate-packed-data - ${PROTOBUF_LIBRARY} + protobuf::libprotobuf ${protobuf_ABSL_USED_TARGETS} ${protobuf_UTF8_USED_TARGETS} )