Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CMake uninitialized variable warnings #19683

Open
bryan-lipinski opened this issue Dec 16, 2024 · 1 comment
Open

CMake uninitialized variable warnings #19683

bryan-lipinski opened this issue Dec 16, 2024 · 1 comment

Comments

@bryan-lipinski
Copy link

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

@bryan-lipinski bryan-lipinski added the untriaged auto added to all issues by default when created. label Dec 16, 2024
@zhangskz zhangskz added c++ cmake help wanted and removed untriaged auto added to all issues by default when created. labels Dec 16, 2024
@bryan-lipinski
Copy link
Author

Here's the patch I'm currently using to workaround the issue. However, I wasn't sure of what behavior the set(${UPPER} call should have if ${Camel} is undefined.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants