1- # build and install c-ares
2- macro (build_install_cares )
1+ # add c-ares
2+ macro (add_cares )
33 if (NOT c-ares_DOWNLOAD_URL)
44 get_github_latest_release_url("c-ares" "c-ares" )
55 endif ()
66 FetchContent_Declare(c-ares URL ${c-ares_DOWNLOAD_URL})
7- # not using FetchContent_MakeAvailable to save compile time
8- FetchContent_GetProperties(c-ares)
9-
10- if (NOT c-ares_POPULATED)
11- FetchContent_Populate(c-ares)
12-
13- # configure build and install
14- if (CMAKE_CXX_COMPILER_ID MATCHES MSVC )
15- execute_process (
16- COMMAND cmake -B ${c-ares_BINARY_DIR } -S ${c-ares_SOURCE_DIR} --fresh -DCARES_BUILD_TOOLS=OFF
17- -DCMAKE_INSTALL_PREFIX=${C-ARES_ROOT_DIR}
18- )
19- execute_process (COMMAND cmake --build ${c-ares_BINARY_DIR } --config Release)
20- execute_process (COMMAND cmake --install ${c-ares_BINARY_DIR } --config Release)
21- execute_process (COMMAND cmake --build ${c-ares_BINARY_DIR } --config Debug)
22- execute_process (COMMAND cmake --install ${c-ares_BINARY_DIR } --config Debug)
23- else ()
24- execute_process (
25- COMMAND cmake -B ${c-ares_BINARY_DIR } -S ${c-ares_SOURCE_DIR} --fresh -DCARES_BUILD_TOOLS=OFF
26- -DCMAKE_INSTALL_PREFIX=${C-ARES_ROOT_DIR}
27- )
28- execute_process (COMMAND cmake --build ${c-ares_BINARY_DIR })
29- execute_process (COMMAND cmake --install ${c-ares_BINARY_DIR })
30- endif ()
31-
32- endif ()
7+ FetchContent_MakeAvailable(c-ares)
338endmacro ()
349
3510# Set normal resolver
@@ -55,27 +30,12 @@ macro(set_cares_resolver)
5530 list (APPEND TRANTOR_SOURCES trantor/net/inner/AresResolver.cc)
5631 list (APPEND private_headers trantor/net/inner/AresResolver.h)
5732
58- # copy dll/libs for Windows, to solve the test/unittests running 0x000135 error
59- copy_files_for_win(${C-ARES_ROOT_DIR}/bin "dll" )
60- copy_files_for_win(${C-ARES_ROOT_DIR}/lib "lib" )
6133endmacro ()
6234
6335# ######################################################################################################################
6436message (STATUS "Setting c-ares: ${TRANTOR_USE_C-ARES}" )
6537
6638if (TRANTOR_USE_C-ARES)
67- # Set C-ARES_ROOT_DIR, to let find_package could search from it
68- if (WIN32 )
69- set (C-ARES_ROOT_DIR
70- ${CMAKE_INSTALL_PREFIX} /../c-ares
71- CACHE PATH "Let find_package use the directory to find" FORCE
72- )
73- else ()
74- set (C-ARES_ROOT_DIR
75- ${CMAKE_INSTALL_PREFIX} /c-ares
76- CACHE PATH "Let find_package use the directory to find" FORCE
77- )
78- endif ()
7939
8040 find_package (c-ares)
8141
@@ -84,8 +44,7 @@ if(TRANTOR_USE_C-ARES)
8444 message (STATUS "⚠️c-ares not found, Building it with FetchContent..." )
8545 unset (c-ares_FOUND)
8646
87- build_install_cares()
88- find_package (c-ares REQUIRED)
47+ add_cares()
8948
9049 else ()
9150 message (FATAL_ERROR "⛔c-ares not found, please install it or set FETCH_BUILD_MISSING_DEPS to ON" )
0 commit comments