Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ set_property(
)
option(USE_SPDLOG "Allow using the spdlog logging library" OFF)

# Update default path for .cmake files.
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
Comment thread
fe-dagostino marked this conversation as resolved.

set(TRANTOR_MAJOR_VERSION 1)
Expand Down Expand Up @@ -46,6 +48,8 @@ set(INSTALL_TRANTOR_CMAKE_DIR
CACHE PATH "Installation directory for cmake files"
)

include(FetchContent)

add_library(${PROJECT_NAME})
if(BUILD_SHARED_LIBS)
list(
Expand Down Expand Up @@ -254,6 +258,7 @@ endif(HAVE_SPDLOG)

set(HAVE_C-ARES NO)
if(BUILD_C-ARES)
include(c-ares)
find_package(c-ares)
if(c-ares_FOUND)
message(STATUS "c-ares found!")
Expand All @@ -265,7 +270,7 @@ if(HAVE_C-ARES)
if(NOT BUILD_SHARED_LIBS)
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)
set(TRANTOR_SOURCES ${TRANTOR_SOURCES} trantor/net/inner/AresResolver.cc)
set(private_headers ${private_headers} trantor/net/inner/AresResolver.h)
if(APPLE)
Expand Down
27 changes: 27 additions & 0 deletions cmake/c-ares.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FetchContent_Declare(
c-ares
GIT_REPOSITORY https://github.com/c-ares/c-ares.git
GIT_TAG v1.34.6 OVERRIDE_FIND_PACKAGE
)
Comment on lines +1 to +5

set(CARES_STATIC
ON
CACHE BOOL "" FORCE
)
set(CARES_STATIC_PIC
ON
CACHE BOOL "" FORCE
)
set(CARES_SHARED
OFF
CACHE BOOL "" FORCE
)

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)
Comment on lines +20 to +23

FetchContent_MakeAvailable(c-ares)

add_library(c-ares::c-ares ALIAS c-ares)
18 changes: 9 additions & 9 deletions cmake_modules/Findc-ares.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
# Try to find c-ares library Once done this will define
#
# c-ares_FOUND - system has c-ares
# C-ARES_INCLUDE_DIRS - The c-ares include directory
# C-ARES_LIBRARIES - Link these to use c-ares
# c-ares_INCLUDE_DIRS - The c-ares include directory
# c-ares_LIBRARIES - Link these to use c-ares
# c-ares_lib - Imported Targets
#
# Copyright (c) 2020 antao <antao2002@gmail.com>
#]]

find_path(C-ARES_INCLUDE_DIRS ares.h)
find_library(C-ARES_LIBRARIES NAMES cares)
if(C-ARES_INCLUDE_DIRS AND C-ARES_LIBRARIES)
find_path(c-ares_INCLUDE_DIRS ares.h)
find_library(c-ares_LIBRARIES NAMES cares)
if(c-ares_INCLUDE_DIRS AND c-ares_LIBRARIES)
add_library(c-ares_lib INTERFACE IMPORTED)
set_target_properties(
c-ares_lib
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${C-ARES_INCLUDE_DIRS}" INTERFACE_LINK_LIBRARIES "${C-ARES_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${c-ares_INCLUDE_DIRS}" INTERFACE_LINK_LIBRARIES "${c-ares_LIBRARIES}"
)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
c-ares
DEFAULT_MSG
C-ARES_INCLUDE_DIRS
C-ARES_LIBRARIES
c-ares_INCLUDE_DIRS
c-ares_LIBRARIES
)
mark_as_advanced(C-ARES_INCLUDE_DIRS C-ARES_LIBRARIES)
mark_as_advanced(c-ares_INCLUDE_DIRS c-ares_LIBRARIES)
Loading