Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

cmake: fix/add missing feature detections for Windows/MS-DOS #16278

Closed
wants to merge 12 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Feb 9, 2025

Almost all feature detection results are pre-filled on Windows
for performance, so none of the issues fixed here affected builds.

For good measure, this patch add missing detections and fixes others
to make sure they work even when omitting the pre-fill.

It also fixes detecting IPv6 for MS-DOS.

Also:

  • add debug option to test without pre-filling.
  • replace NOT LESS with GREATER_EQUAL

w/o whitespace: https://github.com/curl/curl/pull/16278/files?w=1

@vszakats vszakats added cmake Windows Windows-specific tidy-up labels Feb 9, 2025
@vszakats vszakats changed the title cmake: fix feature detections for Windows cmake: fix/add feature detections for Windows Feb 9, 2025
@github-actions github-actions bot added the build label Feb 9, 2025
@vszakats vszakats changed the title cmake: fix/add feature detections for Windows cmake: fix/add missing feature detections for Windows Feb 9, 2025
@testclutch

This comment was marked as outdated.

vszakats added a commit to vszakats/curl that referenced this pull request Feb 10, 2025
Almost all feature detection results are pre-filled on Windows
for performance, so none of the issues fixed here affected builds.

But, for good measure, this patch add missing detections and fixes
others to make sure they work even when omitting the pre-fill.

- fix `HAVE_STRUCT_TIMEVAL` detection for MSVC.
  Follow-up to c1bc090 curl#12495
- add `HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID` detection for Windows.
- fix `HAVE_STRDUP` detection for MSVC.
- fix `HAVE_SNPRINTF` detection for Windows.
  Regression from 8e34505 curl#15164
- fix `HAVE_IOCTLSOCKET` detection for non-UWP MSVC.
- exclude `if_nametoindex` detection for Windows.
  Although it exists on Windows, detection, usage and availability is
  complicated, and curl doesn't use it on this platform.
  Regression from 8e34505 curl#15164

Also:
- move IPv6-related detections so that pre-filling applies to them.
- add debug option to test without pre-filling.
- fix compiler warnings happening in feature detections to reduce log
  noise. (uninitialized/unused variables, missing static, missing const,
  constant conditional, macro redef, OpenSSL 3 deprecation warning.)

Closes curl#16278
To make the cache affect HAVE_SOCKADDR_IN6_* detections
```
cl /c /ID:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\ /I"Generated Files\\\\" /IcmTC_a5c0f.dir\\Debug\\ /Zi /W4 /WX- /diagnostics:column /sdl /MP /Od /Ob0 /Oy- /D _UNICODE /D UNICODE /D _DEBUG /D WINAPI_FAMILY=WINAPI_FAMILY_APP /D __WRL_NO_DEFAULT_LIB__ /D WINAPI_FAMILY=WINAPI_FAMILY_PC_APP /D HAVE_IOCTLSOCKET /D HAVE_STDBOOL_H /D HAVE_SYS_TYPES_H /D WIN32_LEAN_AND_MEAN /D _CRT_NONSTDC_NO_DEPRECATE /D "CMAKE_INTDIR=\\"Debug\\"" /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_a5c0f.dir\\Debug\\\\" /Fd"cmTC_a5c0f.dir\\Debug\\vc143.pdb" /external:W4 /Gd /TC /FU"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.42.34433\\lib\\x86\\store\\references\\platform.winmd" /analyze- /errorReport:queue D:\\a\\curl\\curl\\CMake\\CurlTests.c
          CurlTests.c
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,17): warning C4189: 'flags': local variable is initialized but not referenced [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_a5c0f.vcxproj]
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,1): error C4700: uninitialized local variable 'socket' used [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_a5c0f.vcxproj]
        Done Building Project "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_a5c0f.vcxproj" (default targets) -- FAILED.

        Build FAILED.
```
https://github.com/curl/curl/actions/runs/13215270720/job/36893785770?pr=16238#step:7:12099

vs non-UWP:
```
         cl /c /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /Zi /W4 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D HAVE_IOCTLSOCKET /D HAVE_STDBOOL_H /D HAVE_SYS_TYPES_H /D WIN32_LEAN_AND_MEAN /D _CRT_NONSTDC_NO_DEPRECATE /D "CMAKE_INTDIR=\\"Debug\\"" /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_41ff3.dir\\Debug\\\\" /Fd"cmTC_41ff3.dir\\Debug\\vc143.pdb" /external:W4 /Gd /TC /errorReport:queue D:\\a\\curl\\curl\\CMake\\CurlTests.c
          CurlTests.c
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,17): warning C4189: 'flags': local variable is initialized but not referenced [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,1): warning C4700: uninitialized local variable 'socket' used [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]
        Link:
          C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.42.34433\\bin\\HostX64\\x64\\link.exe /ERRORREPORT:QUEUE /OUT:"D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\Debug\\cmTC_41ff3.exe" /INCREMENTAL /ILK:"cmTC_41ff3.dir\\Debug\\cmTC_41ff3.ilk" /NOLOGO ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"D:/a/curl/curl/bld/CMakeFiles/CMakeTmp/Debug/cmTC_41ff3.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/a/curl/curl/bld/CMakeFiles/CMakeTmp/Debug/cmTC_41ff3.lib" /MACHINE:X64 cmTC_41ff3.dir\\Debug\\CurlTests.obj
          cmTC_41ff3.vcxproj -> D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\Debug\\cmTC_41ff3.exe
        FinalizeBuildStatus:
          Deleting file "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\unsuccessfulbuild".
          Touching "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\cmTC_41ff3.lastbuildstate".
        Done Building Project "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj" (default targets).

        Build succeeded.
```
https://github.com/curl/curl/actions/runs/13215270720/job/36893785770?pr=16238#step:7:12099
This is declared via iphlpapi.h and needs iphlpapi implib.
In MSVC UWP it gets detected, presumably because iphlpapi is linked by default (?),
and the commit below switched detection to 'function' (vs 'symbol')
to match ./configure. This results in an unwanted detection for MSVC UWP,
because we normally don't want to use this function on Windows in curl.
The mis-detection is even stranger because this function is not declared
by the SDK for UWP.

https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-if_nametoindex

Normally we pre-cache this value to FALSE, so it wasn't causing any issue.

Regression from 8e34505

