protocolbuffers/protobuf

CMake uninitialized variable warnings

Fermée

#19 683 ouverte le 16 déc. 2024

 (1 commentaire) (0 réaction) (0 personne assignée)C++ (16 128 forks)batch import
c++cmakehelp wanted

Métriques du dépôt

Stars
 (71 223 étoiles)
Métriques de merge PR
 (Merge moyen 2j 11h) (185 PRs mergées en 30 j)

Description

What version of protobuf and what language are you using? Version: main Language: C++

What operating system (Linux, Windows, ...) and version?

Windows 11 24H2

What runtime / compiler are you using (e.g., python version or gcc version)

cmake 3.30.5 msvc 19.41.34123.0

What did you do? Steps to reproduce the behavior:

find_package(Protobuf CONFIG)

Configure CMake using '--warn-uninitialized'

What did you expect to see

No warnings/errors

What did you see instead?

CMake Error (dev) vcpkg_installed/x64-windows-target/share/protobuf/protobuf-config-version.cmake:7 (set):
  uninitialized variable 'Protobuf_FIND_VERSION_PRERELEASE'
Call Stack (most recent call first):
  vcpkg_installed/x64-windows-target/share/protobuf/vcpkg-cmake-wrapper.cmake:3 (_find_package)
  cmake/tools/VCPkg/scripts/buildsystems/vcpkg.cmake:811 (include)

CMake Error (dev) at vcpkg_installed/x64-windows-target/share/protobuf/protobuf-config-version.cmake:11 (set):
  uninitialized variable 'Protobuf_FIND_VERSION_PRERELEASE'
Call Stack (most recent call first):
  vcpkg_installed/x64-windows-target/share/protobuf/vcpkg-cmake-wrapper.cmake:3 (_find_package)
  cmake/tools/VCPkg/scripts/buildsystems/vcpkg.cmake:811 (include)

CMake Error (dev) at vcpkg_installed/x64-windows-target/share/protobuf/protobuf-module.cmake:188 (set):
  uninitialized variable 'Protobuf_SRC_ROOT_FOLDER'
Call Stack (most recent call first):
  vcpkg_installed/x64-windows-target/share/protobuf/protobuf-config.cmake:21 (include)
  vcpkg_installed/x64-windows-target/share/protobuf/vcpkg-cmake-wrapper.cmake:3 (_find_package)
  cmake/tools/VCPkg/scripts/buildsystems/vcpkg.cmake:811 (include)

// Same error for:
//   Protobuf_IMPORT_DIRS
//   Protobuf_DEBUG
//   Protobuf_INCLUDE_DIR
//   Protobuf_LIBRARY_DEBUG
//   Protobuf_PROTOC_LIBRARY_DEBUG
//   Protobuf_LITE_LIBRARY_DEBUG

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

The first two warnings are related to #1778. However, that change failed to correct the similar variable dereference in the subsequent 'set'.

Code

# Prerelease versions cannot be passed in directly via the find_package command,
# so we allow users to specify it in a variable
if(NOT DEFINED "${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE")  // fixed
  set("${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}" "")  // not fixed
else()

The remaining warnings are due to the camel case to uppercase conversion dereferencing variables that weren't set.

Code

    string(TOUPPER ${Camel} UPPER)
    set(${UPPER} ${${Camel}})   // No check that ${Camel} is defined

Anything else we should know about your project / environment

Guide contributeur