2020-03-07 16:21:33 +08:00
|
|
|
#ifndef HEADER_CURL_SETUP_WIN32_H
|
|
|
|
#define HEADER_CURL_SETUP_WIN32_H
|
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2020-03-07 16:21:33 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2020-03-07 16:21:33 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2020-03-07 16:21:33 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include header files for windows builds before redefining anything.
|
|
|
|
* Use this preprocessor block only to include or exclude windows.h,
|
2021-09-18 07:25:20 +08:00
|
|
|
* winsock2.h or ws2tcpip.h. Any other windows thing belongs
|
2020-03-07 16:21:33 +08:00
|
|
|
* to any other further and independent block. Under Cygwin things work
|
|
|
|
* just as under linux (e.g. <sys/socket.h>) and the winsock headers should
|
|
|
|
* never be included when __CYGWIN__ is defined. configure script takes
|
2021-09-18 07:25:20 +08:00
|
|
|
* care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK2_H,
|
2020-03-07 16:21:33 +08:00
|
|
|
* neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# if defined(UNICODE) && !defined(_UNICODE)
|
2022-08-29 15:59:23 +08:00
|
|
|
# error "UNICODE is defined but _UNICODE is not defined"
|
2020-03-07 16:21:33 +08:00
|
|
|
# endif
|
|
|
|
# if defined(_UNICODE) && !defined(UNICODE)
|
2022-08-29 15:59:23 +08:00
|
|
|
# error "_UNICODE is defined but UNICODE is not defined"
|
2020-03-07 16:21:33 +08:00
|
|
|
# endif
|
2022-08-27 03:16:47 +08:00
|
|
|
/*
|
|
|
|
* Don't include unneeded stuff in Windows headers to avoid compiler
|
|
|
|
* warnings and macro clashes.
|
|
|
|
* Make sure to define this macro before including any Windows headers.
|
|
|
|
*/
|
|
|
|
# ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# endif
|
|
|
|
# ifndef NOGDI
|
|
|
|
# define NOGDI
|
|
|
|
# endif
|
2020-03-07 16:21:33 +08:00
|
|
|
# ifdef HAVE_WINSOCK2_H
|
|
|
|
# include <winsock2.h>
|
|
|
|
# ifdef HAVE_WS2TCPIP_H
|
|
|
|
# include <ws2tcpip.h>
|
|
|
|
# endif
|
|
|
|
# endif
|
cmake: pre-fill rest of detection values for Windows
The goal of this patch is to avoid unnecessary feature detection work
when doing Windows builds with CMake. Do this by pre-filling well-known
detection results for Windows and specifically for mingw-w64 and MSVC
compilers. Also limit feature checks to platforms where the results are
actually used. Drop a few redundant ones. And some tidying up.
- pre-fill remaining detection values in Windows CMake builds.
Based on actual detection results observed in CI runs, preceding
similar work over libssh2 and matching up values with
`lib/config-win32.h`.
This brings down CMake configuration time from 58 to 14 seconds on the
same local machine.
On AppVeyor CI this translates to:
- 128 seconds -> 50 seconds VS2022 MSVC with OpenSSL (per CMake job):
https://ci.appveyor.com/project/curlorg/curl/builds/48208419/job/4gw66ecrjpy7necb#L296
https://ci.appveyor.com/project/curlorg/curl/builds/48217440/job/8m4fwrr2fe249uo8#L186
- 62 seconds -> 16 seconds VS2017 MINGW (per CMake job):
https://ci.appveyor.com/project/curlorg/curl/builds/48208419/job/s1y8q5ivlcs7ub29?fullLog=true#L290
https://ci.appveyor.com/project/curlorg/curl/builds/48217440/job/pchpxyjsyc9kl13a?fullLog=true#L194
The formula is about 1-3 seconds delay for each detection. Almost all
of these trigger a full compile-link cycle behind the scenes, slow
even today, both cross and native, mingw-w64 and apparently MSVC too.
Enabling .map files or other custom build features slows it down
further. (Similar is expected for autotools configure.)
- stop detecting `idn2.h` if idn2 was deselected.
autotools does this.
- stop detecting `idn2.h` if idn2 was not found.
This deviates from autotools. Source code requires both header and
lib, so this is still correct, but faster.
- limit `ADDRESS_FAMILY` detection to Windows.
- normalize `HAVE_WIN32_WINNT` value to lowercase `0x0a12` format.
- pre-fill `HAVE_WIN32_WINNT`-dependent detection results.
Saving 4 (slow) feature-detections in most builds: `getaddrinfo`,
`freeaddrinfo`, `inet_ntop`, `inet_pton`
- fix pre-filled `HAVE_SYS_TIME_H`, `HAVE_SYS_PARAM_H`,
`HAVE_GETTIMEOFDAY` for mingw-w64.
Luckily this do not change build results, as `WIN32` took
priority over `HAVE_GETTIMEOFDAY` with the current source
code.
- limit `HAVE_CLOCK_GETTIME_MONOTONIC_RAW` and
`HAVE_CLOCK_GETTIME_MONOTONIC` detections to non-Windows.
We're not using these in the source code for Windows.
- reduce compiler warning noise in CMake internal logs:
- fix to include `winsock2.h` before `windows.h`.
Apply it to autotools test snippets too.
- delete previous `-D_WINSOCKAPI_=` hack that aimed to fix the above.
- cleanup `CMake/CurlTests.c` to emit less warnings.
- delete redundant `HAVE_MACRO_SIGSETJMP` feature check.
It was the same check as `HAVE_SIGSETJMP`.
- delete 'experimental' marking from `CURL_USE_OPENSSL`.
- show CMake version via `CMakeLists.txt`.
Credit to the `zlib-ng` project for the idea:
https://github.com/zlib-ng/zlib-ng/blob/61e181c8ae93dbf56040336179c9954078bd1399/CMakeLists.txt#L7
- make `CMake/CurlTests.c` pass `checksrc`.
- `CMake/WindowsCache.cmake` tidy-ups.
- replace `WIN32` guard with `_WIN32` in `CMake/CurlTests.c`.
Closes #12044
2023-10-06 07:38:59 +08:00
|
|
|
# include <windows.h>
|
|
|
|
# include <winerror.h>
|
2020-03-07 16:21:33 +08:00
|
|
|
# include <tchar.h>
|
|
|
|
# ifdef UNICODE
|
|
|
|
typedef wchar_t *(*curl_wcsdup_callback)(const wchar_t *str);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
|
|
|
|
* undefine USE_WINSOCK.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef USE_WINSOCK
|
|
|
|
|
|
|
|
#ifdef HAVE_WINSOCK2_H
|
|
|
|
# define USE_WINSOCK 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define _WIN32_WINNT_[OS] symbols because not all Windows build systems have
|
|
|
|
* those symbols to compare against, and even those that do may be missing
|
|
|
|
* newer symbols.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WIN32_WINNT_NT4
|
|
|
|
#define _WIN32_WINNT_NT4 0x0400 /* Windows NT 4.0 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WIN2K
|
|
|
|
#define _WIN32_WINNT_WIN2K 0x0500 /* Windows 2000 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WINXP
|
|
|
|
#define _WIN32_WINNT_WINXP 0x0501 /* Windows XP */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WS03
|
|
|
|
#define _WIN32_WINNT_WS03 0x0502 /* Windows Server 2003 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WIN6
|
|
|
|
#define _WIN32_WINNT_WIN6 0x0600 /* Windows Vista */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_VISTA
|
|
|
|
#define _WIN32_WINNT_VISTA 0x0600 /* Windows Vista */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WS08
|
|
|
|
#define _WIN32_WINNT_WS08 0x0600 /* Windows Server 2008 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_LONGHORN
|
|
|
|
#define _WIN32_WINNT_LONGHORN 0x0600 /* Windows Vista */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WIN7
|
|
|
|
#define _WIN32_WINNT_WIN7 0x0601 /* Windows 7 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WIN8
|
|
|
|
#define _WIN32_WINNT_WIN8 0x0602 /* Windows 8 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WINBLUE
|
|
|
|
#define _WIN32_WINNT_WINBLUE 0x0603 /* Windows 8.1 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WINTHRESHOLD
|
|
|
|
#define _WIN32_WINNT_WINTHRESHOLD 0x0A00 /* Windows 10 */
|
|
|
|
#endif
|
|
|
|
#ifndef _WIN32_WINNT_WIN10
|
|
|
|
#define _WIN32_WINNT_WIN10 0x0A00 /* Windows 10 */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* HEADER_CURL_SETUP_WIN32_H */
|