Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
leleliu008 committed Jan 17, 2025
1 parent 10426c8 commit 7da8a9d
Show file tree
Hide file tree
Showing 7 changed files with 1,251 additions and 0 deletions.
29 changes: 29 additions & 0 deletions library/libcares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.0.0)

project(dns C)

set(PROJECT_VERSION 1.0.0)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH})

find_package(PkgConfig REQUIRED)

find_package(CARES REQUIRED)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

##########################################

add_executable(dns src/dns.c)
target_link_libraries(dns CARES::libcares)

##########################################

include(GNUInstallDirs)

install(TARGETS dns RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
43 changes: 43 additions & 0 deletions library/libcares/FindCARES.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
if (CARES_INCLUDE_DIRS AND CARES_LIBRARIES)
set(CARES_FOUND TRUE)
else()
pkg_check_modules(PKG_CONFIG_CARES QUIET libcares)

message("PKG_CONFIG_CARES_FOUND=${PKG_CONFIG_CARES_FOUND}")
message("PKG_CONFIG_CARES_INCLUDE_DIRS=${PKG_CONFIG_CARES_INCLUDE_DIRS}")
message("PKG_CONFIG_CARES_LIBRARY_DIRS=${PKG_CONFIG_CARES_LIBRARY_DIRS}")
message("PKG_CONFIG_CARES_INCLUDEDIR=${PKG_CONFIG_CARES_INCLUDEDIR}")
message("PKG_CONFIG_CARES_LIBDIR=${PKG_CONFIG_CARES_LIBDIR}")
message("PKG_CONFIG_CARES_VERSION=${PKG_CONFIG_CARES_VERSION}")
message("PKG_CONFIG_CARES_LIBRARIES=${PKG_CONFIG_CARES_LIBRARIES}")
message("PKG_CONFIG_CARES_LINK_LIBRARIES=${PKG_CONFIG_CARES_LINK_LIBRARIES}")

if (PKG_CONFIG_CARES_FOUND)
if (PKG_CONFIG_CARES_INCLUDE_DIRS)
set(CARES_INCLUDE_DIRS "${PKG_CONFIG_CARES_INCLUDE_DIRS}")
elseif (PKG_CONFIG_CARES_INCLUDEDIR)
set(CARES_INCLUDE_DIRS "${PKG_CONFIG_CARES_INCLUDEDIR}")
else()
find_path(CARES_INCLUDE_DIRS cares.h)
endif()

set(CARES_LIBRARIES ${PKG_CONFIG_CARES_LINK_LIBRARIES})

if (NOT TARGET CARES::libcares)
add_library(CARES::libcares INTERFACE IMPORTED)
set_target_properties(CARES::libcares PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CARES_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${CARES_LIBRARIES}"
)
endif()

if (PKG_CONFIG_CARES_VERSION)
set(CARES_VERSION_STRING ${PKG_CONFIG_CARES_VERSION})
endif()
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CARES REQUIRED_VARS CARES_LIBRARIES CARES_INCLUDE_DIRS VERSION_VAR CARES_VERSION)

mark_as_advanced(CARES_INCLUDE_DIRS CARES_LIBRARIES)
Loading

0 comments on commit 7da8a9d

Please sign in to comment.