cmake: force-disable unity for clang-tidied build targets only

Instead of globally disabling unity for all targets when clang-tidy is
enabled.

After this patch `CMAKE_UNITY_BUILD=ON` is honored for:
- static libcurl when building both static and shared separately.
- libcurlu and libcurltool internal libraries when building the test
  target.

While keeping unity disabled for the libcurl build pass running
clang-tidy, and the curl tool, also running clang-tidy.

To make clang-tidy-enabled builds finish faster when unity mode is
enabled, yet performs the same clang-tidy checks as before this patch.

Effect on:
- GHA/macos: core build: same, buils tests 5-12 seconds faster,
  with steps going down from 259 to 25.

  52s: https://github.com/curl/curl/actions/runs/22279958340/job/64448913325 ->
  47s: https://github.com/curl/curl/actions/runs/22279873606/job/64448710743

- GHA/windows (not enabled): it'd save about 1 minute, bringing total
  time barely below 10m, still one of the slowest jobs overall.
  (#20667 is trying a way for 4x speed-up (with a drawback)).

  5m21s: https://github.com/curl/curl/actions/runs/22222907068/job/64284556852 ->
  4m26s: https://github.com/curl/curl/actions/runs/22281033369/job/64451601548

Closes #20670
This commit is contained in:
Viktor Szakats 2026-02-22 11:41:49 +01:00
parent 0824bae8b0
commit fff9905bcf
No known key found for this signature in database
4 changed files with 17 additions and 4 deletions

View file

@ -273,7 +273,6 @@ if(CURL_CLANG_TIDY)
set(PICKY_COMPILER OFF) # Do a best effort and skip passing non-clang warning options to clang-tidy.
# This lets through warning options enabled via CURL_WERROR=ON, affecting lib and src.
endif()
set(CMAKE_UNITY_BUILD OFF) # clang-tidy is not looking into #included sources, thus not compatible with unity builds.
set(CURL_DISABLE_TYPECHECK ON) # to improve performance and avoid potential interference.
set(CMAKE_C_CLANG_TIDY "${CLANG_TIDY}")
list(APPEND CMAKE_C_CLANG_TIDY "--config-file=${PROJECT_SOURCE_DIR}/.clang-tidy.yml")

View file

@ -229,7 +229,8 @@ target_link_libraries(my_target PRIVATE CURL::libcurl)
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`.
If enabled, it implies `CURL_DISABLE_TYPECHECK=ON` and force-disables unity mode
for libcurl and the curl tool.
- `CURL_CLANG_TIDYFLAGS`: Custom options to pass to `clang-tidy`. Default: (empty)
- `CURL_CODE_COVERAGE`: Enable code coverage build options. Default: `OFF`
- `CURL_COMPLETION_FISH`: Install fish completions. Default: `OFF`

View file

@ -125,6 +125,9 @@ if(SHARE_LIB_OBJECT AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
set_target_properties(${LIB_OBJECT} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
if(CURL_CLANG_TIDY)
set_target_properties(${LIB_OBJECT} PROPERTIES UNITY_BUILD OFF)
endif()
if(CURL_CODE_COVERAGE)
set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS})
set_property(TARGET ${LIB_OBJECT} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS})
@ -167,8 +170,12 @@ if(BUILD_STATIC_LIBS)
set_target_properties(${LIB_STATIC} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
if(CURL_CLANG_TIDY AND BUILD_SHARED_LIBS) # disable clang-tidy for static, and limit to the shared library, if both enabled
set_target_properties(${LIB_STATIC} PROPERTIES C_CLANG_TIDY "")
if(CURL_CLANG_TIDY)
if(BUILD_SHARED_LIBS) # disable clang-tidy for static, and limit to the shared library, if both enabled
set_target_properties(${LIB_STATIC} PROPERTIES C_CLANG_TIDY "")
else()
set_target_properties(${LIB_STATIC} PROPERTIES UNITY_BUILD OFF)
endif()
endif()
if(CURL_CODE_COVERAGE)
set_property(TARGET ${LIB_STATIC} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS})
@ -232,6 +239,9 @@ if(BUILD_SHARED_LIBS)
set_target_properties(${LIB_SHARED} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
if(CURL_CLANG_TIDY)
set_target_properties(${LIB_SHARED} PROPERTIES UNITY_BUILD OFF)
endif()
if(CURL_CODE_COVERAGE)
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_DEFINITIONS ${CURL_COVERAGE_MACROS})
set_property(TARGET ${LIB_SHARED} APPEND PROPERTY COMPILE_OPTIONS ${CURL_COVERAGE_CFLAGS})

View file

@ -121,6 +121,9 @@ set_target_properties(curltool PROPERTIES C_CLANG_TIDY "")
if(CURL_HAS_LTO)
set_target_properties(${EXE_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(CURL_CLANG_TIDY)
set_target_properties(${EXE_NAME} PROPERTIES UNITY_BUILD OFF)
endif()
if(ENABLE_UNICODE AND MINGW)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)