```
    kind: "try_compile-v1"
    backtrace:
      - "CMake/Macros.cmake:51 (try_compile)"
      - "CMakeLists.txt:1815 (curl_internal_test)"
    directories:
      source: "D:/a/curl/curl/bld/CMakeFiles/CMakeTmp"
      binary: "D:/a/curl/curl/bld/CMakeFiles/CMakeTmp"
    cmakeVariables:
      CMAKE_C_FLAGS: " -W4 -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include -IC:/vcpkg/installed/x64-windows/debug/../include"
      CMAKE_C_FLAGS_DEBUG: "/Zi /Ob0 /Od /RTC1"
      CMAKE_EXE_LINKER_FLAGS: "-INCREMENTAL:NO"
      CMAKE_MODULE_PATH: "D:/a/curl/curl/CMake"
      VCPKG_INSTALLED_DIR: "C:/vcpkg/installed"
      VCPKG_PREFER_SYSTEM_LIBS: "OFF"
      VCPKG_TARGET_TRIPLET: "x64-windows"
      Z_VCPKG_ROOT_DIR: "C:/vcpkg"
    buildResult:
      variable: "HAVE_IOCTLSOCKET"
      cached: true
      stdout: |
        Change Dir: 'D:/a/curl/curl/bld/CMakeFiles/CMakeTmp'

        Run Build Command(s): "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/amd64/MSBuild.exe" cmTC_41ff3.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=17.0 /v:n
        MSBuild version 17.12.12+1cce77968 for .NET Framework
        Build started 2/8/2025 11:40:41 AM.

        Project "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj" on node 1 (default targets).
        PrepareForBuild:
          Creating directory "cmTC_41ff3.dir\\Debug\\".
          Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
          Creating directory "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\Debug\\".
          Creating directory "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\".
        InitializeBuildStatus:
          Creating "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\unsuccessfulbuild" because "AlwaysCreate" was specified.
          Touching "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\unsuccessfulbuild".
        ClCompile:
          C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.42.34433\\bin\\HostX64\\x64\\CL.exe /c /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /Zi /W4 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D HAVE_IOCTLSOCKET /D HAVE_STDBOOL_H /D HAVE_SYS_TYPES_H /D WIN32_LEAN_AND_MEAN /D _CRT_NONSTDC_NO_DEPRECATE /D "CMAKE_INTDIR=\\"Debug\\"" /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_41ff3.dir\\Debug\\\\" /Fd"cmTC_41ff3.dir\\Debug\\vc143.pdb" /external:W4 /Gd /TC /errorReport:queue D:\\a\\curl\\curl\\CMake\\CurlTests.c
          Microsoft (R) C/C++ Optimizing Compiler Version 19.42.34436 for x64
          Copyright (C) Microsoft Corporation.  All rights reserved.
          cl /c /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /I"C:\\vcpkg\\installed\\x64-windows\\debug\\..\\include" /Zi /W4 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D HAVE_IOCTLSOCKET /D HAVE_STDBOOL_H /D HAVE_SYS_TYPES_H /D WIN32_LEAN_AND_MEAN /D _CRT_NONSTDC_NO_DEPRECATE /D "CMAKE_INTDIR=\\"Debug\\"" /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_41ff3.dir\\Debug\\\\" /Fd"cmTC_41ff3.dir\\Debug\\vc143.pdb" /external:W4 /Gd /TC /errorReport:queue D:\\a\\curl\\curl\\CMake\\CurlTests.c
          CurlTests.c
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,17): warning C4189: 'flags': local variable is initialized but not referenced [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]
        D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,1): warning C4700: uninitialized local variable 'socket' used [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]
        Link:
          C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.42.34433\\bin\\HostX64\\x64\\link.exe /ERRORREPORT:QUEUE /OUT:"D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\Debug\\cmTC_41ff3.exe" /INCREMENTAL /ILK:"cmTC_41ff3.dir\\Debug\\cmTC_41ff3.ilk" /NOLOGO ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"D:/a/curl/curl/bld/CMakeFiles/CMakeTmp/Debug/cmTC_41ff3.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/a/curl/curl/bld/CMakeFiles/CMakeTmp/Debug/cmTC_41ff3.lib" /MACHINE:X64 cmTC_41ff3.dir\\Debug\\CurlTests.obj
          cmTC_41ff3.vcxproj -> D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\Debug\\cmTC_41ff3.exe
        FinalizeBuildStatus:
          Deleting file "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\unsuccessfulbuild".
          Touching "cmTC_41ff3.dir\\Debug\\cmTC_41ff3.tlog\\cmTC_41ff3.lastbuildstate".
        Done Building Project "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj" (default targets).

        Build succeeded.

        "D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj" (default target) (1) ->
        (ClCompile target) ->
          D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,17): warning C4189: 'flags': local variable is initialized but not referenced [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]
          D:\\a\\curl\\curl\\CMake\\CurlTests.c(171,1): warning C4700: uninitialized local variable 'socket' used [D:\\a\\curl\\curl\\bld\\CMakeFiles\\CMakeTmp\\cmTC_41ff3.vcxproj]

            2 Warning(s)
            0 Error(s)

        Time Elapsed 00:00:00.62

      exitCode: 0
```
https://github.com/curl/curl/actions/runs/13215270720/job/36893785298?pr=16238#step:7:7163
vszakats added a commit to vszakats/curl that referenced this pull request Feb 11, 2025
Almost all feature detection results are pre-filled on Windows
for performance, so none of the issues fixed here affected builds.

But, for good measure, this patch add missing detections and fixes
others to make sure they work even when omitting the pre-fill.

- fix `HAVE_STRUCT_TIMEVAL` detection for MSVC.
  Follow-up to c1bc090 curl#12495
- add `HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID` detection for Windows.
- fix `HAVE_STRDUP` detection for MSVC.
- fix `HAVE_SNPRINTF` detection for Windows.
  Regression from 8e34505 curl#15164
- fix `HAVE_IOCTLSOCKET` detection for non-UWP MSVC.
- exclude `if_nametoindex` detection for Windows.
  Although it exists on Windows, detection, usage and availability is
  complicated, and curl doesn't use it on this platform.
  Regression from 8e34505 curl#15164

Also:
- move IPv6 detections so that pre-filling applies to them.
- add debug option to test without pre-filling.
- replace `NOT LESS` with `GREATER_EQUAL`

Closes curl#16278
@vszakats vszakats changed the title cmake: fix/add missing feature detections for Windows cmake: fix/add missing feature detections for Windows/MS-DOS Feb 11, 2025
@vszakats vszakats closed this in 6ab1fa4 Feb 11, 2025
@vszakats vszakats deleted the cm-fix-w-detection branch February 11, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants