cmake: add CURL_BUILD_EVERYTHING option

To build all targets in a single go, meaning curl and libcurl as normal,
and tests and examples in addition. To build-test everything without
running multiple cmake commands.

Enable with:
- `-DCURL_BUILD_EVERYTHING=ON`
  Special values: `QUICK` to build examples quickly for build test,
  `NOEXAMPLES` to not build examples.

A well-equipped build takes 2.8s of configure time, and 1.7s to build
everything (shared, unity, ninja, prefill), 1.4s with `QUICK`. Without
this option it takes <1s to build curl/libcurl.

Also: streamline `CURL_LINT` internal logic.

Closes #20429
This commit is contained in:
Viktor Szakats 2026-01-25 14:10:16 +01:00
parent 795433b923
commit 3aa4fbf2d4
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
4 changed files with 17 additions and 5 deletions

View file

@ -178,6 +178,7 @@ option(BUILD_STATIC_LIBS "Build static libraries" OFF)
option(BUILD_STATIC_CURL "Build curl executable with static libcurl" OFF)
option(ENABLE_ARES "Enable c-ares support" OFF)
option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
option(CURL_BUILD_EVERYTHING "Build optional build targets (examples, tests) by default" OFF)
if(WIN32)
option(ENABLE_UNICODE "Use the Unicode version of the Windows API functions" OFF)
@ -545,10 +546,7 @@ if(PERL_EXECUTABLE)
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh" "lib/ca-bundle.crt"
DEPENDS "${PROJECT_SOURCE_DIR}/scripts/firefox-db2pem.sh"
)
if(CURL_LINT)
set(_lint_all ALL)
endif()
add_custom_target(curl-lint "${_lint_all}"
add_custom_target(curl-lint
COMMENT "Running lint checks" VERBATIM USES_TERMINAL
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND "${PERL_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/scripts/checksrc-all.pl"
@ -557,6 +555,9 @@ if(PERL_EXECUTABLE)
"${PROJECT_SOURCE_DIR}/scripts/checksrc-all.pl" "${PROJECT_SOURCE_DIR}/scripts/checksrc.pl"
"${PROJECT_SOURCE_DIR}/scripts/spacecheck.pl"
)
if(CURL_LINT)
set_target_properties(curl-lint PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif()
endif()
option(BUILD_LIBCURL_DOCS "Build libcurl man pages" ON)

View file

@ -225,6 +225,9 @@ target_link_libraries(my_target PRIVATE CURL::libcurl)
- `BUILD_STATIC_CURL`: Build curl executable with static libcurl. Default: `OFF` (turns to `ON`, when building static libcurl only)
- `BUILD_STATIC_LIBS`: Build static libraries. Default: `OFF` (turns to `ON` if `BUILD_SHARED_LIBS` is `OFF`)
- `BUILD_TESTING`: Build tests. Default: `ON`
- `CURL_BUILD_EVERYTHING`: Build optional build targets (examples, tests) by default. Default: `OFF`
Set `QUICK` to build examples quickly with the `curl-examples-build` target (for build tests).
Set `NOEXAMPLES` to not build examples.
- `CURL_CLANG_TIDY`: Run the build through `clang-tidy`. Default: `OFF`
If enabled, it implies `CMAKE_UNITY_BUILD=OFF` and `CURL_DISABLE_TYPECHECK=ON`.
- `CURL_CLANG_TIDYFLAGS`: Custom options to pass to `clang-tidy`. Default: (empty)

View file

@ -21,7 +21,6 @@
# SPDX-License-Identifier: curl
#
###########################################################################
add_custom_target(curl-examples)
# Get check_PROGRAMS, COMPLICATED_MAY_BUILD, COMPLICATED_EXAMPLES variables
@ -90,3 +89,9 @@ endforeach()
if(_with_deps)
message(STATUS "Enabled examples with dependencies:${_with_deps}")
endif()
if(CURL_BUILD_EVERYTHING STREQUAL "QUICK")
set_target_properties(curl-examples-build PROPERTIES EXCLUDE_FROM_ALL FALSE)
elseif(CURL_BUILD_EVERYTHING AND NOT CURL_BUILD_EVERYTHING STREQUAL "NOEXAMPLES")
set_target_properties(curl-examples PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif()

View file

@ -33,6 +33,9 @@ add_custom_target(testdeps)
if(BUILD_CURL_EXE)
add_dependencies(testdeps "curlinfo")
endif()
if(CURL_BUILD_EVERYTHING)
set_target_properties(testdeps PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif()
if(CURL_CLANG_TIDY)
add_custom_target(tests-clang-tidy)