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)