cmake: add support for "unity" builds

Aka "jumbo" or "amalgamation" builds. It means to compile all sources
per target as a single C source. This is experimental.

You can enable it by passing `-DCMAKE_UNITY_BUILD=ON` to cmake.
It requires CMake 3.16 or newer.

It makes builds (much) faster, allows for better optimizations and tends
to promote less ambiguous code.

Also add a new AppVeyor CI job and convert an existing one to use
"unity" mode (one MSVC, one MinGW), and enable it for one macOS CI job.

Fix related issues:
- add missing include guard to `easy_lock.h`.
- rename static variables and functions (and a macro) with names reused
  across sources, or shadowed by local variables.
- add an `#undef` after use.
- add a missing `#undef` before use.
- move internal definitions from `ftp.h` to `ftp.c`.
- `curl_memory.h` fixes to make it work when included repeatedly.
- stop building/linking curlx bits twice for a static-mode curl tool.
  These caused doubly defined symbols in unity builds.
- silence missing extern declarations compiler warning for ` _CRT_glob`.
- fix extern declarations for `tool_freq` and `tool_isVistaOrGreater`.
- fix colliding static symbols in debug mode: `debugtime()` and
  `statename`.
- rename `ssl_backend_data` structure to unique names for each
  TLS-backend, along with the `ssl_connect_data` struct member
  referencing them. This required adding casts for each access.
- add workaround for missing `[P]UNICODE_STRING` types in certain Windows
  builds when compiling `lib/ldap.c`. To support "unity" builds, we had
  to enable `SCHANNEL_USE_BLACKLISTS` for Schannel (a Windows
  `schannel.h` option) _globally_. This caused an indirect inclusion of
  Windows `schannel.h` from `ldap.c` via `winldap.h` to have it enabled
  as well. This requires `[P]UNICODE_STRING` types, which is apperantly
  not defined automatically (as seen with both MSVS and mingw-w64).
  This patch includes `<subauth.h>` to fix it.
  Ref: https://github.com/curl/curl/runs/13987772013
  Ref: https://dev.azure.com/daniel0244/curl/_build/results?buildId=15827&view=logs&jobId=2c9f582d-e278-56b6-4354-f38a4d851906&j=2c9f582d-e278-56b6-4354-f38a4d851906&t=90509b00-34fa-5a81-35d7-5ed9569d331c
- tweak unity builds to compile `lib/memdebug.c` separately in memory
  trace builds to avoid PP confusion.
- force-disable unity for test programs.
- do not compile and link libcurl sources to libtests _twice_ when libcurl
  is built in static mode.

KNOWN ISSUES:
- running tests with unity builds may fail in cases.
- some build configurations/env may not compile in unity mode. E.g.:
  https://ci.appveyor.com/project/curlorg/curl/builds/47230972/job/51wfesgnfuauwl8q#L250

Ref: https://github.com/libssh2/libssh2/issues/1034
Ref: https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html
Ref: https://en.wikipedia.org/wiki/Unity_build

Closes #11095
This commit is contained in:
Viktor Szakats 2023-05-09 10:10:40 +00:00
parent e812473d1e
commit 3f8fc25720
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
57 changed files with 1188 additions and 899 deletions

View file

@ -58,13 +58,17 @@ transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
if(WIN32)
list(APPEND CURL_FILES curl.rc)
list(APPEND CURL_CFILES curl.rc)
endif()
# CURL_CFILES, CURLX_CFILES, CURL_HFILES come from Makefile.inc
if(NOT BUILD_SHARED_LIBS)
set(CURLX_CFILES ../lib/dynbuf.c)
endif()
# CURL_FILES comes from Makefile.inc
add_executable(
${EXE_NAME}
${CURL_FILES}
${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES}
)
add_executable(

View file

@ -49,7 +49,7 @@ struct finder {
/* The order of the variables below is important, as the index number is used
in the findfile() function */
static const struct finder list[] = {
static const struct finder conf_list[] = {
{ "CURL_HOME", NULL, FALSE },
{ "XDG_CONFIG_HOME", NULL, FALSE }, /* index == 1, used in the code */
{ "HOME", NULL, FALSE },
@ -109,8 +109,8 @@ char *findfile(const char *fname, int dotscore)
if(!fname[0])
return NULL;
for(i = 0; list[i].env; i++) {
char *home = curl_getenv(list[i].env);
for(i = 0; conf_list[i].env; i++) {
char *home = curl_getenv(conf_list[i].env);
if(home) {
char *path;
const char *filename = fname;
@ -120,14 +120,14 @@ char *findfile(const char *fname, int dotscore)
curl_free(home);
continue;
}
if(list[i].append) {
char *c = curl_maprintf("%s%s", home, list[i].append);
if(conf_list[i].append) {
char *c = curl_maprintf("%s%s", home, conf_list[i].append);
curl_free(home);
if(!c)
return NULL;
home = c;
}
if(list[i].withoutdot) {
if(conf_list[i].withoutdot) {
if(!dotscore || xdg) {
/* this is not looking for .curlrc, or the XDG_CONFIG_HOME was
defined so we skip the extended check */

View file

@ -78,6 +78,7 @@ int vms_show = 0;
* when command-line argument globbing is enabled under the MSYS shell, so turn
* it off.
*/
extern int _CRT_glob;
int _CRT_glob = 0;
#endif /* __MINGW32__ */

View file

@ -73,4 +73,10 @@ extern FILE *tool_stderr;
# include "tool_strdup.h"
#endif
#if defined(WIN32) && !defined(MSDOS)
/* set in win32_init() */
extern LARGE_INTEGER tool_freq;
extern bool tool_isVistaOrGreater;
#endif
#endif /* HEADER_CURL_TOOL_SETUP_H */

View file

@ -33,10 +33,6 @@
#if defined(WIN32) && !defined(MSDOS)
/* set in win32_init() */
extern LARGE_INTEGER tool_freq;
extern bool tool_isVistaOrGreater;
/* In case of bug fix this function has a counterpart in timeval.c */
struct timeval tvnow(void)
{