Add fetch content for c-ares. - #400
Conversation
|
it seems that I'm fighting all the time with linters! |
|
to be honest my version was more readable :D |
There was a problem hiding this comment.
Pull request overview
This PR introduces FetchContent-based provisioning of c-ares for trantor's optional asynchronous DNS resolver. A new cmake/c-ares.cmake module declares a pinned c-ares source build (v1.34.6, static, PIC), and the top-level CMakeLists.txt includes it before calling find_package(c-ares) (with OVERRIDE_FIND_PACKAGE). The link target is renamed from c-ares_lib to the namespaced c-ares::c-ares. The existing Findc-ares.cmake is tidied to use lowercase variable names matching the package name, but it still produces only c-ares_lib.
Changes:
- Add
cmake/c-ares.cmakethat pulls and statically builds c-ares viaFetchContent, withOVERRIDE_FIND_PACKAGEand ac-ares::c-aresalias. - Wire the new module into the top-level build (
include(FetchContent), prependcmake/toCMAKE_MODULE_PATH,include(c-ares)beforefind_package, and linkc-ares::c-ares). - Lowercase the variable names inside
cmake_modules/Findc-ares.cmakefor consistency with the package name.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| CMakeLists.txt | Adds module-path setup, FetchContent include, include(c-ares), and switches link target to c-ares::c-ares. |
| cmake/c-ares.cmake | New FetchContent module for c-ares with static build options and namespaced alias. |
| cmake_modules/Findc-ares.cmake | Renames C-ARES_* cache/output variables to lowercase c-ares_*. |
Comments suppressed due to low confidence (1)
CMakeLists.txt:266
include(c-ares)is invoked unconditionally insideif(BUILD_C-ARES), which means a c-ares source tree is always cloned and built from GitHub even when the user already has c-ares installed system-wide. Previously,find_package(c-ares)would simply succeed against the system library at no extra cost. Consider gatinginclude(c-ares)onfind_package(c-ares QUIET)failing first, or expose a separate option (e.g.TRANTOR_FETCH_C_ARES) so that users/packagers/CI can opt out of the network fetch.
if(BUILD_C-ARES)
include(c-ares)
find_package(c-ares)
if(c-ares_FOUND)
message(STATUS "c-ares found!")
set(HAVE_C-ARES TRUE)
endif()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FetchContent_Declare( | ||
| c-ares | ||
| GIT_REPOSITORY https://github.com/c-ares/c-ares.git | ||
| GIT_TAG v1.34.6 OVERRIDE_FIND_PACKAGE | ||
| ) |
| target_compile_definitions(${PROJECT_NAME} PRIVATE CARES_STATICLIB) | ||
| endif() | ||
| target_link_libraries(${PROJECT_NAME} PRIVATE c-ares_lib) | ||
| target_link_libraries(${PROJECT_NAME} PRIVATE c-ares::c-ares) |
|
|
||
| FetchContent_MakeAvailable(c-ares) | ||
|
|
||
| add_library(c-ares::c-ares ALIAS c-ares) |
| set(c-ares_INCLUDE_DIRS "${FETCHCONTENT_BASE_DIR}/c-ares-build/" "${FETCHCONTENT_BASE_DIR}/c-ares-src/include/") | ||
| set(c-ares_LIBRARIES "${FETCHCONTENT_BASE_DIR}/c-ares-build/src/lib/") | ||
|
|
||
| mark_as_advanced(c-ares_INCLUDE_DIRS c-ares_LIBRARIES) |
|
@fe-dagostino Thanks for the PR, this is a good improvement overall. I think we may want to clarify two things in the CMake logic:
So essentially:
This keeps both modes working correctly. |
|
Hi @an-tao you are welcome! thanks to you for the library :D |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Propose to adopt fetch_content and to simply all cmake files.