Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135648

[REG 6.7->6.8] macOS: FindWrapResolv.cmake fails check_cxx_source_compiles with strict flags (-Werror -Wzero-as-null-pointer-constant)

    XMLWordPrintable

Details

    • macOS
    • 52e2a89c6 (dev), 1f2f5ee08 (6.9), 366def8f6 (6.8)

    Description

      CMake configuration fails when finding Qt6 Network (or components depending on it like Gui/Widgets) on macOS when using strict compiler flags like -Weverything and -Werror.

      The specific failure occurs within the 
      FindWrapResolv.cmake
       script, which is new or changed in Qt 6.8. This script uses check_cxx_source_compiles to verify the presence of resolver functions. However, the test code within this check uses res_state statep = 0;.

      When compiled with strict flags, specifically -Wzero-as-null-pointer-constant (often enabled by -Wall, -Wextra, or -Weverything) combined with -Werror, this line causes a fatal compilation error because 0 is used instead of nullptr for a pointer type.

      This compilation error causes check_cxx_source_compiles to fail, leading 
      FindWrapResolv.cmake
       to incorrectly report that the dependency is not found, ultimately causing find_package(Qt6) to fail for components requiring QtNetwork.

      This is a regression from Qt 6.7.x where this check was either not present or did not cause issues.

      Steps to Reproduce:

      Set up a minimal CMake project on macOS.
      Configure CMake to use C++20 or later.
      Set CMAKE_CXX_FLAGS to include strict checks, crucially -Werror and -Wzero-as-null-pointer-constant (e.g., -Wall -Wextra -Wpedantic -Werror -Wzero-as-null-pointer-constant).
      Ensure Qt 6.8.0 or later is available (e.g., via vcpkg or system install).
      Add find_package(Qt6 6.8 REQUIRED COMPONENTS Network) (or Gui/Widgets) to 
      CMakeLists.txt.

      Run CMake configure.

      Expected Result:

      CMake configures the project successfully, finding Qt6 and its components.

      Actual Result:

      CMake configuration fails. The error messages typically indicate that WrapResolv could not be found, or that Qt6Network could not be found because its dependency WrapResolv failed. Example CMake output snippet:

      ...

      CMake Error at /path/to/vcpkg_installed/arm64-osx/share/Qt6/Qt6Config.cmake:190 (find_package):
        Found package configuration file:

          /path/to/vcpkg_installed/arm64-osx/share/Qt6Network/Qt6NetworkConfig.cmake

        but it set Qt6Network_FOUND to FALSE so package "Qt6Network" is considered
        to be NOT FOUND.  Reason given by package:

        Qt6Network could not be found because dependency WrapResolv could not be
        found.
      (Note: The exact error message might vary slightly depending on which Qt component triggers the find_package call first)

      Proposed Fix:

      Modify the test code within 
      FindWrapResolv.cmake
       to use modern C++: Change:

      res_state statep = 0;
      to:

      res_state statep = nullptr;

      Workaround:

      A successful workaround is to temporarily clear CMAKE_CXX_FLAGS before calling find_package(Qt6) and restore it afterwards within the 
      CMakeLists.txt:

      set(ORIGINAL_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
      set(CMAKE_CXX_FLAGS "" CACHE STRING "Temp clear for Qt find" FORCE)
      find_package(Qt6 6.8 REQUIRED COMPONENTS Network) # Or other components
      set(CMAKE_CXX_FLAGS "${ORIGINAL_CMAKE_CXX_FLAGS}" CACHE STRING "Restore flags" FORCE)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            semlanik Alexey Edelev
            ordis_ben Benjamin Oldenburg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes