A C library for asynchronous DNS requests (grpc依赖)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.2 KiB

# Copyright (C) The c-ares project and its contributors
# SPDX-License-Identifier: MIT
# Get rid of: warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
IF (MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
ENDIF ()
find_package(Threads)
find_package(GTest REQUIRED)
IF (CMAKE_VERSION VERSION_LESS "3.23.0")
Message("GoogleTest found, cmake version too old to verify GMock, look for errors...")
ELSE ()
IF (NOT TARGET GTest::gmock)
Message(FATAL_ERROR "GoogleTest found but the GMock component was not found")
ENDIF()
ENDIF()
# create target to access and use internal cares library
add_library(caresinternal INTERFACE)
target_compile_definitions(caresinternal INTERFACE HAVE_CONFIG_H=1)
target_include_directories(caresinternal
INTERFACE "${PROJECT_BINARY_DIR}"
Autotools: rework to simplify and fix recent issues (#674) Completely rework the autotools build system, issues have cropped up due to the complexity and could cause issues on even semi-modern Linux systems (Ubuntu 20.04 for example). Changes include: Remove all curl/xc/cares m4 helper files, they go overboard on detections of functions and datatypes. Go back to more plain autoconf macros as they've come a long way over the years. Use known systems and heuristics to determine datatypes for functions like send() and recv(), rather than the error prone detection which required thousands of permutations and might still get it wrong. Remove unneeded configure arguments like --enable-debug or --enable-optimize, its more common for people to simply pass their own CFLAGS on the command line. Only require CARES_STATICLIB definition on Windows static builds, its not necessary ever for other systems, even when hiding non-public symbols. Remove some function and definition detections that were never used in c-ares The test framework is now embedded into the toplevel configure system, there was no need to chain build the test system as it is never built externally to c-ares. As a side-effect of the changes, a configure run completes in about 25% of the original time. This has been tested on various Linux distributions (of varying age), FreeBSD, MacOS, Windows (via MSYS2 with Mingw), and Solaris10/11 (by @dfandrich), AIX 7.3 (by @dfandrich). It is not unlikely that this may have broken more esoteric or legacy systems, and we'll likely need to be ready to accept bug reports and patches, but it has removed over 10k lines of build system code. It is very likely any issues that crop up will add far fewer lines of code to fix such systems. Fixes Bug: #670 Fix By: Brad House (@bradh352)
11 months ago
"${PROJECT_BINARY_DIR}/src/lib"
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/src/lib"
"${PROJECT_SOURCE_DIR}/include"
)
IF (CARES_STATIC)
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME}::cares_static)
ELSE ()
target_link_libraries(caresinternal INTERFACE ${PROJECT_NAME}::cares)
ENDIF ()
transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
add_executable(arestest ${TESTSOURCES} ${TESTHEADERS})
target_include_directories(arestest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
IF (CMAKE_VERSION VERSION_LESS "3.23.0")
FIND_LIBRARY(LIBGMOCK NAMES gmock PATHS ${GTEST_ROOT} PATH_SUFFIXES lib)
IF (LIBGMOCK-NOTFOUND)
MESSAGE(FATAL_ERROR "Could not find Gmock")
ENDIF ()
target_link_libraries(arestest PRIVATE caresinternal GTest::GTest ${LIBGMOCK})
ELSE ()
target_link_libraries(arestest PRIVATE caresinternal GTest::gmock)
ENDIF()
target_compile_definitions(arestest PRIVATE CARES_NO_DEPRECATED)
IF (CARES_BUILD_CONTAINER_TESTS)
target_compile_definitions(arestest PRIVATE HAVE_USER_NAMESPACE HAVE_UTS_NAMESPACE)
ENDIF ()
add_executable(aresfuzz ${FUZZSOURCES})
target_compile_definitions(aresfuzz PRIVATE CARES_NO_DEPRECATED)
target_link_libraries(aresfuzz PRIVATE caresinternal)
add_executable(aresfuzzname ${FUZZNAMESOURCES})
target_compile_definitions(aresfuzzname PRIVATE CARES_NO_DEPRECATED)
target_link_libraries(aresfuzzname PRIVATE caresinternal)
add_executable(dnsdump ${DUMPSOURCES})
target_compile_definitions(dnsdump PRIVATE CARES_NO_DEPRECATED)
target_link_libraries(dnsdump PRIVATE caresinternal)
add_executable(ares_queryloop ${LOOPSOURCES})
target_compile_definitions(ares_queryloop PRIVATE CARES_NO_DEPRECATED)
target_link_libraries(ares_queryloop PRIVATE caresinternal)
# register tests
add_test(NAME arestest COMMAND $<TARGET_FILE:arestest>)
file(GLOB_RECURSE FUZZINPUT_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/fuzzinput" "fuzzinput/*")
add_test(
NAME aresfuzz
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fuzzinput"
COMMAND $<TARGET_FILE:aresfuzz> ${FUZZINPUT_FILES}
)
file(GLOB_RECURSE FUZZNAMES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/fuzznames" "fuzznames/*")
add_test(
NAME aresfuzzname
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/fuzznames"
COMMAND $<TARGET_FILE:aresfuzzname> ${FUZZNAMES_FILES}
)