From fff9905bcf7c8c1da1668213d79473865461048f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 22 Feb 2026 11:41:49 +0100 Subject: [PATCH] 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 --- CMakeLists.txt | 1 - docs/INSTALL-CMAKE.md | 3 ++- lib/CMakeLists.txt | 14 ++++++++++++-- src/CMakeLists.txt | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 154ba5ef8f..cb294a8036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index 428431d61d..d59a509d47 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -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` diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8d8215de94..f20873cdbf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -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}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c72c9496b2..0063b438c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)