cmake: support building static and shared libcurl in one go

This patch adds the ability to build a static and shared libcurl library
in a single build session. It also adds an option to select which one to
use when building the curl executable.

New build options:
- `BUILD_STATIC_LIBS`. Default: `OFF`.
  Enabled automatically if `BUILD_SHARED_LIBS` is `OFF`.
- `BUILD_STATIC_CURL`. Default: `OFF`.
  Requires `BUILD_STATIC_LIBS` enabled.
  Enabled automatically if building static libcurl only.
- `STATIC_LIB_SUFFIX`. Default: empty.
- `IMPORT_LIB_SUFFIX`. Default: `_imp` if implib filename would collide
  with static lib name (typically with MSVC) in Windows builds.
  Otherwise empty.

Also:

- Stop setting the `CURL_STATICLIB` macro via `curl_config.h`, and pass
  it directly to the compiler. This also allows to delete a condition
  from `tests/server/CMakeLists.txt`.

- Complete a TODO by following the logic used in autotools (also for
  `LIBCURL_NO_SHARED`), and set `-DCURL_STATICLIB` in `Cflags:` of
  `libcurl.pc` for _static-only_ curl builds.

- Convert an existing CI test to build both shared and static libcurl.

Closes #11505
This commit is contained in:
Viktor Szakats 2023-06-22 09:24:37 +00:00
parent 40c63290e3
commit 1199308dbc
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
8 changed files with 143 additions and 90 deletions

View file

@ -62,7 +62,7 @@ if(WIN32)
endif()
# CURL_CFILES, CURLX_CFILES, CURL_HFILES come from Makefile.inc
if(NOT BUILD_SHARED_LIBS)
if(BUILD_STATIC_CURL)
set(CURLX_CFILES ../lib/dynbuf.c)
endif()
@ -107,7 +107,7 @@ include_directories(
)
#Build curl executable
target_link_libraries(${EXE_NAME} libcurl ${CURL_LIBS})
target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS})
################################################################################